Skip to Content
TelamonJS

Quick Start

Create an app with the CLI, generate a CRUD module from a Prisma model, and read its config

From an empty folder to a working Products module: list, search, create, edit, view and delete, all in one route. You need Node.js 22+, pnpm and Docker (for the database).

Create the app

npx -p @telamonjs/cli create-telamonjs-app my-admin
cd my-admin
pnpm dev

The CLI installs the dependencies, starts the database with Docker Compose, migrates and seeds it (flags and the monorepo option are on Installation). Open http://localhost:3001 and sign in as admin@example.com / 12345.

The app ships one complete module, src/app/admin/usuarios/. It is the reference for everything below, and AGENTS.md at the app root explains the conventions to coding agents.

Add a Prisma model

prisma/schema.prisma
model Product {
  id        String   @id @default(cuid())
  name      String
  sku       String   @unique
  price     Decimal
  active    Boolean  @default(true)
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  @@map("products")
}
pnpm db:migrate

Generate the module

pnpm telamonjs generate crud products --model Product

The generator reads the model, maps each column to a field type, asks for the module path (Enter accepts src/app/admin/products) and writes:

src/app/admin/products/
├── config.tsx                    # CrudConfig — the whole module
├── page.tsx                      # <ListPage config={productsConfig} />
└── _components/ProductDetail.tsx # body of the view dialog
src/lib/api/products-client.ts    # the only file that calls fetch()
src/app/api/products/route.ts     # GET list, POST create (Prisma)
src/app/api/products/[id]/route.ts# GET, PATCH, DELETE (Prisma)

It also adds a menu entry to src/config/menu.ts and the module's keys to messages/{pt-BR,en,es}.json. Reload the app: Products is in the sidebar.

Read the config

Data moves in one direction: Route Handler (Prisma) → products-client.ts (fetch) → config.tsx. The config never touches Prisma or fetch(); it wires the client into one CrudConfig object, and page.tsx renders it:

src/app/admin/products/page.tsx
'use client'

import { ListPage } from '@telamonjs/ui'
import { productsConfig } from './config'

export default function ProductsPage() {
  return <ListPage config={productsConfig} />
}

config.tsx starts with 'use client' (its queries and mutations run through React Query hooks). Its key parts:

query loads the list. queryFn must resolve a PaginatedResponse<T> (data, page, total, totalPages), not a bare array: the list is an infinite, virtualized scroll that pages through it.

query: { queryKey: ['products'], queryFn: productsApi.list, staleTime: 30_000 },

mutations write. Each mutationFn resolves { success, data? }, so the config adapts the client's raw entity; invalidates refreshes the list. getForEdit and getForView fetch one record when a dialog opens — getForEdit maps it to the form's shape:

mutations: {
  create: {
    mutationFn: async (data) => ({ success: true, data: await productsApi.create(data) }),
    invalidates: [['products']],
  },
  // update and delete follow the same shape
  getForEdit: async (id) => {
    const item = await productsApi.getById(id)
    return { name: item.name, sku: item.sku, price: item.price, active: item.active }
  },
  getForView: productsApi.getById,
},

dialogs are where create, edit and view happen. Each one syncs to a URL parameter (?view=<id>, ?edit=<id>, ?create=1), so it can be linked to and Back closes it. The edit and create dialogs render form.sections; the view dialog renders the detail component:

dialogs: {
  view: {
    urlParam: 'view',
    title: msg('products.dialogs.view.title'),
    headerConfig,
    renderContent: (item) => <ProductDetail item={item} />,
  },
  edit: { urlParam: 'edit', title: msg('products.dialogs.edit.title'), headerConfig },
  create: { urlParam: 'create', title: msg('products.dialogs.create.title'), headerConfig },
},

actionsConfig adds the row buttons (view, edit, delete with a confirmation dialog). form holds the field sections and the Zod schema shared by the create and edit dialogs. Text slots use msg('<key>') so they follow the active locale.

CrudConfig has the full annotated example and every key.

Check it

pnpm lint:telamonjs   # telamonjs lint src/app/admin
pnpm type-check

telamonjs lint checks modules against the list, dialog and hub conventions and exits 1 on any error. A fresh module has no errors; it warns (i18n-untranslated) about en.json and es.json keys that still hold the pt-BR text, until you translate them.

No create, edit or detail routes

A module is one route. Don't add new/, [id]/ or [id]/edit/ pages next to config.tsx: create, edit and view are the dialogs above, and delete is a row action. telamonjs lint fails on a [id]/page.tsx next to a config.tsx (no-crud-pages). For a form that genuinely needs its own page (a settings screen, a long wizard), see Standalone form pages.

Next steps

  • CrudConfig — the canonical example, key by key
  • Dialogs — rich headers, detail tabs, the portal view for large records
  • Form Pattern and Field Types — sections, validation, relationship fields
  • i18n — msg(), <Msg> and the message files

On this page