Repository navigation
Add schema-validated environment config for the backend - #62
Merged
Muhammadcodes112 merged 1 commit intoJul 10, 2026
Merged
Conversation
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.
Problem
apps/backend/src/config/env.tsreadprocess.envwith hand-rolledrequired()/optional()helpers. Missing or malformed variables (e.g. a non-numericPORT, or an unrecognizedSTELLAR_NETWORK) weren't caught in a structured way, so bad configuration could surface later as a confusing runtime crash instead of a clear failure at boot.Solution
zodschema (envSchema) covering every variable documented inapps/backend/.env.example:NODE_ENV,HOST,PORT,DATABASE_URL,REDIS_URL, theWHATSAPP_*vars, theSTELLAR_*vars,HASHPORT_CONTRACT_ID,SIGNER_SECRET_KEY, andWALLET_ENCRYPTION_KEY.superRefinecheck keyed onNODE_ENV: storage/WhatsApp/Stellar/secret vars stay optional for local development (preserving the existing behavior where the backend boots without WhatsApp/Stellar credentials), but become required onceNODE_ENV=production.loadEnv()inenv.ts), instead of failing later inside request handling.parseEnv()andformatEnvIssues()are exported as pure functions (no process side effects) so they're directly unit-testable.apps/backend/test/env.test.tscovering: default values with no vars set, a malformedPORT, an invalidSTELLAR_NETWORK, an invalidNODE_ENV, missing production-required vars, a fully-populated production config, and the readable-error-list formatting.envandsecrets(including the lazy secret getters) is unchanged, so no call sites elsewhere in the backend needed to change.closes #2