Open MercatoDocsSearch docsAPI reference

Architecture

Configuration decision guide

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.

Litmus test

Work through these in order and stop at the first match.

  1. Does only the person who operates the deployment decide it, and should it never vary per tenant? → Environment variable. Timeouts, credentials, cache and profiling switches, infrastructure endpoints.
  2. Should this installation disable the capability for every tenant at bootstrap? → modules.ts overrides. App-wide removal of a route, agent, widget, subscriber, or ACL declaration from its runtime registry.
  3. Is it an on/off (or small typed value) that varies per tenant, and might be read from a client component? → Feature toggle. UI-surface gating, controlled rollouts, kill switches.
  4. Is it written by code, for code, with no human ever editing it in a form? → Module config. Sync cursors, connector state, cached structural config.
  5. Is it a business rule a merchant admin would look for under the module's settings page? → Domain settings entity. Numbering formats, editability policy, thresholds with real domain meaning.

If two answers fit, prefer the earlier one – it is the cheaper and more contained mechanism.

At a glance

Env vars (OM_*)modules.ts overridesFeature togglesModule configsDomain settings
ScopeInstanceInstanceInstance default + per-tenant overrideGlobal or per-tenant, with fallbackPer organization + tenant
Changed byOperator, at deployApp developer, in codeAdmin, at runtimeCodeMerchant admin, at runtime
Takes effectRestartRebuild / restartImmediatelyImmediatelyImmediately
Admin UI – – /backend/feature-toggles/global and /backend/feature-toggles/overrides – The module's own settings page
Readable from client componentsNoNo (already applied at bootstrap)YesNoVia the module's API
Typed / validatedAd-hoc parsingTypeScriptboolean / string / number / jsonAny JSON, no schemazod + ORM schema
Needs a migrationNoNoNoNoYes
Declared by the moduleIn the code that reads itIn the app's modules.tsCore defaults in defaults.json; provisioned via CLI or UIIn the code that reads itEntity + command + API

Environment variables

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 overrides

Static 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.features entry 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 on acl.features: null alone as a security boundary.

Whole-module activation is a related but separate knob: see Developing Official Modules and official-modules.json.

Feature toggles

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/*.

Toggles must be provisioned

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:

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.

Not for

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.

Module configs

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.

Domain settings entities

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.

Adjacent knobs that are not configuration

ff_om_hide_contact – hide the demo contact widget

Demo 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 valueWidget
key absentvisible
0, false, no, n, off, disable, disabledvisible
any other non-empty valuehidden
empty or whitespace-onlyhidden

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.

Worked example: disabling sales channels

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:

Known gaps

Documented so you are not surprised by them:

Previous: Cache CLI architecture · Next: Tenant data encryption