Skip to content

wcz-layout

general

122 linesSource

Use ALWAYS, before any other skill here, for every code change. Sets the approved stack, coding, UI and translation conventions, tests and the validation command, where each new file goes, and the skills to load, in order, to build or remove a feature.

wcz-layout skills sit on top of the TanStack skills they name: load both. Where they disagree, the wcz-layout skill wins. Permissions, scopes, the signed-in user and downstream tokens: references/auth.md.

Stack

  • TanStack owns each concern: Start (app, server functions), Router, DB (client data), Form, Table (through LayoutTable), Query (fetches outside collections), Virtual (long lists), Hotkeys, Pacer (debounce, throttle, queue), AI, Charts. MUI for components and icons. Vite+ (vp) runs, formats, lints and tests.
  • Anything else: install a maintained, typed library rather than hand-rolling logic, unless it takes a few lines.

Code

  • Strict ES2023 TypeScript: no any, keep local inference, type public boundaries.
  • Double quotes, semicolons, ~/ for imports from src/.
  • The React Compiler memoizes: no useMemo, useCallback or memo.
  • Comment only intent the code cannot show.
  • Done means the narrowest relevant test passes and vp check --fix (format, lint, type-check) is clean.

UI

  • Every screen works in light and dark (theme.applyStyles("dark", …); the theme sets colorSchemeSelector: "data-mui-color-scheme") and on desktop and mobile (breakpoints).
  • Dates: dayjs(value).format("L LT"), or "L" for a date alone.
  • Loading states are skeletons of the final layout.
  • A component fetching its own useQuery waits until visible: const { ref, inView } = useInView({ triggerOnce: true }) (wcz-layout/hooks), enabled: inView, ref on the skeleton wrapper. Route-preloaded data stays eager. Infinite scroll: useInView() on a sentinel after the last item.
  • Content that fills the rest of the viewport (table, map, chart) goes in Fullscreen (wcz-layout/components; Box props, scrolls inside).
  • Success shows no message: the changed item animates where it lives (created enters, deleted collapses out, edited briefly tints). When it is out of sight (you navigate away), the trigger button morphs into a check for ~400 ms. Failures go to alert() (dialogs).
  • Ids: uuidv7() from wcz-layout/utils, generated on the client. OS: Platform.isAndroid | isIOS | isWindows | isMacOS from wcz-layout/utils.

Translations

  • Every user-facing string goes through t: useTranslation() from wcz-layout/hooks in components, t from wcz-layout/utils. t() translates when called, so never at module scope (Zod messages: see db-schema).
  • Add each key to src/lib/locales/*.json. Feature keys go under the feature's namespace ("Feature": { "Name": "Name" }), shared ones at the root. Counts use plural keys: _one, _other, and _few in Czech.

Building a feature

Ask for the permission key when the task names none; a new key goes in src/lib/auth/permissions.ts. Then, loading each skill on the way:

  1. Table src/server/db/schemas/<entity>.ts (+ relations.ts), Zod schema and type src/lib/schemas/<entity>.ts: db-schema
  2. Server functions src/server/actions/<entity>.ts: server-functions
  3. Collection src/db/collections/<entity>.ts, live queries src/db/queries/<entity>.ts: client-db
  4. Pages src/routes/<entities>/ (index.tsx list, $id.tsx detail, create.tsx, edit.$id.tsx, -components/Form.tsx, -components/<Entity>Skeleton.tsx), the navigation item and the locale keys: routing, table, forms, dialogs
  5. Tests, below

File layout

Feature UI stays next to its route; root UI folders are for cross-feature reuse. Schema, server and client-data layers use the paths below even for one feature.

plaintext
src/
├── components/                  # shared by several features
├── hooks/                       # shared hooks; useTheme.ts (MUI theme)
├── db/
│   ├── collections/<entity>.ts  # collection descriptor + use<Entity>Collection
│   └── queries/<entity>.ts      # live query options
├── lib/                         # isomorphic: client and server
│   ├── auth/                    # permissions.ts, scopes.ts
│   ├── locales/                 # en.json, cs.json
│   └── schemas/<entity>.ts      # Zod schema + type
├── routes/
│   ├── __root.tsx               # shell, navigation, root beforeLoad
│   ├── index.tsx, login.tsx, health.ts, auth/   # from the template, keep
│   ├── api/<entities>/          # REST routes, only for a requested public API
│   └── <entities>/              # feature pages; -components/, -hooks/
├── server/                      # server-only
│   ├── actions/<entity>.ts      # server functions
│   ├── db/                      # index.ts, schemas/<entity>.ts, schemas/relations.ts, migrations/
│   └── middleware/databaseMiddleware.ts
├── env.ts                       # clientEnv, serverEnv (createEnv)
├── router.tsx                   # QueryClient, DbClient, router defaults
└── types/                       # i18next.d.ts, wcz-layout.d.ts

Tests

Test what guards real behavior (schema rules, form behavior, queries, constraints, a fixed bug), not coverage. vp test runs tests/unit and tests/integration, paths mirroring src/; npm run test:e2e runs tests/e2e.

  • No globals: import from vite-plus/test. Component tests start with // @vitest-environment jsdom and call afterEach(cleanup).
  • Without an initialized i18n fixture, assert Zod issue path and code, not messages.
  • Collection tests mock the select server function, not TanStack DB. Use a fresh DbClient per case; for one query, await preloadLiveQuery(q) and read dehydrate().liveQueries?.[0]?.snapshot?.rows.map(({ value }) => value). Clean up with await dbClient.cleanup() and queryClient.clear().
  • Database tests need an intended test DATABASE_URL, always roll back and pool.end(). Server functions themselves need a Start request context; pure DB tests do not prove RPC validation, auth or HTTP behavior. Do not assume CI skips these tests.
  • e2e uses auth.setup.ts and gotoHydrated(page, url) before interacting. Match the browser locale to translated selectors. The fake session tests app access, not OAuth/delegated APIs. Check create/edit/delete after reload, missing rows and rejected saves, not only type-checks.