Reference

Tenant

Configure tenants — isolated databases and code roots for multi-tenant apps.

A tenant is an isolated slice of your app: its own MongoDB connection and its own on-disk folder for collections, routes, and scripts.

Required fields

FieldDescription
idUnique identifier used in URLs: POST /api/:tenant_id/:collection/:action.
dirPath relative to the project root (working directory when the server starts). dnax resolves collections/, routes/, and scripts/ under this path. Omitting dir is not supported.
database.uriMongoDB connection string for this tenant.

Optional fields

FieldDescription
nameHuman-readable label (logging, UI).
descriptionFree-text description.
routes.prefixBase path for custom routes (**/*.route.ts). Without a prefix, the routes/ folder is not loaded.
database.optionsExtra options passed to the MongoDB client.

Example

import { define, app } from '@dnax/core';

await app.boot(
  define.Server({
    server: { port: 4000 },
    tenants: [
      {
        id: 'v1',
        dir: 'v1',
        routes: { prefix: '/api/v1' },
        database: { uri: 'mongodb://localhost:27017/myapp' },
      },
    ],
  }),
);

Layout under dir

Relative to tenant.dir (e.g. v1/):

PathRole
collections/**/*.model.tsCollection models
routes/**/*.route.tsCustom HTTP routes (needs routes.prefix)
scripts/**/*.run.tsScripts run shortly after boot
services/**/*.service.tsTenant-scoped services exposed under /services/:tenant_id/...

Several tenants can share the same dir or use different folders (e.g. v1, tenants/client-a).

For a full repo layout (cache, config/, uploads/, optional services/, tasks/, etc.), see Project structure.

See also

Copyright © 2026