Developer guide
Feature flags
Roll out features per organization with env defaults and database overrides.
Feature flags live in packages/domain/src/feature-flags. A flag has a registry
definition, an optional environment default, and optional per-organization
overrides.
Resolution order
For a given organization, the first matching source wins:
- Kill switch —
FEATURE_FLAGS_DISABLED="true"disables every flag. - Organization override — a row in
feature_flag_overrides. - Environment default — an entry in
FEATURE_FLAGS. - Registry default — the flag's built-in default.
Rollouts are bucketed by organizationId with a stable hash, so the admin and
storefront agree for the same organization.
Registry
| Flag | Default | Purpose |
|---|---|---|
demoBadge | Off | Temporary badge that proves the pipeline |
orderSms | Off | Transactional order SMS |
whatsappNotifications | Off | WhatsApp order messages and replies |
Environment defaults
FEATURE_FLAGS='{"orderSms":{"enabled":true,"rolloutPercentage":100}}'
FEATURE_FLAGS_DISABLED="false"- Keys must exist in the registry.
rolloutPercentageis an integer from 0 to 100.- Malformed JSON fails closed in the apps: the configuration is ignored and the error is logged. The CLI surfaces the parse error directly.
Per-organization overrides
Use the developer CLI from the repository root:
pnpm flags -- list --org my-store
pnpm flags -- set --org my-store --flag orderSms --enabled --rollout 100
pnpm flags -- set --org my-store --flag orderSms --disabled
pnpm flags -- unset --org my-store --flag orderSms
pnpm flags -- unset --org my-store --allThe CLI validates the organization, flag key, and rollout range. It requires Bun and a reachable database.
Adding a flag
- Add the definition to
featureFlagRegistrywith a default and description. - Use the flag in the app through the feature-flag provider or server helper.
- Add env defaults if needed.
- Add tests for resolution and rollout behavior.
- Document the flag here.
- Remove the flag when the feature is fully rolled out.
Using flags in the apps
- The admin and storefront expose resolved flag values to the UI through their feature-flag providers.
- Server code can resolve states with
resolveFeatureFlagStatesand read the boolean values withtoFeatureFlagValues. - Always pass an organization ID; there is no global value without a tenant.
Debugging
- Run
pnpm flags -- list --org <slug>to see the resolved state and source. - Check
FEATURE_FLAGS_DISABLEDfirst. - Check the override row before changing env defaults.
- Remember that a rollout percentage below 100 may exclude the organization you are testing.