Skip to Content
TelamonJS

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.tsx starts with 'use client'.
  • query.queryFn resolves PaginatedResponse<T>, and every mutationFn resolves { success, data? } — adapt inside the mutationFn, not in the API client.
  • There is no 'select' field type: use 'relationship' with loadField.

CRUD Module

PatternUse it for
Admin Module StructureWhere 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
FormAdminForm/CreateForm/EditForm/ZustandForm: sections, grid, validation
CRUD Fieldtype: 'crud' for 1:N / N:M lists inside a form (create(data, { id: parentId }))
Nested DataNested records in forms with dot notation (person.email)

Dialogs, Detail Pages and Shell

PatternUse it for
DialogsView, edit and create dialogs, rich headers, sizes
Detail PageA dedicated detail route with DetailLayout, DetailCard, DetailField...
Standalone Form PagesCreate/edit routes with CreatePage/EditPage, when a dialog is not enough (dialogs are the default)
DashboardDashboardShell, ShellPage + AdminHeader + AdminTabs, stat cards
Provider SetupAppProviders, the app's QueryClient, AdminShell, icon resolver

Cross-Cutting

PatternUse it for
i18nUI text: msg() in configs, useTranslations()/getTranslations(), useFormat()
Accessibilitydata-testid conventions, ARIA attributes, vitest-axe tests
Zustand SelectorReading 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
config.tsx
'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']],
    },
  },
}
page.tsx
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' with loadField
  • ❌ Server Actions, actions.ts or unstable_cache as the data layer
  • ❌ className: 'w-full' on a form field — the grid ignores it; use span
  • ❌ any — use unknown or the real type
  • ❌ redirect() inside try/catch — the NEXT_REDIRECT error is caught; redirect outside the block
  • ❌ Looking for React Query hooks in @telamonjs/ui — they are not re-exported; import @tanstack/react-query directly

Next Steps

  1. Admin Module Structure - What goes in config.tsx
  2. ListPage - Everything ListPage does with the config
  3. Data Layer (React Query) - API client, mutations and invalidation
  4. Form Pattern - Sections, grid and validation
  5. Provider Setup - App shell + providers

On this page