Getting Started
Project structure
Recommended layout for a dnax backend repository.
Below is a recommended repository layout. This guide uses v1/ as the tenant folder (id: 'v1', dir: 'v1'). That directory is your tenant.dir: dnax loads collection models, routes, scripts, and services from it. Subfolders like endpoints/ or plugins/ are for your own code unless you wire them from index.ts or config/app.ts.
.
├── .cache/ # System caches and temporary backup data
├── config/
│ ├── app.ts # Server configuration (boot, tenants, options)
│ └── ...
├── v1/ # Tenant root for API version 1 (`id: 'v1'`, `dir: 'v1'`)
│ ├── collections/ # Collection models (`*.model.ts`) — MongoDB / dnax
│ ├── endpoints/ # Custom HTTP endpoints (your code)
│ ├── plugins/ # Standalone plugin-style modules (your code)
│ ├── middlewares/ # HTTP / app middlewares (your code)
│ ├── routes/ # dnax routes (`*.route.ts`) — needs `routes.prefix`
│ ├── scripts/ # dnax boot scripts (`*.run.ts`)
│ ├── services/ # dnax services (`*.service.ts`)
│ ├── sockets/ # WebSocket / real-time handlers (your code)
│ └── tasks/ # Cron or scheduled tasks (your code)
├── uploads/ # Public & private file storage
├── data/ # Shared backups or durable local data
├── index.ts # Process entrypoint (calls `app.boot` or loads `config/app.ts`)
├── package.json
└── tsconfig.json
What dnax loads automatically
Under tenant.dir (here v1/), the framework only scans:
| Path | Pattern | Notes |
|---|---|---|
collections/ | **/*.model.ts | Defines collections and API rules |
routes/ | **/*.route.ts | Registered only if the tenant has routes.prefix |
scripts/ | **/*.run.ts | Runs shortly after the server is ready |
services/ | **/*.service.ts | Exposed under POST /services/:tenant_id/:service/:action |
Folders such as endpoints/, plugins/, middlewares/, sockets/, and tasks/ are not read by dnax today—they are conventional places to organize code you import from your entrypoint, routes, or hooks.
If you prefer another name than scripts/ for boot logic, keep a scripts/ tree (or symlink) for *.run.ts files so discovery keeps working.
Root files
index.ts— Start the process; typicallyimport { app } from '@dnax/core'andawait app.boot(...)or import fromconfig/app.ts.config/app.ts— Central place fordefine.Server/ boot options, tenant list, and shared constants..cache/— Optional; local caches (build, temp exports, etc.).uploads//data/— Static files, user uploads, dumps; keep them out of version control as needed.
See also
- Tenant —
dir,id, database - Quick Start — minimal tree to run the API
- Routes —
*.route.tsand prefix - Scripts —
*.run.ts - Services —
*.service.ts