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
| Field | Description |
|---|---|
id | Unique identifier used in URLs: POST /api/:tenant_id/:collection/:action. |
dir | Path 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.uri | MongoDB connection string for this tenant. |
Optional fields
| Field | Description |
|---|---|
name | Human-readable label (logging, UI). |
description | Free-text description. |
routes.prefix | Base path for custom routes (**/*.route.ts). Without a prefix, the routes/ folder is not loaded. |
database.options | Extra 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/):
| Path | Role |
|---|---|
collections/**/*.model.ts | Collection models |
routes/**/*.route.ts | Custom HTTP routes (needs routes.prefix) |
scripts/**/*.run.ts | Scripts run shortly after boot |
services/**/*.service.ts | Tenant-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
- Configuration — server options and tenant table
- Project structure
- Quick Start
- Collections
- Routes
- Scripts
- Services