Skip to main content

Architecture

Module dependency graph

Open Mercato is composed of independent modules that you enable per app in apps/mercato/src/modules.ts. Most modules can be disabled freely — but a small subset of foundational modules are pulled in transitively because other modules declare them via ModuleInfo.requires. This page enumerates every module that ships in the monorepo, names its declared dependencies, and explains how the platform enforces the graph.

TL;DR​

  • Declare hard inter-module dependencies in your module's index.ts via metadata.requires: string[].
  • yarn generate fails with a clear message if an enabled module's requires list references a module that is not enabled.
  • Tenant setup (mercato init, setupInitialTenant()) runs seedDefaults and seedExamples in dependency order derived from requires — see packages/shared/src/modules/setup.ts.

Where dependencies are declared​

Each module's root index.ts may export a ModuleInfo metadata object. The requires array names the module ids (the same id you'd put in enabledModules) that must be co-enabled:

// packages/core/src/modules/sales/index.ts
import type { ModuleInfo } from '@open-mercato/shared/modules/registry'

export const metadata: ModuleInfo = {
name: 'sales',
title: 'Sales Management',
version: '0.1.0',
description: 'Quoting, ordering, fulfillment, and billing.',
requires: ['catalog', 'customers', 'dictionaries'],
ejectable: true,
}

The shape lives in packages/shared/src/modules/registry.ts (ModuleInfo). Only the requires field participates in the dependency graph; the other fields (title, description, author, license, ejectable, …) are descriptive metadata.

Enforcement​

The generator reads requires statically: it parses the module's index.ts (or the compiled index.js of a packaged module) and never executes it, so module side effects do not run and packaged TypeScript sources are supported. Only the exported metadata object counts, and requires must be an array of string literals. A declaration built dynamically — a spread, a constant, a computed entry — cannot be read; the generator prints a [generate] ⚠ warning naming the file and skips the check for that module rather than guessing.

The check runs at code-generation time, not at HTTP request time, but the effect on the running app is the same: if a required module is missing the generator refuses to write modules.generated.ts.

Module dependency check failed:
- Module "sales" requires: catalog, customers, dictionaries
Fix: Enable module 'catalog' in src/modules.ts.
Fix: Enable module 'customers' in src/modules.ts.
Fix: Enable module 'dictionaries' in src/modules.ts.

(See extractModuleRequiresFromSource and findMissingModuleRequires in packages/cli/src/lib/generators/module-registry.ts.) Because the generator emits the registry that the Next.js dispatcher imports, a failed yarn generate means the app cannot boot until the dependency is satisfied.

In addition, seedDefaults and seedExamples hooks in each module's setup.ts are executed in topological order derived from requires so that a dependent module sees the data its dependency seeded.

Optional capabilities and diagnostics​

Declare metadata.optionalRequires when a peer module adds a capability and the owner can run without it. Provide an English <owner>.optionalRequires.<peer> label and guard references to the peer where they execute. Use the shared server-side isModuleEnabled helper when the enabled registry determines whether the operation is available.

Run yarn mercato module doctor in an app to see missing dependencies, inactive capabilities, and static source findings. Run yarn mercato module list --all to inspect installed modules. In this repository, yarn check:module-coupling --fail checks declarations, guards, direction and integration metadata against the committed baseline. Use --prune-baseline to remove resolved pairs. The packed kernel smoke builds and boots a reduced app with business modules disabled. Business implementations still in Core remain in its installed tarball until their extraction.

Module catalog​

The tables below list the modules that ship in the monorepo and the create-app templates, including every module that declares or is the target of a requires edge (the edge list under Reading the graph is the complete, enforced set). The Requires column reproduces the module's declared metadata.requires; an empty cell means the module has no declared hard dependencies. Foundational marks modules that another module declares as a dependency — disabling one of these is only safe if every dependent module is also disabled.

Core platform (@open-mercato/core)​

Module idTitleRequiresFoundational?
api_docsAPI Documentation—
api_keysAPI Keysauth
attachmentsAttachments—✅ (catalog, documents, forms)
audit_logsAudit & Action Logs—
authAuthentication & Accounts—✅ (api_keys, devices, documents, push_notifications)
business_rulesBusiness Rules—✅ (workflows)
cartCartcatalog, sales, customer_groups, promotions
catalogProduct Catalogattachments, currencies, dictionaries, entities✅ (cart, ecommerce, eudr, sales, sync_akeneo, wms)
communication_channelsCommunication Channelsprogress✅ (channel_resend, channel_ses, channel_smtp, push_notifications)
configsConfiguration—
currenciesCurrencies—✅ (catalog)
customer_accountsCustomer Identity & Portal Authentication—✅ (forms, portal)
customer_groupsCustomer Groups & B2B Terms—✅ (cart)
customersCustomer Relationship Managementprogress, dictionaries, feature_toggles✅ (sales, sync_excel)
dashboardsAdmin Dashboards—
data_syncData Sync—✅ (sync_akeneo, sync_excel)
devicesDevicesauth✅ (push_notifications)
dictionariesShared Dictionaries—✅ (catalog, customers, sales, staff)
directoryDirectory (Tenants & Organizations)—✅ (documents)
ecommerceEcommerce Storescatalog, sales
entitiesCustom Entities & Fieldsquery_index✅ (catalog)
eudrEUDR Compliancecatalog
feature_togglesFeature Toggles—✅ (customers, portal)
formsFormsattachments, customer_accounts
inbox_opsInboxOps — Email-to-ERP Agent—
integrationsIntegrations—✅ (channel_resend, channel_ses, channel_smtp, push_notifications, sync_akeneo, tillio)
messagesMessages—
notificationsNotifications—✅ (push_notifications)
payment_gatewaysPayment Gateways—
perspectivesTable perspectives—
phone_callsPhone Calls—✅ (tillio)
plannerWorktime / Availabilities—✅ (staff)
portalCustomer Portalcustomer_accounts, feature_toggles
progressProgress—✅ (communication_channels, customers, sync_akeneo)
promotionsPromotions—✅ (cart)
push_notificationsPush Notificationsauth, devices, notifications, communication_channels, integrations
query_indexQuery Indexes—✅ (entities)
resourcesResource planning—✅ (staff)
salesSales Managementcatalog, customers, dictionaries✅ (cart, ecommerce, wms)
shipping_carriersShipping Carriers—
staffEmployeesplanner, resources, dictionaries
sync_excelExcel / CSV Importcustomers, data_sync
translationsEntity Translations—
wmsWarehouse Management Systemcatalog, sales
workflowsWorkflow Enginebusiness_rules

Other first-party packages​

Module idPackageRequiresFoundational?
ai_assistant@open-mercato/ai-assistant—
channel_resend@open-mercato/channel-resendcommunication_channels, integrations
channel_ses@open-mercato/channel-sescommunication_channels, integrations
channel_smtp@open-mercato/channel-smtpcommunication_channels, integrations
checkout@open-mercato/checkout—
content@open-mercato/content—
documents@open-mercato/documentsauth, directory, attachments
events@open-mercato/events—
gateway_stripe@open-mercato/gateway-stripe—
onboarding@open-mercato/onboarding—
scheduler@open-mercato/scheduler—
search@open-mercato/search—
sync_akeneo@open-mercato/sync-akeneointegrations, data_sync, catalog, progress
tillio@open-mercato/tilliointegrations, phone_calls
webhooks@open-mercato/webhooks—

Enterprise (@open-mercato/enterprise)​

Enterprise modules are off by default. Toggle them via OM_ENABLE_ENTERPRISE_MODULES, OM_ENABLE_ENTERPRISE_MODULES_SSO, OM_ENABLE_ENTERPRISE_MODULES_SECURITY, and OM_ENABLE_ENTERPRISE_MODULES_AGENTS.

Module idTitleRequires
agent_orchestratorAgent Orchestrator—
record_locksRecord Locking—
securitySecurity—
ssoSingle Sign-On—
system_status_overlaysSystem Status Overlays—

Templates and examples​

These are scaffolded into new apps by create-app but are not enabled in the monorepo dev app.

Module idPackageRequires
example@open-mercato/create-app template—
example_customers_sync@open-mercato/create-app template—

Reading the graph​

The current declared edges are:

api_keys → auth
cart → catalog, sales, customer_groups, promotions
catalog → attachments, currencies, dictionaries, entities
channel_resend → communication_channels, integrations
channel_ses → communication_channels, integrations
channel_smtp → communication_channels, integrations
communication_channels → progress
customers → progress, dictionaries, feature_toggles
devices → auth
documents → auth, directory, attachments
ecommerce → catalog, sales
entities → query_index
eudr → catalog
forms → attachments, customer_accounts
portal → customer_accounts, feature_toggles
push_notifications → auth, devices, notifications, communication_channels, integrations
sales → catalog, customers, dictionaries
staff → planner, resources, dictionaries
sync_akeneo → integrations, data_sync, catalog, progress
sync_excel → customers, data_sync
tillio → integrations, phone_calls
wms → catalog, sales
workflows → business_rules

Transitive closures worth noting:

  • Enabling staff requires planner, resources, and dictionaries, so the effective set is { dictionaries, planner, resources, staff }. resources alone requires neither planner nor dictionaries; without them its availability section and dictionary-backed labels are unavailable.
  • Enabling sync_akeneo implicitly requires what catalog requires, plus progress: { attachments, catalog, currencies, data_sync, dictionaries, entities, integrations, progress, query_index, sync_akeneo }. sales is an optional peer: when it is disabled, the importer skips channel-bound offers and prices and logs the sync_akeneo.sales_channels_unavailable warning.
  • Enabling sales implicitly requires progress and feature_toggles too, since sales requires customers, which now requires progress, dictionaries, and feature_toggles.
  • entities requires query_index because hybrid querying for custom entities is delegated to the query-index layer.

A module that does not appear on the right-hand side of any arrow (no module has it as requires) is safe to remove from enabledModules without breaking another enabled module. That said, individual modules may still have soft runtime expectations (for example, a module's UI might link to another module's page) that the dependency graph does not capture — treat the graph as the floor, not the ceiling.

Adding a new dependency​

When you build a module that depends on another:

  1. Edit your module's index.ts and add the dependency id to metadata.requires.
  2. Run yarn generate. If the dependency is not enabled in the consuming app, the generator will fail with the message above.
  3. If your module relies on a dependency's setup data (currencies, dictionaries, statuses, …), put that logic in setup.ts under seedDefaults/seedExamples; the platform already invokes those hooks in dependency order.
  4. Document the new dependency in your module's AGENTS.md or matching framework/modules/<module>.mdx page so other contributors can discover it.

Never reach across modules with direct ORM relationships — declare the dependency in requires and load data via the dependency's public services or the query engine. See AGENTS.md → Critical Rules → Architecture for the broader rule set.

See also​