Changes for CLAUDE.md: 110 added lines, 102 removed lines.
Original line number
Diff line number
Diff line
@@ -2,144 +2,152 @@
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Project Status
## What this is
This repository is in the **pre-implementation phase**. Currently only design/requirements documents and the OpenAPI contract exist — no source code has been written yet. All build commands, directory structure, and module descriptions below describe the intended implementation.
Chronos UI — a React 18 + TypeScript single-page app for the ETSI OSL Chronos
resource-reservation service. The application is **implemented**: all epics from
the implementation plan are built (pools, memberships, reservations, availability,
-`chronos-ui-implementation-plan-v0.2.md` — Epics/tasks with dependency ordering.
-`docs/` — One dated markdown file per completed task (`yyyymmdd_hhmm_title.md`), indexed by `docs/index.md`. Add a new doc + index entry when completing a unit of work.
app/ # One file per aggregate (pools.ts, reservations.ts, …) = TanStack Query hooks. queryKeys.ts is the single key registry. (mutations/ and queries/ dirs exist but are empty.)
adapters/
api/ # ⭐ CODEC BOUNDARY — all wire-shape mapping lives here
generated/ # openapi-typescript output (committed; regenerate with gen:types)
config.ts # validateConfig() reads import.meta.env; throws on missing required vars
```
## The Codec Boundary (Requirement 16)
### Conventions
-**Hooks**: each `app/<aggregate>.ts` exports `useX()` queries and `useCreateX/useUpdateX/...` mutations. They call `useGateways()`, read/write via `queryKeys`, and invalidate on success. Follow the existing pattern in `app/pools.ts`.
-**Gateways**: a `createXGateway(transport, zone)` factory returning an object that implements the matching `XGateway` port from `domain/ports`. Wire shapes are decoded/encoded here via `mappers/`.
-**Query keys**: add new keys to `app/queryKeys.ts`; never inline raw arrays.
-**New page**: create `features/<area>/XPage.tsx`, export from the feature `index.ts`, then add a `<Route>` wrapped in `<RoleGuard capability="...">` in `shell/AppRoutes.tsx` and a nav entry in `shell/Shell.tsx`.
This is the architectural load-bearing wall. All wire-shape quirks are resolved in `adapters/api/mappers/` — views and hooks only ever see clean domain types.
## The codec boundary (the load-bearing wall)
Key mappings (implement in Epic 4):
All wire-shape quirks resolve in `adapters/api/mappers/`. Key mappings:
The `FeasibilityResult` discriminated union (FEASIBLE / FEASIBLE\_WITH\_ALTERNATIVES / NOT\_FEASIBLE / CONFLICT) is the central domain type — the `OutcomePanel` view switches on it; HTTP status codes never reach the UI layer.
is the central domain union; `ui/OutcomePanel` switches on it.
## Auth & Security
## Auth & roles
- Keycloak PKCE authorization-code flow via `keycloak-js`
- Tokens stored in memory only (never `localStorage`) — Req 1.6
- Single 401 refresh-and-retry in `transport.ts`; re-auth on second 401 — ADR-3
- Role derivation from JWT claims; `RoleGuard` enforces per-feature access
- Keycloak is initialized **once** in `main.tsx` before React renders (avoids StrictMode double-`init` consuming the PKCE code). The adapter wraps that instance.
- PKCE auth-code flow; tokens in memory only (never `localStorage`/`sessionStorage`).
- Single 401 refresh-and-retry in `transport.ts`.
- Roles come from JWT: `chronos.admin`, `chronos.auditor`, `chronos.requester`.
-`features/shell/capabilities.ts#deriveCapabilities()` maps roles → boolean capabilities; `RoleGuard` and the nav use them. Add a new gated feature by adding a capability there.
## Environment Variables (Epic 1.4)
## Environment variables (validated in `config.ts`)
-**`npm run build` (`tsc -b && vite build`) currently fails** on pre-existing MUI v9 theme typing errors (`colorSchemes`/`colorSchemeSelector`/`theme.vars` in `src/ui/theme.ts` + theme/token tests) — unrelated to most changes. `vite build` alone succeeds, so the Docker image runs `npx vite build` directly. `npm run typecheck` is a **no-op** (root `tsconfig.json` has `files: []`); the real type gate is `tsc -b`. Fix the theme types to unbreak `npm run build`.
## Open Questions (resolve in Epic 19)
## Testing
-**OQ-UI-5**: `conflictFlags` delimiter — provisional: whole string as one token
-**OQ-UI-7**: Tenant timezone source — provisional: `VITE_TENANT_TIMEZONE` env var
-**OQ-UI-8**: `fieldErrors` array element shape — untyped in v1.1 contract
-**OQ-UI-9**: Extract-override wire format — query param vs request body
-**OQ-UI-3**: Statistics fields missing from v1.1 schema — dashboard omits, does not fabricate
- MSW intercepts all API calls (`src/test/server.ts`); no real backend needed for unit/component tests. Vitest config inlines `@mui` deps (MUI v9 `.mjs` subpath imports break native ESM resolution) — keep that `server.deps.inline` setting.
- Codec mappers have the heaviest unit coverage (round-trips, absent-field defaults, unknown enum tokens).
- E2E journeys live in `e2e/journeys.spec.ts` (Playwright, Chromium).
## Implementation Order
## Open questions (provisional decisions, see design doc §Open Questions)
Follow the epic dependency order in `chronos-ui-implementation-plan-v0.1.md`. The codec boundary (Epic 4) must be completed before any feature epics (7–17) because it establishes the mappers that all features depend on. Epic 2 (API type generation) must precede Epic 4.
-**OQ-UI-5**: `conflictFlags` delimiter → treat whole string as one token.
@@ -560,7 +560,7 @@ No optimistic updates; reflect server result incl `cancelPending`/`inconsistent`
**Rationale:** matches the operator's model and keeps statistics restricted per R17.3/R2.3 — the v1.1 relaxation is reverted, so no requirements change is needed.
**Implications:** requester-only users get the full UI minus the statistics view; the `useStatistics` query is not enabled for them and the route is guarded.
### ADR-10: MUI v6 theming via CSS variables, dark mode, neutral AA palette (new)
### ADR-10: MUI v9 theming via CSS variables, dark mode, neutral AA palette (new)
**Decision:**`createTheme({ cssVariables: { cssVarPrefix: 'chronos' }, colorSchemes: { light: true, dark: true } })`; two-tier primitive→semantic tokens with TS module augmentation; neutral WCAG-AA default palette; status never color-only; Emotion runtime (not Pigment CSS); theme factory lives in the `ui` module.
**Rationale:** CSS variables give token visibility, plain-CSS reuse, and flash-free dark mode; dark mode is in scope; a neutral AA palette is brand-agnostic and accessible by default and easy to re-skin via primitives. Pigment CSS is alpha and brings no RSC benefit to a Vite SPA.
**Implications:** a user-facing dark/light toggle in the shell; components consume `theme.vars`/semantic tokens only; contrast is a token-level test target.