Open MercatoDocsSearch docsAPI reference

Architecture

Generator architecture

A new route on disk has to reach a runtime registry before a request can use it. Follow the generator from the module scan to the files your application loads.

yarn generate is the registry compiler for Open Mercato. It scans enabled modules, applies built-in generator extensions, loads optional module-declared plugins, and emits the generated files consumed by routing, DI bootstrap, CLI dispatch, widgets, notifications, search, and other runtime registries.

High-level flow

Module files pass through generators into runtime registries
The same generator run supplies routing, service registration, UI contributions and the CLI.
Diagram source
flowchart TD
  subgraph Inputs["Module inputs"]
    modules["enabled modules<br/>src/modules.ts"]
    conventions["convention files<br/>cli.ts, index.ts, api/, backend/, frontend/, di.ts, search.ts, widgets, workers, subscribers"]
    plugins["optional generators.ts<br/>exports generatorPlugins[]"]
  end

  subgraph Engine["Generator engine"]
    scan["scan enabled module roots"]
    builtins["apply built-in extensions"]
    modulePlugins["load module-declared plugins"]
    emit["emit .mercato/generated/*"]
  end

  subgraph Runtime["Runtime consumers"]
    routes["route dispatchers"]
    bootstrap["bootstrap + DI registration"]
    cli["CLI registry"]
    ui["widgets, middleware, notifications"]
    openapi["OpenAPI build"]
  end

  modules --> scan
  conventions --> scan
  plugins --> modulePlugins
  scan --> builtins --> emit
  modulePlugins --> emit
  emit --> routes
  emit --> bootstrap
  emit --> cli
  emit --> ui
  emit --> openapi

    classDef focus fill:#e0f29c,stroke:#34402d,color:#172011,stroke-width:2px
    class emit focus

Two extension layers

Open Mercato uses two additive extension layers during generation:

Built-in generators and generators supplied by modules
A module can provide a generator plugin alongside the built-in extension points.
Diagram source
flowchart TD
  root["Generator engine"] --> built["Built-in extensions"]
  root --> custom["Module-declared plugins"]
  built --> registry["Registry contributions<br/>search, AI tools, events and analytics"]
  built --> ui["UI contributions<br/>widgets, notifications, messages and overrides"]
  built --> intercept["Extension hooks<br/>middleware, enrichers, guards and interceptors"]
  custom --> exports["generators.ts exports plugins"]
  exports --> contract["GeneratorPlugin contract"]
  contract --> output["Plugin-specific generated files"]
    classDef focus fill:#e0f29c,stroke:#34402d,color:#172011,stroke-width:2px
    class root focus

Built-in extensions

These are framework-owned registries that every app can rely on without extra plugin authoring:

Module-declared plugins

Modules can extend generation without editing the generator package by exporting generatorPlugins from generators.ts.

Plugin contract summary:

FieldMeaning
idUnique registry/plugin family ID
conventionFileModule-local file to scan for plugin entries
importPrefixPrefix for generated import variable names
configExpr(importName, moduleId)Expression that turns a discovered module file into one generated entry
outputFileNameGenerated file produced by the plugin
buildOutput(...)Function that renders the generated TypeScript source
bootstrapRegistrationOptional bootstrap-time registration contribution

This is what keeps generator architecture additive: new registry families can ship as module-owned plugin definitions rather than as hard-coded cases in the root generator.

Core generated files

These are the primary generated files emitted by the core generator pipeline.

Generated filePurpose
modules.generated.tsFull discovered module graph, including rich runtime metadata used by framework registries and compatibility paths.
modules.runtime.generated.tsRuntime-focused module registry used by the current lightweight bootstrap/runtime path.
modules.app.generated.tsApp bootstrap registry used by application startup without route-heavy coupling.
modules.cli.generated.tsCLI module registry loaded by yarn mercato for module-owned commands.
cli-modules.generated.tsConvenience export/wrapper around the generated CLI module list.
bootstrap-modules.generated.tsBootstrap-oriented module registry helpers used during startup assembly.
bootstrap-registrations.generated.tsGenerated bootstrap registration calls, including optional plugin-contributed registrations.
entities.generated.tsMikroORM entity registry for discovered modules.
entities.ids.generated.tsStable generated entity ID constants.
entity-fields-registry.tsGenerated entity-fields registry used by encryption and related metadata consumers.
di.generated.tsDiscovered DI registrars for enabled modules.
frontend-routes.generated.tsFrontend route manifest with lazy route-loading metadata.
backend-routes.generated.tsBackend route manifest with lazy route-loading metadata.
api-routes.generated.tsAPI route manifest with method/path metadata and lazy handlers.
subscribers.generated.tsLegacy/generated subscriber registry compatibility file.
openapi.generated.jsonGenerated OpenAPI document built from discovered API routes and route metadata.
module-package-sources.cssGenerated stylesheet that tracks module package source markers for runtime styling/diagnostics.

Built-in extension outputs

These generated files come from built-in generator extensions.

Generated fileSource extensionPurpose
search.generated.tssearchSearch module config registry.
notifications.generated.tsnotificationsNotification type registry.
notifications.client.generated.tsnotificationsClient-side notification renderers.
payments.client.generated.tsnotificationsPayment-related notification/client adapters.
notification-handlers.generated.tsnotificationsReactive notification side-effect handlers.
message-types.generated.tsmessagesMessage type registry.
message-objects.generated.tsmessagesMessage object registry.
messages.client.generated.tsmessagesClient-side message object renderers/adapters.
ai-tools.generated.tsai-toolsAI/MCP tool registry.
events.generated.tseventsEvent definitions and event registry metadata.
analytics.generated.tsanalyticsAnalytics/dashboard configuration registry.
translations-fields.generated.tstranslatable-fieldsTranslatable field declarations by module/entity.
enrichers.generated.tsenrichersResponse enricher registry.
interceptors.generated.tsinterceptorsAPI interceptor registry.
component-overrides.generated.tscomponent-overridesUI component override registry.
inbox-actions.generated.tsinbox-actionsInbox action registry.
guards.generated.tsguardsMutation/page/runtime guard registry.
command-interceptors.generated.tscommand-interceptorsCommand interceptor registry.
frontend-middleware.generated.tspage-middlewareFrontend page middleware registry.
backend-middleware.generated.tspage-middlewareBackend page middleware registry.
dashboard-widgets.generated.tsdashboard-widgetsDashboard widget registry.
injection-widgets.generated.tsinjection-widgetsInjection widget registry.
injection-tables.generated.tsinjection-widgetsInjection table/slot registry.

Why this architecture exists

Relationship to cache CLI

The cache command is a normal cli.ts discovery case, not a generator plugin. It is documented separately in Cache CLI architecture. That page focuses on cache-specific runtime behavior, while this page documents the broader generator system that makes module-owned commands discoverable.

Previous: Platform roadmap and release status · Next: Glossary