Skip to main content
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

This generates:
Without a domain, the same entity would be at /api/invoices. The domain adds the /billing/ prefix automatically.

API

DomainConfig

PropertyTypeRequiredDescription
entitiesEntityDefinition[]No*Entities in this domain
servicesServiceDefinition[]No*Services in this domain
middlewareNamedMiddlewareDef[]NoDomain-scoped middleware
* At least one of 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}/:
Routes generated:

Domain middleware

Domains can have their own middleware that runs only for routes inside that domain:
Execution order:
  1. Global middleware (from app.middlewares([...]))
  2. Domain middleware (only for routes in this domain)
  3. Entity/service handler
Domain middleware receives the full context from global middleware (e.g., 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 using inject:
The 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 a tenantId field) work seamlessly inside domains. The framework’s automatic tenant filtering applies regardless of domain membership:
See Multi-Tenancy for more on tenant scoping.