feat: centralized typed configuration with strict startup validation#117
Open
0xDeon wants to merge 1 commit intoTevaLabs:mainfrom
Open
feat: centralized typed configuration with strict startup validation#1170xDeon wants to merge 1 commit intoTevaLabs:mainfrom
0xDeon wants to merge 1 commit intoTevaLabs:mainfrom
Conversation
Introduces src/config/ with strict TypeScript types for all runtime configuration (app, JWT, database, Soroban, scheduler, Stellar, socket). Parses env vars once at startup, validates required fields, rejects placeholder secrets, and fails fast with actionable error messages.
08a78e5 to
f3b8265
Compare
Author
|
@josephchimebuka Please review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #93
Introduces a centralized, typed configuration module (
src/config/) that replaces all scatteredprocess.envaccess across the runtime codebase. The module parses environment variables once at startup, validates every field with clear error messages, and fails fast — the server will never partially boot with invalid or missing configuration.What changed
src/config/validation.ts— Reusable validation primitives (required,sensitiveRequired,port,url,positiveInt,boolean,oneOf) that collect all errors and throw once with actionable messagessrc/config/index.ts— Typed config entry point defining strict interfaces for every config section (App, JWT, Database, Soroban, Scheduler, Stellar, Socket), exported as a frozen singletonconfiginstead of readingprocess.envdirectly.env.examplewith all variables, defaults, and required/optional annotationsREADME.mdEnvironment Setup section with complete variable reference tableConfig sections
port,nodeEnv,clientUrl,logLevelsecret,expiryyour-,CHANGE_ME, etc.)urlcontractId,network,rpcUrl,adminSecret,oracleSecretautoResolveEnabled,autoResolveIntervalSeconds,roundSchedulerEnabled,roundSchedulerModenetworktestnet|mainnet)clientUrlFiles modified
src/config/index.tssrc/config/validation.tssrc/index.tsdotenv.config(), inlinevalidateEnv(), usesconfig.app.*src/utils/jwt.util.tsgetJwtSecret()helper andJWT_EXPIRYconstant, usesconfig.jwt.*src/utils/logger.tsconfig.app.logLevelsrc/lib/prisma.tsconfig.app.nodeEnvsrc/socket.tsconfig.socket.clientUrlsrc/services/soroban.service.tsconfig.sorobansrc/services/scheduler.service.tsconfig.scheduler.*src/services/round-scheduler.service.tsconfig.scheduler.*src/services/stellar.service.tsconfig.stellar.network.env.exampleREADME.mdDesign decisions
ConfigValidationErrorlisting them all, so developers fix everything in one pass instead of playing whack-a-molesensitiveRequiredscans for common placeholder patterns (your-,CHANGE_ME,TODO, etc.) to prevent accidental deployments with example secretsoptional()rather thanrequired()to preserve that behaviorObject.freeze()on the exported singleton prevents accidental mutation at runtimeprocess.envto exercise services under different configurations; this is correct and expectedAudit checklist
process.envusage in runtime paths (only test files remain)JWT_SECRET,DATABASE_URL) have no insecure defaults"testnet" | "mainnet","UP_DOWN" | "LEGENDS").env.examplematches actual config requirementsnpm run buildsucceeds without errorsTest plan
npm run buildpasses.env— should boot normallyJWT_SECRET— should fail with clear errorDATABASE_URL— should fail with clear errorJWT_SECRET=your-secret-here— should reject placeholderPORT=abc— should fail with port validation errorNODE_ENV=invalid— should fail with enum errornpm test)