Architecture
Decide who owns the setting and when it must change. Deployment-wide credentials, a tenant's rollout switch and a merchant's numbering policy belong in different places.
Work through these in order and stop at the first match.
modules.ts overrides. App-wide removal of a route, agent, widget, subscriber, or ACL declaration from its runtime registry.If two answers fit, prefer the earlier one – it is the cheaper and more contained mechanism.
Env vars (OM_*) | modules.ts overrides | Feature toggles | Module configs | Domain settings | |
|---|---|---|---|---|---|
| Scope | Instance | Instance | Instance default + per-tenant override | Global or per-tenant, with fallback | Per organization + tenant |
| Changed by | Operator, at deploy | App developer, in code | Admin, at runtime | Code | Merchant admin, at runtime |
| Takes effect | Restart | Rebuild / restart | Immediately | Immediately | Immediately |
| Admin UI | – | – | /backend/feature-toggles/global and /backend/feature-toggles/overrides | – | The module's own settings page |
| Readable from client components | No | No (already applied at bootstrap) | Yes | No | Via the module's API |
| Typed / validated | Ad-hoc parsing | TypeScript | boolean / string / number / json | Any JSON, no schema | zod + ORM schema |
| Needs a migration | No | No | No | No | Yes |
| Declared by the module | In the code that reads it | In the app's modules.ts | Core defaults in defaults.json; provisioned via CLI or UI | In the code that reads it | Entity + command + API |
Instance-wide values an operator sets before the process starts. Read them with process.env.OM_* and parse with parseBooleanToken / parseBooleanWithDefault from @open-mercato/shared/lib/boolean rather than hand-rolled truthiness checks.
Use them for: infrastructure endpoints, credentials, timeouts, pool sizes, cache and profiling switches, and anything whose wrong value should stop the deployment rather than degrade one tenant.
Rule of thumb: if one tenant could legitimately want a different value from another tenant, it must not be only an env var.
Prefix every variable with OM_ and document it in apps/mercato/.env.example. When you add one to the app, mirror it into the create-mercato-app template in the same change.
modules.ts overridesStatic app configuration in apps/<app>/src/modules.ts, applied during bootstrap before the affected registries are stored. Mapping an id to null disables the contract; mapping it to a definition replaces it.
export const enabledModules: ModuleEntry[] = [
{
id: 'example',
from: '@app',
overrides: {
routes: { pages: { '/backend/example/reports': null } },
ai: { agents: { 'catalog.catalog_assistant': null } },
acl: { features: { 'example.manage': null } },
},
},
]
This is the mechanism for building a thin installation – one with a reduced registered capability surface. It covers eighteen domains (routes, pages, AI agents and tools, subscribers, workers, widgets, notifications, interceptors, enrichers, guards, CLI commands, setup hooks, ACL features, DI bindings, encryption maps). See Module overrides for the full key reference and resolution order.
Reach for it instead of a feature toggle when the answer is the same for every tenant on the installation and you would rather the capability not be registered than be switchable. It is source-controlled, needs no seeding, and adds no per-request lookup.
Nulling an
acl.featuresentry currently removes the feature from the ACL catalog and the management UI. Work to make a nulled feature runtime-inert for every caller – including wildcard grants and super-admins – is in progress; until it lands, do not rely onacl.features: nullalone as a security boundary.
Whole-module activation is a related but separate knob: see Developing Official Modules and official-modules.json.
Runtime on/off switches (and small typed values) resolved per tenant, with an instance-wide default underneath. This is the canonical layer for gating UI surfaces, running controlled rollouts, and shipping emergency kill switches.
Server side:
const service = container.resolve('featureTogglesService') as FeatureTogglesService
const result = await service.getBoolConfig('sales_channels_enabled', tenantId)
Client side, useFeatureFlagBoolean({ id }) and <FeatureGuard id={...}> read the same value through /api/feature_toggles/check/*.
A toggle with no definition row resolves to MISSING_TOGGLE, the check API answers 404, and the client helpers coerce that to disabled. Two consequences:
setup.ts seedDefaults hook (portal, customers, sales and wms all do), which covers new tenants and lets existing installations catch up with yarn mercato seed:defaults --module <moduleId>. packages/core/src/modules/feature_toggles/defaults.json is only for demo/platform toggles that no module owns; it is seeded once by yarn mercato feature_toggles seed-defaults during init, so a toggle that lives only there stays unregistered on every database created before it shipped.*_enabled identifier with defaultValue: true over an inverted disable_* flag.Where hiding UI on a failed lookup would be worse than showing it, wrap the check in your own fail-open helper rather than depending on the default coercion – packages/core/src/modules/sales/lib/salesChannelsToggle.ts is the reference.
Anything an operator alone should control (use an env var), anything written by code (use a module config), or anything with validation rules and a dedicated form (use domain settings).
See Feature toggles for the data model and resolution order, and the user guide for the admin screens.
ModuleConfigService stores per-module JSON key/value state in module_configs. Resolve it from the container and always pass the tenant scope derived from the authenticated context, never from request input.
const service = container.resolve('moduleConfigService')
const cursor = await service.getValue<string>('data_sync', 'akeneo:cursor', {
defaultValue: null,
scope: { tenantId },
})
await service.setValue('data_sync', 'akeneo:cursor', nextCursor, { tenantId })
Reads with a tenantId resolve the scoped row, then fall back to the global row (tenant_id IS NULL). Use getRecord instead of getValue when you need the record's source field to report which scope answered. Writes with a tenantId only ever touch that tenant's row. Omit scope entirely for genuinely instance-global config.
Use it for machine-facing state: sync cursors, connector settings, cached structural config, anything written by code rather than typed into a form. It has no admin UI and no client-side read path, so it is the wrong home for anything a human needs to change.
See configs module.
A first-class entity owned by the module, with zod validation, a command for writes, an API, and a settings page. SalesSettings behind /backend/config/sales is the reference implementation.
Use it when the value is part of the domain model – document numbering formats, order editability rules, policy thresholds – and a merchant admin would expect to find it under the module's own settings. It is the most expensive option (entity, migration, snapshot, command, API, form, translations) and the one that can enforce domain validation and participate in the standard audit/undo patterns. Audit and undo still require the command's explicit buildLog and undo implementations.
Follow the standard entity workflow: update data/entities.ts, run yarn db:generate, review the emitted SQL and migrations/.snapshot-open-mercato.json. Give the entity an updated_at column and return updatedAt from its API so optimistic locking works.
acl.ts decide who may use a capability, per role, wildcard-aware. They do not decide whether the deployment or the tenant has it. The exception is modules.ts acl.features: null, which removes the declaration itself – see above.official-modules.json activates or deactivates whole modules at generate time. Coarser than everything on this page.localStorage are per-browser escape hatches for surfaces that only exist in demo deployments. They are not feature toggles by the litmus test above: nothing is provisioned, nothing is tenant-scoped, and nothing is readable on the server. See below.ff_om_hide_contact – hide the demo contact widgetDemo deployments (DEMO_MODE, which is on unless you set it to a false value – 0, false, no, n, off, disable, disabled) render a contact/feedback surface in the backend: a floating call-to-action button, plus a popup that appears after 30 seconds of inactivity. When you are recording a walkthrough or screenshotting the admin, that surface gets in the way – but turning DEMO_MODE off is a blunt instrument: it also unlocks attachment partition settings, changes how mercato init treats the demo superadmin, and (for the literal value false) drops the demo notice bar.
Set the ff_om_hide_contact key in the browser's localStorage to hide just the contact widget:
// Hide the floating button and the inactivity popup
localStorage.setItem('ff_om_hide_contact', '1')
// Bring them back without deleting the key
localStorage.setItem('ff_om_hide_contact', 'off')
// Bring them back by removing the key
localStorage.removeItem('ff_om_hide_contact')
Reload the page after changing the key. The flag is read once, on mount, and nothing listens for later storage changes – setting it in devtools has no visible effect until the next render of the backend layout.
The semantics are deliberately presence-based, so that typing the key with no value in devtools is enough to hide the widget:
| Stored value | Widget |
|---|---|
| key absent | visible |
0, false, no, n, off, disable, disabled | visible |
| any other non-empty value | hidden |
| empty or whitespace-only | hidden |
Values are trimmed and lower-cased before matching, so " OFF " counts as a false value. The explicit false values exist so the flag can be switched off while the key stays in place. The flag is read per browser and per origin – it is not synced, not tenant-scoped, and has no server-side equivalent. If localStorage is unavailable (private-mode restrictions, a blocked origin), the widget stays visible rather than failing closed.
If you are trying to confirm the flag worked, note that the inactivity popup has its own suppression conditions independent of it – it shows at most once per day per browser (om_feedback_shown), never while the AI dock or another modal is open, and not at all while om_feedback_suppress holds the value 1. Both of those are cookies, not localStorage keys – devtools lists them under Application → Cookies, not beside ff_om_hide_contact. The floating button is the reliable thing to check.
The key name and the parsing live in apps/mercato/src/components/demoFeedbackFlag.ts, mirrored into the scaffold at packages/create-app/template/src/components/demoFeedbackFlag.ts.
A client uses products but has a single sales channel, so the channel picker, column, filter, and management pages are noise for them.
The value varies per tenant, only gates UI surfaces, and has to be read from client components – litmus test step 3, so a feature toggle. sales_channels_enabled is defined and seeded by the sales module itself (packages/core/src/modules/sales/lib/salesChannelsToggleSeed.ts, wired into sales/setup.ts seedDefaults) with defaultValue: true; tenant admins override it at /backend/feature-toggles/overrides. No data-layer change was needed: channelId is already nullable and channel-less base prices already resolve.
Two alternatives that would have been wrong:
SalesSettings – right if disabling channels changed behaviour (pricing resolution, order validation). It only hides UI, so the migration would buy nothing.modules.ts override – right if no tenant on the installation used channels and the pages could be removed outright. Here other tenants still need them.Documented so you are not surprised by them:
setup.ts seedDefaults; there is no toggles.ts contract the generator picks up the way it picks up acl.ts, events.ts or ce.ts. Forgetting the seedDefaults call is silent – the toggle simply resolves to MISSING_TOGGLE at runtime.getFeatureToggleValue and useFeatureFlagBoolean take no default value, so callers who need fail-open behaviour hand-roll it. ModuleConfigService.getValue does accept defaultValue.OM_* env vars are not indexed. There are well over a hundred and they are only discoverable by grep. A handful are semantically per-tenant despite being process-wide – OM_ATTACHMENT_TENANT_QUOTA_MB and OM_SEARCH_ENABLED among them. Treat those as legacy, not as precedent.Previous: Cache CLI architecture · Next: Tenant data encryption