Skip to content

Config: move feature flags out of the source into env - #218

Merged
Baskarayelu merged 2 commits into
QuickLendX:mainfrom
greatest0fallt1me:feat/107-feature-flags-env
Aug 28, 2026
Merged

Baskarayelu merged 2 commits into
QuickLendX:mainfrom
greatest0fallt1me:feat/107-feature-flags-env

Conversation

@greatest0fallt1me

@greatest0fallt1me greatest0fallt1me commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Note on scope

No feature flags existed in the codebase to move -- there was no flag infrastructure at all. Added the infrastructure itself: flags keyed by name, backed by env vars, defaulting closed.

Change

`lib/featureFlags.ts`:

  • `FEATURE_FLAG_ENV_KEYS`: maps a flag name to its `NEXT_PUBLIC_FEATURE_*` env var name (one example flag, `newDashboardLayout`, to establish the pattern).
  • `isFeatureEnabled(flag)`: `true` only for the exact string `"true"` -- unset, empty, or any other value is disabled, so a new flag defaults closed instead of needing every environment to explicitly opt out.

Documented the example flag's env var in `.env.example`.

Tests

`lib/featureFlags.test.ts`: disabled when unset, enabled only for the exact string `"true"`, disabled for other truthy-looking values (`"1"`, `"TRUE"`, `"yes"`, `"false"`, `""`).

`npx vitest run lib/featureFlags.test.ts`: 3 passed. `npx tsc --noEmit` / `npx eslint` on changed files: clean.

Related to #107

No feature-flag infrastructure existed. Add lib/featureFlags.ts:
flags are keyed by name, mapped to a NEXT_PUBLIC_FEATURE_* env var,
and isFeatureEnabled() treats exactly the string "true" as enabled --
unset/empty/anything else defaults closed, so a flag never needs
every environment to explicitly opt out. Documented in .env.example.
The README states every runtime env var is read through lib/config.ts
-- "never access process.env directly in business logic" -- but
featureFlags.ts did exactly that. Move flag definitions and reading
into config.ts (alongside sentryDsn/stellarNetwork, same
sane-default-then-env-override pattern) and make featureFlags.ts a
thin isFeatureEnabled() convenience wrapper over config.featureFlags.
@greatest0fallt1me

Copy link
Copy Markdown
Contributor Author

Pushed a follow-up commit: the first version read `process.env` directly in `featureFlags.ts`, which violates this repo's own stated convention (README: "All runtime env vars are read through `lib/config.ts` — never access `process.env` directly in business logic"). Moved the flag definitions and reading into `lib/config.ts` alongside `sentryDsn`/`stellarNetwork`, and `featureFlags.ts` is now a thin `isFeatureEnabled()` wrapper over `config.featureFlags`. Tests updated to match (module-load-time env stubbing via `vi.stubEnv` + `vi.resetModules()`, matching `lib/config.test.ts`'s existing pattern).

@Baskarayelu
Baskarayelu merged commit c634e67 into QuickLendX:main Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants