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.tsviametadata.requires: string[]. yarn generatefails with a clear message if an enabled module'srequireslist references a module that is not enabled.- Tenant setup (
mercato init,setupInitialTenant()) runsseedDefaultsandseedExamplesin dependency order derived fromrequires— seepackages/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 id | Title | Requires | Foundational? |
|---|---|---|---|
api_docs | API Documentation | — | |
api_keys | API Keys | auth | |
attachments | Attachments | — | ✅ (catalog, documents, forms) |
audit_logs | Audit & Action Logs | — | |
auth | Authentication & Accounts | — | ✅ (api_keys, devices, documents, push_notifications) |
business_rules | Business Rules | — | ✅ (workflows) |
cart | Cart | catalog, sales, customer_groups, promotions | |
catalog | Product Catalog | attachments, currencies, dictionaries, entities | ✅ (cart, ecommerce, eudr, sales, sync_akeneo, wms) |
communication_channels | Communication Channels | progress | ✅ (channel_resend, channel_ses, channel_smtp, push_notifications) |
configs | Configuration | — | |
currencies | Currencies | — | ✅ (catalog) |
customer_accounts | Customer Identity & Portal Authentication | — | ✅ (forms, portal) |
customer_groups | Customer Groups & B2B Terms | — | ✅ (cart) |
customers | Customer Relationship Management | progress, dictionaries, feature_toggles | ✅ (sales, sync_excel) |
dashboards | Admin Dashboards | — | |
data_sync | Data Sync | — | ✅ (sync_akeneo, sync_excel) |
devices | Devices | auth | ✅ (push_notifications) |
dictionaries | Shared Dictionaries | — | ✅ (catalog, customers, sales, staff) |
directory | Directory (Tenants & Organizations) | — | ✅ (documents) |
ecommerce | Ecommerce Stores | catalog, sales | |
entities | Custom Entities & Fields | query_index | ✅ (catalog) |
eudr | EUDR Compliance | catalog | |
feature_toggles | Feature Toggles | — | ✅ (customers, portal) |
forms | Forms | attachments, customer_accounts | |
inbox_ops | InboxOps — Email-to-ERP Agent | — | |
integrations | Integrations | — | ✅ (channel_resend, channel_ses, channel_smtp, push_notifications, sync_akeneo, tillio) |
messages | Messages | — | |
notifications | Notifications | — | ✅ (push_notifications) |
payment_gateways | Payment Gateways | — | |
perspectives | Table perspectives | — | |
phone_calls | Phone Calls | — | ✅ (tillio) |
planner | Worktime / Availabilities | — | ✅ (staff) |
portal | Customer Portal | customer_accounts, feature_toggles | |
progress | Progress | — | ✅ (communication_channels, customers, sync_akeneo) |
promotions | Promotions | — | ✅ (cart) |
push_notifications | Push Notifications | auth, devices, notifications, communication_channels, integrations | |
query_index | Query Indexes | — | ✅ (entities) |
resources | Resource planning | — | ✅ (staff) |
sales | Sales Management | catalog, customers, dictionaries | ✅ (cart, ecommerce, wms) |
shipping_carriers | Shipping Carriers | — | |
staff | Employees | planner, resources, dictionaries | |
sync_excel | Excel / CSV Import | customers, data_sync | |
translations | Entity Translations | — | |
wms | Warehouse Management System | catalog, sales | |
workflows | Workflow Engine | business_rules |
Other first-party packages
| Module id | Package | Requires | Foundational? |
|---|---|---|---|
ai_assistant | @open-mercato/ai-assistant | — | |
channel_resend | @open-mercato/channel-resend | communication_channels, integrations | |
channel_ses | @open-mercato/channel-ses | communication_channels, integrations | |
channel_smtp | @open-mercato/channel-smtp | communication_channels, integrations | |
checkout | @open-mercato/checkout | — | |
content | @open-mercato/content | — | |
documents | @open-mercato/documents | auth, 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-akeneo | integrations, data_sync, catalog, progress | |
tillio | @open-mercato/tillio | integrations, 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 id | Title | Requires |
|---|---|---|
agent_orchestrator | Agent Orchestrator | — |
record_locks | Record Locking | — |
security | Security | — |
sso | Single Sign-On | — |
system_status_overlays | System Status Overlays | — |
Templates and examples
These are scaffolded into new apps by create-app but are not enabled in the monorepo dev app.
| Module id | Package | Requires |
|---|---|---|
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
staffrequiresplanner,resources, anddictionaries, so the effective set is{ dictionaries, planner, resources, staff }.resourcesalone requires neitherplannernordictionaries; without them its availability section and dictionary-backed labels are unavailable. - Enabling
sync_akeneoimplicitly requires whatcatalogrequires, plusprogress:{ attachments, catalog, currencies, data_sync, dictionaries, entities, integrations, progress, query_index, sync_akeneo }.salesis an optional peer: when it is disabled, the importer skips channel-bound offers and prices and logs thesync_akeneo.sales_channels_unavailablewarning. - Enabling
salesimplicitly requiresprogressandfeature_togglestoo, sincesalesrequirescustomers, which now requiresprogress,dictionaries, andfeature_toggles. entitiesrequiresquery_indexbecause 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:
- Edit your module's
index.tsand add the dependency id tometadata.requires. - Run
yarn generate. If the dependency is not enabled in the consuming app, the generator will fail with the message above. - If your module relies on a dependency's setup data (currencies, dictionaries, statuses, …), put that logic in
setup.tsunderseedDefaults/seedExamples; the platform already invokes those hooks in dependency order. - Document the new dependency in your module's
AGENTS.mdor matchingframework/modules/<module>.mdxpage 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
- Module registry API — programmatic access to
modules,modulesInfo, and the generated registry. - Modules: authoring and usage — module conventions, discovery, and overrides.
- System overview — how modules feed into the generator and the runtime registry.