domain() groups related entities and services under a shared namespace. Entities and services inside a domain get route-prefixed with the domain name — no manual path configuration needed.
Quick start
/api/invoices. The domain adds the /billing/ prefix automatically.
API
DomainConfig
| Property | Type | Required | Description |
|---|---|---|---|
entities | EntityDefinition[] | No* | Entities in this domain |
services | ServiceDefinition[] | No* | Services in this domain |
middleware | NamedMiddlewareDef[] | No | Domain-scoped middleware |
entities or services must be provided.
Name rules
Domain names must match/^[a-z][a-z0-9-]*$/:
- Start with a lowercase letter
- Only lowercase letters, digits, and hyphens
- No uppercase, no slashes, no underscores
Route prefixing
All entities and services inside a domain are prefixed with/api/{domainName}/:
Domain middleware
Domains can have their own middleware that runs only for routes inside that domain:- Global middleware (from
app.middlewares([...])) - Domain middleware (only for routes in this domain)
- Entity/service handler
userId, tenantId). Each domain’s middleware is isolated — it doesn’t affect other domains.
Mixing domains with top-level resources
You can use domains alongside top-level entities and services:Cross-domain injection
Entities in one domain can reference entities from another domain usinginject:
inject system resolves dependencies across domains — the entity doesn’t need to know which domain its dependency lives in.
Collision detection
The framework validates names at startup and throws clear errors for conflicts:Duplicate domain names
Same entity in multiple domains
Domain name conflicts with top-level resource
Tenant scoping
Tenant-scoped entities (with atenantId field) work seamlessly inside domains. The framework’s automatic tenant filtering applies regardless of domain membership: