Open MercatoDocsSearch docsAPI reference

Customization

Create your first module

Give the stock team a page called Inventory. A page with no records is enough for this first step: opening it proves that the app found the module, generated its route and granted your account access.

With the base app running, add a custom inventory module directly inside the app. Modules placed under apps/mercato/src/modules/<id>/ (or src/modules/<id>/ in a standalone app) are automatically resolved when you register them with from: '@app' -- no separate package setup required.

Before you build, search modules.openmercato.com. The feature you need may already exist as a module you can install with one command.

Info · Monorepo vs. standalone paths

This tutorial uses monorepo paths (apps/mercato/src/modules/). If you scaffolded a standalone app with create-mercato-app, replace every apps/mercato/src/ prefix with src/. Everything else is identical.

1. Scaffold the module

mkdir -p apps/mercato/src/modules/inventory
touch apps/mercato/src/modules/inventory/{index.ts,acl.ts,setup.ts,di.ts}

Populate the metadata in index.ts so the module shows up in registries:

import type { ModuleInfo } from '@open-mercato/shared/modules/registry';

export const metadata: ModuleInfo = {
  name: 'inventory',
  title: 'Inventory',
  version: '0.1.0',
  description: 'Track stock levels for sellable items.',
};

Declare the RBAC features you plan to enforce in acl.ts:

export const features = [
  { id: 'inventory.view',   title: 'View inventory',   module: 'inventory' },
  { id: 'inventory.create', title: 'Create inventory', module: 'inventory' },
  { id: 'inventory.edit',   title: 'Edit inventory',   module: 'inventory' },
  { id: 'inventory.delete', title: 'Delete inventory', module: 'inventory' },
];

export default features;

Every module that declares features in acl.ts should also create a setup.ts file with defaultRoleFeatures. Without this, the features exist but no role will have them assigned by default -- users would need to manually grant them from the admin panel:

import type { ModuleSetupConfig } from '@open-mercato/shared/modules/setup';

export const setup: ModuleSetupConfig = {
  defaultRoleFeatures: {
    admin: ['inventory.*'],
    employee: ['inventory.view'],
  },
};

export default setup;

Create an Awilix registrar in di.ts even if you do not wire services yet -- the file keeps the structure predictable:

import type { AppContainer } from '@open-mercato/shared/lib/di/container';

export function register(_: AppContainer) {
  // Register services when you introduce business logic.
}

2. Enable the module

Open apps/mercato/src/modules.ts and add the new entry to the enabledModules array:

export const enabledModules: ModuleEntry[] = [
  // ... existing modules ...
  { id: 'inventory', from: '@app' }, // new module
];

The from: '@app' value tells the generator to look for the module inside apps/mercato/src/modules/inventory/.

Run the generators so the new module is included in the registry:

yarn generate

3. Add the first page

Create the backend page directory and metadata:

mkdir -p apps/mercato/src/modules/inventory/backend/inventory
touch apps/mercato/src/modules/inventory/backend/inventory/page.tsx
touch apps/mercato/src/modules/inventory/backend/inventory/page.meta.ts
const InventoryLanding = () => {
  return (
    <div className="container">
      <h1 className="margin-bottom--md">Inventory</h1>
      <p>Welcome! You will add data grids and forms in the next steps.</p>
    </div>
  );
};

export default InventoryLanding;
import type { PageMetadata } from '@open-mercato/shared/modules/registry';

export const metadata: PageMetadata = {
  title: 'Inventory',
  group: 'Operations',
  order: 20,
  requireAuth: true,
  requireFeatures: ['inventory.view'],
};

After adding pages, regenerate the module registry and clear the navigation cache so the sidebar picks up the new page:

yarn generate
yarn mercato configs cache structural --all-tenants

Restart the dev server (or wait for hot reload) and open /backend. You should now see an Inventory link in the sidebar that leads to the placeholder page.

Tip · Existing reference modules

Browse apps/mercato/src/modules/example/ for a full working module that exercises most platform features (entities, APIs, forms, grids, events, dashboard widgets, custom fields, and injection) – or start from the Reference Example Module showcase, which indexes every capability it demonstrates with an exact link to the source. Core modules from @open-mercato/core can be customized by adding override files under apps/mercato/src/modules/auth, apps/mercato/src/modules/directory, etc.

Tip · Publish your module

If you've built a module that would be useful for others, publish it as an npm package with create-mercato-module and list it on modules.openmercato.com/submit. Other Open Mercato users then find it in the Modules catalog and install it with one command.

Check discovery and access separately

First load the page with a role that has the module's view feature. Then sign in with a role that lacks it. If neither account can find the route, inspect registration and regeneration. If only the second account is refused, the access check is doing its job.

Previous: Build your first Open Mercato app · Next: Create the data API