Open MercatoDocsSearch docsAPI reference

Framework

Module overrides

An application can replace one upstream route, hide a widget or disable a subscriber without copying the entire package. Declare the exact contract to override in the module entry, regenerate, and verify the effective registration.

Use entry.overrides in apps/<app>/src/modules.ts when an app needs to replace or disable a contract shipped by an upstream module. The override is static app configuration: it applies during bootstrap before the affected registries are stored.

import type { ModuleEntry } from './modules'

export const enabledModules: ModuleEntry[] = [
  {
    id: 'example',
    from: '@app',
    overrides: {
      routes: {
        api: {
          'GET /api/example/override-probe': {
            handler: async () => Response.json({ ok: true, source: 'override' }),
            metadata: { requireAuth: false },
          },
        },
        pages: {
          '/backend/example': null,
          '/frontend/store': { metadata: { title: 'Storefront' } },
        },
      },
    },
  },
]

Resolution order is:

  1. Programmatic apply*Overrides(...).
  2. modules.ts inline entry.overrides.
  3. File-based overrides where a domain supports them.
  4. The module's own registrations.

null disables the contract. A definition replaces it. Programmatic overrides can restore a contract disabled by modules.ts by mapping the same id back to a definition.

The default app and create-mercato-app template also export a non-applied moduleOverrideExamples object from src/modules.ts. It is a copyable catalog for all wired domains; it does not change runtime behavior unless you assign one of those shapes to a module entry's overrides field.

Domains

DomainKeyStable id
AIai.agents, ai.toolsagent id / tool name
API routesroutes.api'METHOD /api/path'
Page routesroutes.pages'/backend/path' or '/frontend/path'
Event subscribersevents.subscriberssubscriber id
Workersworkersworker id
Widget injectionwidgets.injectioninjection widget id – either the registry key (module:widget:file) or the widget's own widgetId (module.injection.widget)
Component overrideswidgets.componentscomponent handle
Dashboard widgetswidgets.dashboardwidget id
Notification types and handlersnotifications.types, notifications.handlerstype id / handler id
API interceptorsinterceptorsinterceptor id
Command interceptorscommandInterceptorsinterceptor id
Response enrichersenrichersenricher id
Page guardsguardsmiddleware id
CLI commandsclicommand string
Setup hookssetupmodule id
ACL featuresacl.featuresfeature id
DI bindingsdicontainer key
Encryption mapsencryption.mapsentity id
Sidebar nav orderingnav.groupOrdernav group id

Examples

Full modules.ts Catalog

Use this shape when you need to find the correct key for a domain quickly. Keep only the domains you actually intend to override.

import type { ModuleOverrides } from '@open-mercato/shared/modules/overrides'

export const moduleOverrideExamples: ModuleOverrides = {
  ai: {
    agents: { 'catalog.catalog_assistant': null },
    tools: { inbox_ops_accept_action: null },
  },
  routes: {
    api: { 'DELETE /api/example/items': null },
    pages: { '/backend/example/reports': null },
  },
  events: {
    subscribers: { 'example.todo.audit': null },
  },
  workers: { 'example:sync': null },
  widgets: {
    injection: { 'example.sidebar': null },
    components: { 'page:/backend/example': null },
    dashboard: { 'example.kpi': null },
  },
  notifications: {
    types: { 'example.notice': null },
    handlers: { 'example.notice.toast': null },
  },
  interceptors: { 'example.items.interceptor': null },
  commandInterceptors: { 'example.command.interceptor': null },
  enrichers: { 'example.items.enricher': null },
  guards: { 'example.backend.guard': null },
  cli: { 'example seed': null },
  setup: { seedExamples: false },
  acl: {
    features: { 'example.manage': null },
  },
  di: { exampleService: null },
  encryption: {
    maps: { 'example:item': null },
  },
}

Setting an ACL feature to null is an exact runtime denial, not only a catalog change. The denial wins over a stale explicit database grant, module.*, *, staff super-admin, and portal-admin status. Open Mercato intentionally does not migrate or delete stored grants: they remain inert while the null override exists and become effective again if a higher-precedence definition restores the feature or the null override is removed.

Browser capability fields contain the concrete effective feature IDs after ACL and module overrides are applied. They do not contain wildcard strings or a separate deny-list.

setup overrides apply to the module entry that carries them. For example, setup: { seedExamples: false } on { id: 'catalog', ... } skips catalog's seedExamples hook; it does not address setup hooks by a separate map key.

Routes

overrides: {
  routes: {
    api: {
      'DELETE /api/catalog/products/[id]': null,
      'POST /api/catalog/products': {
        handler: async (req) => Response.json({ ok: true }),
        metadata: { requireAuth: true, requireFeatures: ['catalog.manage'] },
      },
    },
    pages: {
      '/backend/catalog/products': null,
      '/frontend/products': { metadata: { navHidden: true } },
    },
  },
}

Events, Workers, CLI

overrides: {
  events: {
    subscribers: {
      'catalog.product.updated.reindex': null,
    },
  },
  workers: {
    'catalog:reindex': {
      id: 'catalog:reindex',
      queue: 'catalog-reindex-fast',
      concurrency: 4,
      handler: async (job, ctx) => {},
    },
  },
  cli: {
    'catalog reindex': null,
  },
}

Widgets

overrides: {
  widgets: {
    injection: {
      'catalog.product.toolbar': null,
    },
    components: {
      'page:/backend/catalog/products': {
        target: { componentId: 'page:/backend/catalog/products' },
        priority: 10,
        propsTransform: (props) => props,
      },
    },
    dashboard: {
      'catalog.low_stock': null,
    },
  },
}

An injection widget is addressable by two ids: the generated registry key (catalog:product-seo:widget) and the widget module's own widgetId (catalog.injection.product-seo). Either spelling disables or replaces the widget in both the entries registry and every injection table that places it, so you never need to list both – and neither is reported as a stale override.

The dispatcher must also run in the browser. ClientBootstrap re-registers the injection, dashboard and notification registries after hydration, and ComponentOverridesBootstrap re-registers the component overrides, so an app that forks either one MUST call applyModuleOverridesFromEnabledModules(enabledModules, { domains: ['widgets', 'notifications'] }) before those registrations – otherwise the raw generated registries overwrite the filtered ones and a disabled widget or component override reappears once hydration finishes. ComponentOverridesBootstrap must additionally pass the generated component entries through applyComponentOverridesToEntries before flattening them, exactly as the server bootstrap does – dispatching alone only fills the override stores, it does not filter anything. The injection, dashboard and notification registries already apply their own domain filters inside their register* functions, so no extra filtering call is needed for those.

Warning · Keep client-side overrides off server-only env gates

Because the browser re-evaluates src/modules.ts, an enabledModules entry gated on a server-only environment variable MUST NOT carry widgets or notifications overrides. Next.js inlines only NEXT_PUBLIC_* values into the client bundle, so a gate such as parseBooleanWithDefault(process.env.OM_ENABLE_ENTERPRISE_MODULES, false) is always false in the browser: the entry is absent there, the server dispatches its overrides and the client does not, and the widget the server correctly hid reappears the moment hydration finishes.

// ✗ the override is server-only — it never reaches the browser
if (parseBooleanWithDefault(process.env.OM_ENABLE_ENTERPRISE_MODULES, false)) {
  enabledModules.push({
    id: 'record_locks',
    from: '@open-mercato/enterprise',
    overrides: { widgets: { injection: { 'catalog.injection.product-seo': null } } },
  })
}

// ✓ gate the module on the server variable, declare the override on an ungated entry
//   (or gate it on a NEXT_PUBLIC_ variable, which is inlined into both bundles)

Outside production ClientBootstrap compares the browser's enabledModules against the build-time enabled-module-ids.generated list and warns for every module the browser cannot see, so the mismatch shows up in the console instead of silently.

Notifications And Runtime Hooks

overrides: {
  notifications: {
    types: {
      'catalog.low_stock': null,
    },
    handlers: {
      'catalog.low_stock.toast': null,
    },
  },
  interceptors: {
    'catalog.products.audit': null,
  },
  commandInterceptors: {
    'catalog.products.command_audit': null,
  },
  enrichers: {
    'catalog.products.stock_enricher': null,
  },
  guards: {
    'catalog.products.page_guard': null,
  },
}

Setup, ACL, DI, Encryption

overrides: {
  setup: {
    defaultRoleFeatures: {
      admin: ['catalog.view'],
    },
    seedExamples: false,
  },
  acl: {
    features: {
      'catalog.manage': null,
    },
  },
  di: {
    catalogPricingService: {
      register: (container, key) => container.register({ [key]: { mode: 'custom' } }),
    },
  },
  encryption: {
    maps: {
      'catalog:product': null,
    },
  },
}

Core ranks a built-in list of sidebar nav groups ahead of everything else, so an app's own group would otherwise sit below the shipped ones no matter what priority or order its pages declare. nav.groupOrder lets the app decide:

overrides: {
  nav: {
    groupOrder: ['my_app.nav.group'],
  },
}

Per-role ordering is a different mechanism: seed SidebarPreferencesSettings.groupOrder on a RoleSidebarPreference row (see the sidebar customization page, which writes exactly those rows). Use nav.groupOrder for an app-wide default and role preferences when different roles need different orders.

Programmatic Overrides

Use programmatic helpers for env-driven boot decisions and tests:

import {
  applyApiRouteOverrides,
  applyPageRouteOverrides,
  applyWorkerOverrides,
} from '@open-mercato/shared/modules/overrides'

applyApiRouteOverrides({ 'GET /api/example/override-probe': null })
applyPageRouteOverrides({ '/backend/example': null })
applyWorkerOverrides({ 'example:sync': null })

Sidebar nav ordering has the same tier, and it takes precedence over the modules.ts declaration:

import { applyNavGroupOrderOverrides } from '@open-mercato/shared/modules/overrides'

applyNavGroupOrderOverrides(['my_app.nav.group'])
applyNavGroupOrderOverrides(null) // clear, falling back to modules.ts

Programmatic calls must happen before the affected registry registers its base entries. The standard app bootstrap already calls applyModuleOverridesFromEnabledModules(enabledModules) for inline modules.ts overrides.

Both bootstrap paths do this, so modules.ts overrides apply everywhere: the Next.js runtime dispatches them from bootstrap-common.ts, and CLI, worker and scheduler processes dispatch the same overrides from bootstrapFromAppRoot() before registerModules/registerCliModules first read the registry. A src/modules.ts that is present but fails to load aborts that bootstrap rather than continuing with a partial override set (#5582).

Notes

Previous: Modules catalog · Next: Module authoring & discovery