Open MercatoDocsSearch docsAPI reference

Tutorials

Tutorial - authoring your first module

Build a module end to end. Register its services, add a persistent entity and expose that entity through the application so you can exercise the feature.

This guide extends the first app tutorial by taking a blank module from concept to shipped feature set. You will:

Info · Looking for inspiration?

The packages/example workspace ships a full example module that exercises most of the platform features and extensibility points. Browse it as a reference implementation before starting your own module to see how everything connects end to end.

1. Scaffold the module

mkdir -p packages/inventory/src/modules/inventory_items
touch packages/inventory/src/modules/inventory_items/{index.ts,acl.ts,di.ts}

Populate the module metadata and features:

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

export const metadata: ModuleInfo = {
  name: 'inventory_items',
  title: 'Inventory Items',
  version: '0.1.0',
  description: 'Track stock levels and product availability.',
};
export const features = [
  'inventory_items.view',
  'inventory_items.create',
  'inventory_items.edit',
  'inventory_items.delete',
];

2. Wire dependency injection

import { asClass } from 'awilix';
import type { AppContainer } from '@open-mercato/shared/lib/di/container';
import { InventoryService } from './services/inventory-service';

export function register(container: AppContainer) {
  container.register({
    inventoryService: asClass(InventoryService).scoped(),
  });
}

3. Define entities and migrations

Create data/entities.ts with MikroORM definitions and run yarn generate && yarn db:generate to emit migrations. Remember to include organization_id, tenant_id, and soft-delete columns when appropriate.

4. Build CRUD APIs and admin UI

5. Add dashboards and subscribers

Finally, enable the module in apps/mercato/src/modules.ts, re-run yarn generate, and restart the dev server. You have a fully fledged module with end-to-end functionality ready for production.

6. Publish and list it

Once your module is production-ready, share it with other Open Mercato apps:

  1. Publish it as an npm package with create-mercato-module, following Publishing Custom Modules.
  2. List it on modules.openmercato.com/submit: paste the package name. The page builds the catalog entry and opens GitHub with the file filled in; commit it and open the pull request.

After the merge the catalog reads the module from its published source and installs it every night, so other developers and their agents can find it. See Modules catalog for what Listed and Verified mean.

Previous: API data fetching tutorial · Next: Building a Todo Module with Custom Fields