CLI
Create a TelamonJS app, generate CRUD modules from Prisma, add admin-kit modules, and check modules against the conventions
@telamonjs/cli ships two binaries and no library code:
| Binary | What it runs |
|---|---|
create-telamonjs-app | telamonjs create with the same arguments; with no arguments, the wizard |
telamonjs | Every command on this page; with no arguments, the wizard |
It requires Node 22 or later.
Create an app
npx -p @telamonjs/cli create-telamonjs-app my-adminOr install the CLI globally and use telamonjs:
npm install -g @telamonjs/cli
telamonjs create my-adminThe single-app template is a Next.js admin wired to @telamonjs/ui: an
AdminShell layout with its menu, NextAuth v5, Prisma with a docker-compose.yml
database, a reference CRUD module (usuarios) whose create, edit and view open in
dialogs, database-backed roles and permissions (below), and pt-BR/en/es
messages. Unless you pass --skip-install, the CLI
installs dependencies and then sets the app up: it copies .env, starts the
database container, runs the migrations and the seed. Then:
cd my-admin
pnpm dev # http://localhost:3001, sign in as admin@example.com / 12345If the automatic setup fails (Docker not running, for example), the CLI prints
the manual steps: docker compose up -d db, cp .env.example .env,
pnpm db:migrate, pnpm db:seed.
Roles and permissions in a new app
New apps ship RBAC from the database, built on
@telamonjs/permissions and
@telamonjs/auth:
| Piece | Where |
|---|---|
Role, Permission, RolePermission, UserRole tables (the package's Prisma fragment); User has roles, active, accessChangedAt, sessionsRevokedAt | prisma/schema.prisma |
The permission catalog (users.read/write, roles.read/write) and loadAccess() | src/rbac.ts |
Catalog sync with diffPermissionCatalog, a built-in admin role holding every permission, the admin user with that role | prisma/seed.ts (idempotent: rerun it after adding a permission) |
Roles and permission codes materialized into the JWT at sign-in; on every renewal sessionState signs out a deactivated or revoked user and recomputes the claims of a stale token | src/auth.ts |
requirePermission('users.write') in every Route Handler | src/lib/auth.ts, src/app/api/** |
PermissionsProvider around the AdminShell, menu items with permission, CrudConfigs with permissions | LayoutProviders.tsx, src/config/menu.ts |
/admin/papeis: role CRUD and a PermissionMatrix tab (built-in roles locked); /admin/usuarios: multi-role assignment, activate/deactivate | src/app/admin/** |
Changing a role's permissions, renaming or deleting it, or changing a user's
roles stamps accessChangedAt on the affected users, so their next request
carries fresh claims without a new sign-in; deactivating a user or changing
their password stamps sessionsRevokedAt and ends their sessions. In the monorepo, src/rbac.ts
moves to packages/shared (@<name>/shared/rbac) and apps/api enforces the
same codes with createPermissionsGuard and @Permissions(...).
Options
telamonjs create [project-name] [options] # alias: telamonjs new| Option | Default | Effect |
|---|---|---|
-p, --provider <provider> | postgresql | Database: postgresql or mysql |
--port <port> | 3001 | Development server port |
--monorepo | asked | Generate a pnpm monorepo instead of a single app (see below) |
--skip-install | Skip dependency installation and the automatic setup | |
--skip-git | Skip git init |
Without --monorepo, create asks whether you want a monorepo when it runs in a
terminal, and creates a single app when it does not (CI, piped stdin).
telamonjs create my-admin --provider mysql --port 3005 --skip-gitThe wizard
telamonjs with no arguments, telamonjs wizard (alias init), or
npx -p @telamonjs/cli create-telamonjs-app with no arguments starts an
interactive setup. It asks for:
- the project name
- the database (PostgreSQL or MySQL)
- the development server port (1024-65535, default 3001)
- monorepo or single app
- whether to install dependencies
- whether to initialize git
It shows a summary, asks for confirmation, then runs create with those answers.
--monorepo
npx -p @telamonjs/cli create-telamonjs-app my-admin --monorepoapps/web/ Next.js + @telamonjs/ui, port <port>
apps/api/ NestJS API, prefix /v1, port <port> + 1000
apps/jobs/ BullMQ worker and scheduler on @telamonjs/queue
packages/shared/ Prisma schema and client, shared by web, api and jobsapps/web starts from the single-app template, with Prisma, src/rbac.ts and
the Route Handlers of usuarios and roles moved out to packages/shared and
apps/api. The
monorepo uses pnpm through corepack and does not run the database setup for you:
cd my-admin
corepack enable pnpm # once per machine
cp .env.example .env # fill NEXTAUTH_SECRET (openssl rand -base64 32)
docker compose up -d # postgres + redis
pnpm db:push
pnpm db:seed
pnpm dev # apps/web
pnpm dev:api # apps/api
pnpm worker # apps/jobsgenerate crud
telamonjs generate crud [name] [options] # alias: telamonjs g crudRun it from the app root. It reads the Prisma schema, maps each model field
to a form field type and a column, and writes a module in the
standard structure. The schema is the
one package.json#prisma.schema names, else prisma/schema.prisma (also
database/, src/prisma/ and a multi-file prisma/schema/ folder); from a
monorepo's apps/web it finds packages/shared/prisma at the workspace root.
When the schema or the model is missing it stops and says where it looked, or
which models exist; --no-prisma-schema generates generic fields instead.
| File | Contents |
|---|---|
src/app/admin/<name>/config.tsx | Zod schema, columns, form sections and the CrudConfig, with create, edit and view dialogs |
src/app/admin/<name>/page.tsx | <ListPage config={…} />, the module's only route |
src/app/admin/<name>/_components/<Model>Detail.tsx | The view dialog body |
src/lib/api/<name>-client.ts | Typed REST client used by the config |
src/app/api/<name>/route.ts, [id]/route.ts | Route Handlers backed by Prisma |
It also adds the module to menu-items.ts, writes the module's messages to
messages/{pt-BR,en,es}.json when the app has i18n, and formats the files with
Prettier when it is available.
| Option | Effect |
|---|---|
[name] | Module name, plural: folder, route and query key |
-m, --model <model> | Prisma model to read (singular) |
-p, --path <path> | Module path (default src/app/admin/<name>) |
--no-prisma-schema | Skip Prisma detection and generate generic fields |
--no-update-menu | Do not add the module to the menu |
-f, --force | Overwrite the module's messages block if it already exists |
Missing arguments are asked interactively, including a pick list of the models found in the schema.
telamonjs generate crud products --model Product
telamonjs g crud # fully interactiveThe output is a starting point. Fill in the loadField stubs for relationships,
review the validation schema, and check that the Route Handlers match your
authorization rules: none of that can be inferred from the schema. Icons are
resolved by name from src/lib/icons.ts.
Monorepo apps
The generated Route Handlers import @/lib/prisma, which only exists in the single-app
template. In a monorepo, the API belongs in apps/api: move the data access there and
point the generated client at it.
Admin kit: add admin
telamonjs add admin <module> [--dry-run] [--cwd <dir>]Adds a ready-made admin module to an app generated by telamonjs create. It
detects the layout (single app, or a monorepo with apps/api and
packages/shared/prisma) and writes the module in the app's own patterns:
Prisma model, API with permission checks, permission codes, menu entry, i18n
messages and an admin page.
| Module | Prisma model | Permissions | Admin page |
|---|---|---|---|
audit | AuditLog: user, impersonator, action, entity type and id, changes (JSON, secrets redacted), IP, user agent, method, path, status, date; indexed by entity, user and date | audit.read | /admin/auditoria: read-only list (when, who, action, entity, record), action filter, view dialog with AuditChangesViewer |
parameters | Parameter: unique key, text value read through type (STRING, NUMBER, BOOLEAN, JSON), description, group, public | parameters.read, parameters.write | /admin/parametros: CRUD in dialogs, the value input follows the type |
invitations | Invitation: email, name, roleIds, tokenHash (sha256 of the link's token, unique), status (PENDING, ACCEPTED, REVOKED; a pending one past expiresAt reads as EXPIRED), expiresAt, acceptedAt, resendCount, invitedById, userId | invitations.read, invitations.write | /admin/convites: list (email, roles, status, expiry, inviter), invite dialog with a roles multiselect, resend and revoke row actions; plus the public /convite/<token> accept page |
What each module writes besides the shared edits below:
| Module | Single app | Monorepo |
|---|---|---|
audit | src/lib/audit.ts (audit(), built on computeDiff and redactPayload), GET /api/audit and /api/audit/[id]; the users and roles Route Handlers call audit() after each create, update, (de)activation, deletion, grant and revoke | apps/api/src/modules/audit (GET /v1/audit, GET /v1/audit/:id), and createAuditInterceptor registered as APP_INTERCEPTOR, so every successful, authenticated mutation is recorded |
parameters | src/lib/parameters.ts (getParameter(key, fallback)), Route Handlers under /api/parameters | apps/api/src/modules/parameters (ParametersService.get(key, fallback), exported by its module), wired into AppModule |
invitations | src/lib/invitations.ts, src/lib/mail.ts (the mail port: sendMail({ to, subject, html, text })), Route Handlers under /api/invitations | apps/api/src/modules/invitations wired into AppModule, and apps/api/src/modules/mail (the mail port: the MAIL_SENDER token, a MailSender interface and ConsoleMailSender) |
The audit list takes the filters entityType, entityId, userId, action,
from and to (ISO dates), plus search. GET /parameters/public?keys=a,b
needs no session and answers { key: value } for the requested parameters marked
public, typed; private and unknown keys are absent.
Invitations: GET /invitations, POST /invitations, POST /invitations/:id/resend
(a new link, the previous one stops working, a new 7-day expiry) and
PUT /invitations/:id/revoke check the permissions; GET /invitations/by-token/:token
and POST /invitations/accept need no session. The link carries a random 32-byte
token (generateApiKey from @telamonjs/auth) and the row keeps only its sha256
(hashApiKey). Inviting an email that already has a user or a pending invitation is
a 409. Accepting creates the user (active, with the invited roles that still exist)
and marks the invitation accepted in one transaction; an unknown, used, revoked or
expired token gets the same 410. The accept page then signs in with the new
credentials. Mail goes through the port above, which only logs to the console:
replace it with your provider. The link is NEXTAUTH_URL/convite/<token>, never
the request's host, and the run notes it in .env.example.
Shared edits, all idempotent:
schema.prismagets a block between// telamonjs:admin:<module>markers; with a multi-file schema folder (prisma/schema/), the model goes in its own<module>.prismafile.- The permission codes go into
PERMISSIONSinsrc/rbac.ts(packages/shared/src/rbac.tsin the monorepo). - A menu entry with its
permissionjoins the Administration group ofsrc/config/menu.ts. - The module's keys are merged into
messages/{pt-BR,en,es}.json; keys the app already has are never overwritten. @telamonjs/datais added to the dependencies when missing.
A second run changes nothing, and a module file that already exists is kept as
it is. --dry-run lists the files it would create or modify and writes nothing.
A code patch whose anchor is gone (a Route Handler you changed) is skipped with a
warning naming what to add by hand.
The command never touches the database. Afterwards:
pnpm install
pnpm db:migrate --name add-audit # monorepo: or pnpm db:push
pnpm db:seed # syncs the catalog; the admin role gets the new permissionsApps not generated from the templates
add admin refuses an app without src/rbac.ts and a Role model: it only edits code it
knows. In an existing app, adopt the runtime pieces instead: createAuditInterceptor and
@SkipAudit from @telamonjs/data/nest, computeDiff and redactPayload from
@telamonjs/data, AuditChangesViewer and PermissionMatrix from @telamonjs/ui, and
diffPermissionCatalog from @telamonjs/permissions.
lint
telamonjs lint [dir] [--json]Checks admin modules against the list, dialog and hub conventions. dir defaults
to src/app/admin when it exists, otherwise the current directory. Generated apps
have it as a script: pnpm lint:telamonjs.
Rules on CrudConfig run on every config.tsx; page rules run on every other
.tsx. A value the linter cannot resolve statically is never reported. The exit
code is 1 when there is at least one error, 0 otherwise, and 2 when the directory
does not exist. --json prints the report as JSON. Messages are printed in
Portuguese.
| Rule | Severity | Checks |
|---|---|---|
list-infinite | error | list.infiniteScroll: false: lists use infinite scroll, the default |
list-title-empty | warning | list.title / list.description should be '': the shell breadcrumb names the page |
list-pagesize | warning | list.defaultPageSize missing or below 50 (use 100 with infinite scroll) |
actions-icon-tooltip | error | actionsConfig.standard.view/edit/delete needs { icon, tooltip }, and delete also a confirmDialog |
view-header | error / warning | dialogs.view without headerConfig or renderHeader (error); a headerConfig without icon or title (warning) |
view-content | error | dialogs.view without renderContent or portal |
view-tabs | error | The view dialog body imports raw Tabs/TabsList/TabsTrigger/TabsContent instead of ContentTabs |
dialog-height | warning | A view dialog body with ContentTabs and no fixed height (h-[min(600px,60vh)] overflow-y-auto) |
portal-size | warning | A view dialog body with more than 5 tabs: use dialogs.view.portal |
form-span | error | A field span other than '1', '2', '3', '12' or 'full' |
no-fetch-in-config | error | fetch() in config.tsx: only src/lib/api/<module>-client.ts calls fetch |
no-crud-pages | error | adicionar/page.tsx, [id]/page.tsx or [id]/editar/page.tsx next to a config.tsx: CRUD happens in the list's dialogs |
icons-from-registry | error | config.tsx imports from lucide-react instead of using getIcon('Name') from @/lib/icons |
no-raw-link | error | A raw <a> or next/link <Link> for navigation instead of <Button asChild><Link /></Button> (external target='_blank', downloads, mailto: and tel: are allowed) |
button-icon-size | warning | An icon inside a Button whose className lacks h-4 w-4 or size-4 |
i18n-literal-in-config | error | A pt-BR literal in title, label, header, placeholder or description in config.tsx, in an app with i18n: use msg('<key>') |
hub-tabs | warning | A page with more than 5 tabs in useTabUrlSync: use AdminPortal |
i18n-untranslated | warning | A key in messages/en.json or es.json whose value is identical to pt-BR.json |
To silence a deliberate exception, add a comment to the flagged file:
// telamonjs-lint-disable-file no-crud-pagesList several rules separated by commas, or name none to disable every rule in that file.
link / unlink
telamonjs link [--ui <path>] [--package <path>]
telamonjs unlink [--package <path>]Switch an app between the published @telamonjs/ui and a local TelamonJS
checkout, following the link recipe:
linksets@telamonjs/uito an injectedfile:dependency on the checkout'spackages/ui(dependenciesMeta["@telamonjs/ui"].injected: true) and addspnpm.overrides["@telamonjs/logger"]as alink:to itspackages/logger. The override goes in the workspace root'spackage.json: the nearest directory with apnpm-workspace.yaml, or the app itself.unlinkrestores the range committed atHEAD, or^plus the latest published version whenHEADhas none, never the checkout's own version, which may not be on npm yet. It removes the override and thedependenciesMetaentry.
| Option | Default | Effect |
|---|---|---|
--ui <path> | $TELAMONJS_UI, else ../telamonjs/packages/ui from the workspace root | The checkout's packages/ui; packages/logger must sit next to it |
--package <path> | apps/web/package.json when it exists, else package.json | The package.json that depends on @telamonjs/ui |
Neither command runs pnpm install: run it afterwards. A missing checkout, or a
package.json without @telamonjs/ui, exits 1 without writing anything.
In a monorepo generated with --monorepo, the root scripts pnpm telamonjs:link
and pnpm telamonjs:unlink run the command and then pnpm install. Its husky
hooks keep commits on the published range: pre-commit runs telamonjs unlink
and updates the lockfile (a failed update aborts the commit), and post-commit
runs telamonjs link again when node_modules still holds the checkout. For a
checkout outside the default location, export TELAMONJS_UI so the hook relinks
the same path.
db
telamonjs db dump [name] # database/dumps/<name>_<timestamp>.sql.gz
telamonjs db restore # pick a dump from a list, confirm, restoreBoth read DATABASE_URL from .env in the current directory and use pg_dump
and psql, so they need the PostgreSQL client tools on the PATH and work with
PostgreSQL only. Without a name, the dump is dump_<timestamp>.sql.gz.
analyze
telamonjs analyze [--verbose] [--json]Reads package.json in the current directory and reports the TelamonJS packages
installed, the database provider, NextAuth, Docker, and the recommended scripts
that are missing (dev, build, db:migrate, db:seed, and the db:dump
scripts for PostgreSQL), with a snippet to add them.
stats
telamonjs stats [--verbose] [--json] [-p, --path <path>]Git statistics for a repository (the current directory by default): lines added and removed, commits, authors, activity by time of day, and lines per commit.
Related
- Installation: adding
@telamonjs/uito an existing app - Quick Start: from
createto a generated module - Module structure: the files
generate crudwrites