Docs/Getting Started
Scaffold (CLI)
npx alado (3.10.0) creates a project and adds modules, DTOs, auth strategies and access controls to it. What it writes follows the Project Structure, and every generated file compiles, passes ESLint and is formatted by Prettier.
Create a project
In a new folder, with alado installed there first:
mkdir my-api && cd my-api
npm install alado
npx alado init \
--modules=user,session \
--authentications=bearer \
--access-controls=admin
npm run build && npm startOr in a folder init creates:
npx alado init my-api \
--repo=git@github.com:me/my-api.git \
--modules=user,sessioninit [path] works in path, or in the current folder without one. The folder has to be new, empty, or hold only what npm init and npm install alado leave there (package.json, package-lock.json, node_modules, .git); anything else is refused. An existing package.json is completed, not replaced: the installed alado, other dependencies, name, version and scripts of the same name stay (the CLI lists the scripts it kept). A package.json with "type": "module" is refused: the project is compiled to CommonJS.
init writes:
package.json: alado, and the TypeScript, ESLint, Prettier, husky and tsc-alias versions alado itself is built with; scriptsbuild,start,eslint,check-format,format,preparetsconfig.json(experimentalDecorators, the@/*alias forsrc/*),eslint.config.mjs,.prettierrc,.prettierignore,.editorconfig,.gitignore.husky/pre-commit, which formats the staged filessrc/main.ts,src/config/server.options.ts(port fromPORT, Swagger UI at/docs)src/auth/,src/access-control/andsrc/modules/with what the options ask for
Then it runs git init (with origin for --repo) and npm install. When the install fails (offline, a registry error), the project is still written and staged, and init exits with 1.
Add to a project
npx alado create module invoice --id=objectId
npx alado create dto CreateUser user \
--properties='name!,email!,age:integer,role:enum:admin/user,createdAt'
npx alado create auth api-key
npx alado create access-control owner| Command | Writes |
|---|---|
create module <module> |
src/modules/<module>/ with its controller, index.ts and dto/<module>-id.dto.ts. src/modules/index.ts lists the controller of every module and is rewritten each time, so main.ts never changes |
create dto <name> <module> |
src/modules/<module>/dto/<name>.dto.ts, added to dto/index.ts |
create auth <name> |
src/auth/<name>.auth.ts, a RequestAuthentication reading headers.x-api-key for api-key, headers.authorization for any other name |
create access-control <name> |
src/access-control/<name>.access-control.ts, an AccessControlConfig on auth.user |
create commands work in the project of the current folder (or a folder inside it).
The CLI stages what it writes and never commits.
createcommands refuse a work tree with uncommitted changes, so that what is staged afterwards is the command's own work: commit or stash your changes (git stash push --include-untracked), run the command again, review and commit the staged files, thengit stash pop. An existing file is never overwritten; only theindex.tsfiles the CLI writes from a folder listing are.
Options
| Option | Commands | Meaning |
|---|---|---|
--repo=<url> |
init |
origin of the new repository, and repository in package.json; refused inside another repository |
--modules=a,b |
init |
modules to create, as create module does |
--authentications=a,b |
init |
auth strategies, as create auth does |
--access-controls=a,b |
init |
access controls, as create access-control does |
--id=uuid |
init, create module |
type of the :id path parameter: uuid (default), objectId, integer, string |
--properties=... |
create dto |
the DTO's properties (below) |
--no-install |
init |
skip npm install |
--dry-run |
all | list the files the command would write, write nothing |
--help, --version |
usage, and the alado version |
Names are written in kebab-case or camelCase (orderItem and order-item both give src/modules/order-item/ and OrderItemController).
Every option at once:
npx alado init my-api \
--repo=git@github.com:me/my-api.git \
--modules=user,session,order-item \
--authentications=bearer,api-key \
--access-controls=basic,admin \
--id=uuid \
--no-install \
--dry-runWhat is generated
Generated code does nothing until you implement it:
- A module's controller has
GET /<module>,GET /<module>/:id,QUERY /<module>/:id,POST /<module>,PUT /<module>/:id,PATCH /<module>/:idandDELETE /<module>/:id. Each answers501 Not implemented. The:idroutes take the module's id DTO; add a body DTO to@defineRequestof the routes that read one. - An auth strategy's handler returns
undefined, so every request gets its401: return what the request is authenticated as. See Authentication. - An access control's handler returns
false, so every request gets its403: returntrueto allow. See Access Control.
@get('/user/:id', { tags: ['User'], title: 'Get by id' })
@defineResponse({
statusCode: 200,
title: 'Get by id',
headers: { 'Content-Type': 'application/json' },
body: {},
})
@defineRequest({ path: UserIdDto })
async getById(req: Request): Promise<Response<unknown>> {
throw new HttpError(501, 'Not implemented');
}DTO properties
--properties is a comma-separated list of name or name:type, with ! at the end for a required property (email!, age:integer!). Keep the list in single quotes: zsh reads ! as history expansion.
| Type | Validator | Initial value |
|---|---|---|
string |
validate.string() |
'' |
number, integer |
validate.number(), .integer() |
0 |
boolean |
validate.boolean() |
false |
email, uuid, objectId, url |
validate.string().email(), .uuid(), .objectId(), .url() |
an example value |
date |
an ISO 8601 date-time string of a day that exists (2026-11-26T05:46:00.000Z, as toISOString() and MongoDB write it), documented as format: date-time |
new Date().toISOString() |
timestamp |
validate.number().integer().positive() (milliseconds) |
Date.now() |
enum:a/b |
validate.string().enum('a', 'b') |
the first value |
array:<type> |
validate.array().items(...) (array:string, array:enum:a/b) |
[] |
Without a type, the name gives one, and the CLI prints what it chose: email an email, createdAt / birthDate a date, timestamp a timestamp, isActive / hasAccess a boolean, homepageUrl a url, any other name a string. Each property gets one @validateProperty; its validator also gives the OpenAPI schema (see @documentProperty).
npx alado create dto CreateUser user --properties='name!,email!,createdAt'import { documentProperty, validate, validateProperty } from 'alado';
export class CreateUserDto {
@validateProperty({
handler: validate.string().required().build(),
error: { statusCode: 400, message: 'Invalid name' },
})
name: string = '';
@validateProperty({
handler: validate.string().email().required().build(),
error: { statusCode: 400, message: 'Invalid email' },
})
email: string = 'user@example.com';
@validateProperty({
handler: validate.string().regex(isoDate).custom(isDate).build(),
error: { statusCode: 400, message: 'Invalid createdAt' },
})
@documentProperty({ schema: { format: 'date-time' } })
createdAt: string = new Date().toISOString();
}isoDate and isDate are written at the top of the file.