Open MercatoDocsSearch docsAPI reference

Framework

Module authoring & discovery

A module is the boundary around a business feature. Start with the entity it owns, then locate the page, API and permissions that expose it. Generated registries tell the runtime which of those contributions your application enabled.

This app supports modular features delivered as either:

In a standalone app, local modules live under src/modules/ and are registered in src/modules.ts. To scaffold one, publish it as an npm package and dedicated GitHub repository, or link repository development back into the same app, see Publishing Custom Modules.

Conventions

Module Interface

Metadata (index.ts)

Create @open-mercato/core/modules/<module>/index.ts exporting metadata (or override via apps/mercato/src/modules/<module>/index.ts):

import type { ModuleInfo } from '@/modules/registry'

export const metadata: ModuleInfo = {
  name: '<module-id>',
  title: 'Human readable title',
  version: '0.1.0',
  description: 'Short description',
  author: 'You',
  license: 'MIT',
  // Optional: declare hard dependencies (module ids)
  // The generator will fail with a clear message if missing
  requires: ['some_other_module']
}

Generators expose modulesInfo for listing.

Dependency Injection (di.ts)

Create @open-mercato/core/modules/<module>/di.ts exporting register(container) to add/override services and components. To override/extend, add apps/mercato/src/modules/<module>/di.ts.

import { asClass, asValue } from 'awilix'
import type { AppContainer } from '@/lib/di/container'

export function register(container: AppContainer) {
  // container.register({ myService: asClass(MyService).scoped() })
  // container.register({ myComponent: asValue(MyComponent) })
}

Routes (Auto-discovery + Overrides)

Widget Injection (Centralized Registry)

Page Metadata

Precedence: if a *.meta.ts file is present it is used; otherwise, the generator will look for export const metadata in the page module (server-only).

Override Example

API Endpoints (Auto-discovery + Overrides)

Database Schema and Migrations (MikroORM)

See also:

EBAC Events & Subscribers

Declaring Custom Entities and Fields in ce.ts (data/fields.ts deprecated)

export const entities = [
  {
    id: 'my_module:calendar_entity',
    label: 'Calendar Entity',
    showInSidebar: true,
    fields: [
      { key: 'title', kind: 'text', label: 'Title', required: true, indexed: true, filterable: true, formEditable: true },
      { key: 'when', kind: 'text', label: 'When', filterable: true, formEditable: true },
      { key: 'location', kind: 'text', label: 'Location', filterable: true, formEditable: true },
      { key: 'notes', kind: 'multiline', label: 'Notes', editor: 'markdown', formEditable: true },
    ],
  },
]

Notes:

Validation (zod)

CLI

Adding an External Module

  1. Install the npm package (must be ESM compatible) into node_modules.
  2. Expose a pseudo-tree under apps/mercato/src/modules/<module> via a postinstall script or a wrapper package; or copy its files into apps/mercato/src/modules/<module>.
  3. Ensure it ships its MikroORM entities under /db/entities.ts so migrations generate.
  4. Run yarn generate to refresh the registry, entities, and DI.

Translations (i18n)

Client usage:

"use client"
import { useT } from '@/lib/i18n/context'
import { translateWithFallback } from '@open-mercato/shared/lib/i18n/translate'

export default function MyComponent() {
  const t = useT()
  const heading = translateWithFallback(t, 'my_module.moduleTitle', 'My Module')
  return <h1>{heading}</h1>
}

Server usage:

import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'

export default async function Page() {
  const { translate } = await resolveTranslations()
  const title = translate('backend.title', 'Dashboard')
  const subtitle = translate('backend.subtitle', 'Manage your workspace', { org: 'Acme' })
  return (
    <>
      <h1>{title}</h1>
      <p>{subtitle}</p>
    </>
  )
}

Module Isomorphism

Modules must be isomorphic (self-contained) to ensure proper isolation and migration generation:

This ensures that:

Multi-tenant

Listing and Overriding

Enabling Modules

Monorepo, Overrides, and Module Config

Find modules

Beyond core and app-level modules, the core team, partners, and the community publish reusable modules as npm packages. Open Mercato Modules lists them with what each one adds, its license, and the Open Mercato versions it installs on. They install in one command and can be ejected for full local ownership. Search it before you build a feature, and list your own module there to share it without modifying the core platform.

See Modules catalog for installation, ejection, and listing details.

Learning from a Real Module

Before building from scratch, check the Reference Example Module showcase – a capability-by-capability index into apps/mercato/src/modules/example/, the canonical, source-present-but-runtime-disabled module that demonstrates nearly every extension point this framework exposes (entities, APIs, forms, events, UMES, AI tools, and more), each with an exact link to the file that proves it.

Read a working module from the outside in

Open src/modules/example/backend/todos/ in a classic standalone app. Follow the page into api/todos/route.ts, then inspect data/entities.ts, commands/ and acl.ts under the same module. The directory boundary shows which code is responsible for the record.

Previous: Module overrides · Next: Payment Gateways