Open MercatoDocsSearch docsAPI reference

REST API

Module registry API

Use the module registry to discover what an application loaded. Its declarations describe the available routes and features that can be used when provisioning roles.

Open the API Explorer at /docs/api on your Open Mercato instance to inspect request and response schemas or try a call with an API key.

Open Mercato keeps module metadata in a generated file rather than a dedicated REST endpoint. When you run yarn generate, the generator writes generated/modules.generated.ts, which exports the module graph consumed by the API dispatcher, navigation builders, and the OpenAPI generator.

import { modules, modulesInfo } from '@/generated/modules.generated'

modulesInfo.forEach((entry) => {
  console.log(entry.id, entry.title)
})

const authApis = modules
  .find((m) => m.id === 'auth')
  ?.apis?.map((api) => ('handlers' in api ? api.path : api.path))

Shapes and helpers

The exported types live in packages/shared/src/modules/registry.ts:

These structures are stable runtime contracts and can be imported anywhere in your application (Next.js server components, scripts, CLI tooling).

Enumerating APIs at runtime

import { modules } from '@/generated/modules.generated'
import type { ModuleApiRouteFile } from '@open-mercato/shared/modules/registry'

const apiIndex = modules.flatMap((module) => {
  return (module.apis ?? [])
    .filter((api): api is ModuleApiRouteFile => 'handlers' in api)
    .map((api) => ({
      moduleId: module.id,
      path: api.path,
      methods: Object.keys(api.handlers),
      requireAuth: api.metadata?.GET?.requireAuth ?? api.metadata?.POST?.requireAuth ?? false,
      requireFeatures: api.metadata?.GET?.requireFeatures ?? api.metadata?.POST?.requireFeatures ?? []
    }))
})

console.table(apiIndex)

Features and ACL seeding

Each module declares its feature flags in <module>/acl.ts. The generator hoists them into module.features, enabling tooling to seed default roles or audit coverage:

import { modules } from '@/generated/modules.generated'

const featureMatrix = modules.flatMap((module) =>
  (module.features ?? []).map((feature) => ({
    module: module.id,
    feature: feature.id,
    title: feature.title ?? feature.id
  }))
)

Combine this with the Auth module’s GET /auth/features endpoint when you need a remote-friendly list; the HTTP route pads the same data with translations (packages/core/src/modules/auth/api/features.ts:5).

When to regenerate


Rather than hitting a /modules HTTP endpoint, import the generated registry to inspect enabled modules, enumerate APIs, or reason about feature coverage. This keeps build artifacts deterministic while still giving you the structured metadata needed for automation.

For a human-readable list of every module that ships with Open Mercato, plus the requires graph that ties them together and how it is enforced, see Module dependency graph.

Previous: Integrations and data sync API · Next: REST API Overview