Patterns
The architectural patterns behind a TelamonJS app - CRUD modules, forms, dialogs, detail pages and the app shell
How TelamonJS apps are built. Read the relevant pattern before changing a CRUD module, a form, a dialog, a detail page or a dashboard.
Architecture
Data flows Client → REST API in one hop (cookie auth), through React Query.
Critical Rules
Dynamic Zustand selectors inside custom hooks loop forever
A dynamic selector inside a custom hook causes an infinite loop (getSnapshot should be cached). Subscribe to the store and select locally. See
Zustand Selector Pattern.
// ✅ CORRECT
const formState = useFormStore()
const data = formState.forms[formId]
// ❌ WRONG (inside a custom hook)
const data = useFormStore(state => state.forms[formId])config.tsxstarts with'use client'.query.queryFnresolvesPaginatedResponse<T>, and everymutationFnresolves{ success, data? }— adapt inside themutationFn, not in the API client.- There is no
'select'field type: use'relationship'withloadField.
CRUD Module
| Pattern | Use it for |
|---|---|
| Admin Module Structure | Where each file of a module lives, and config.tsx ('use client') with the module's CrudConfig |
| ListPage | <ListPage config={...} />: infinite scroll (default), toolbar, filters, bulk actions, dialogs |
| Data Layer (React Query) | API client, queryFn → PaginatedResponse<T>, mutationFn → { success, data? }, invalidation |
| Form | AdminForm/CreateForm/EditForm/ZustandForm: sections, grid, validation |
| CRUD Field | type: 'crud' for 1:N / N:M lists inside a form (create(data, { id: parentId })) |
| Nested Data | Nested records in forms with dot notation (person.email) |
Dialogs, Detail Pages and Shell
| Pattern | Use it for |
|---|---|
| Dialogs | View, edit and create dialogs, rich headers, sizes |
| Detail Page | A dedicated detail route with DetailLayout, DetailCard, DetailField... |
| Standalone Form Pages | Create/edit routes with CreatePage/EditPage, when a dialog is not enough (dialogs are the default) |
| Dashboard | DashboardShell, ShellPage + AdminHeader + AdminTabs, stat cards |
| Provider Setup | AppProviders, the app's QueryClient, AdminShell, icon resolver |
Cross-Cutting
| Pattern | Use it for |
|---|---|
| i18n | UI text: msg() in configs, useTranslations()/getTranslations(), useFormat() |
| Accessibility | data-testid conventions, ARIA attributes, vitest-axe tests |
| Zustand Selector | Reading stores without render loops |
| Troubleshooting | "No QueryClient set", linked packages, getSnapshot should be cached |
A Complete CRUD Module
app/admin/users/
├── config.tsx 'use client' — CrudConfig (module config + data layer)
├── page.tsx <ListPage config={config} />
└── [id]/
└── page.tsx Detail Page (optional — the view dialog covers most cases)
lib/api/
└── users-client.ts list / get / create / update / delete against the API'use client'
import { type CrudConfig } from '@telamonjs/ui'
import { usersApi } from '@/lib/api/users-client'
export const config: CrudConfig<User, UserFormData> = {
module: { name: 'users', title: 'Users', description: 'Manage system users', route: '/admin/users' },
list: { title: 'Users', description: 'Registered users', columns, searchPlaceholder: 'Search...' },
form: { sections, validation: validationSchema },
// queryFn resolves PaginatedResponse<User> ({ data, total, page, pageSize, totalPages })
query: { queryKey: ['users'], queryFn: usersApi.list },
mutations: {
// mutationFn resolves { success, data? } — shape it here, not in the API client
create: {
mutationFn: async data => ({ success: true, data: await usersApi.create(data) }),
invalidates: [['users']],
},
update: {
mutationFn: async ({ id, data }) => ({ success: true, data: await usersApi.update(id, data) }),
invalidates: [['users']],
},
delete: {
mutationFn: async ({ id }) => {
await usersApi.delete(id)
return { success: true }
},
invalidates: [['users']],
},
},
}import { ListPage } from '@telamonjs/ui'
import { config } from './config'
export default function UsersPage() {
return <ListPage config={config} />
}Anti-Patterns
- ❌ A dynamic Zustand selector inside a custom hook (see above)
- ❌
type: 'select'— use'relationship'withloadField - ❌ Server Actions,
actions.tsorunstable_cacheas the data layer - ❌
className: 'w-full'on a form field — the grid ignores it; usespan - ❌
any— useunknownor the real type - ❌
redirect()insidetry/catch— theNEXT_REDIRECTerror is caught; redirect outside the block - ❌ Looking for React Query hooks in
@telamonjs/ui— they are not re-exported; import@tanstack/react-querydirectly
Next Steps
- Admin Module Structure - What goes in
config.tsx - ListPage - Everything
ListPagedoes with the config - Data Layer (React Query) - API client, mutations and invalidation
- Form Pattern - Sections, grid and validation
- Provider Setup - App shell + providers