Tutorials
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.
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',
];
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(),
});
}
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.
api/items/route.ts.backend/items/page.tsx and backend/items/create/page.tsx with CrudForm and DataGrid.widgets/dashboard/stock/widget.ts to surface KPIs.subscribers/stock-adjusted.ts by emitting notifications or syncing external systems.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.
Once your module is production-ready, share it with other Open Mercato apps:
create-mercato-module, following Publishing Custom Modules.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