From 88ad6ff276074e4076a54c94928bb4e69b387948 Mon Sep 17 00:00:00 2001 From: lila Date: Sat, 21 Mar 2026 12:10:59 +0100 Subject: [PATCH] updating documentaion --- documentation/CLAUDE.md | 18 +++++++++ documentation/decisions.md | 82 ++++++++++++++++++++++++++++++++++++++ documentation/roadmap.md | 11 ++++- 3 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 documentation/CLAUDE.md create mode 100644 documentation/decisions.md diff --git a/documentation/CLAUDE.md b/documentation/CLAUDE.md new file mode 100644 index 0000000..b3399d3 --- /dev/null +++ b/documentation/CLAUDE.md @@ -0,0 +1,18 @@ +# instructions + +## How we work together + +- We work through the roadmap **one checkbox at a time** +- For each checkbox, the mentor explains what needs to be done, the definition of done, and how to verify it +- The developer explains their approach first +- We discuss until the approach is solid +- The developer implements +- The developer shows the output for approval +- The mentor approves before moving to the next checkbox + +## Rules + +- **No code from the mentor** — explanations, directions, and feedback only +- **No implementing before discussing** — always align on the approach first +- **Commit after every approved checkbox** +- The mentor suggests commit messages when asked diff --git a/documentation/decisions.md b/documentation/decisions.md new file mode 100644 index 0000000..0b322e2 --- /dev/null +++ b/documentation/decisions.md @@ -0,0 +1,82 @@ +# Decisions Log + +A record of non-obvious technical decisions made during development, with reasoning. Intended to preserve context across sessions. + +--- + +## Tooling + +### Monorepo: pnpm workspaces (not Turborepo) +Turborepo adds parallel task running and build caching on top of pnpm workspaces. For a two-app monorepo of this size, plain pnpm workspace commands are sufficient and there is one less tool to configure and maintain. + +### TypeScript runner: `tsx` (not `ts-node`) +`tsx` is faster, requires no configuration, and uses esbuild under the hood. `ts-node` is older and more complex to configure. `tsx` does not do type checking — that is handled separately by `tsc` and the editor. Installed as a dev dependency in `apps/api` only. + +### ORM: Drizzle (not Prisma) +Drizzle is lighter — no binary, no engine. Queries map closely to SQL. Migrations are plain SQL files. Works naturally with Zod for type inference. Prisma would add Docker complexity (engine binary in containers) and abstraction that is not needed for this schema. + +### WebSocket: `ws` library (not Socket.io) +For rooms of 2–4 players, Socket.io's room management, transport fallbacks, and reconnection abstractions are unnecessary overhead. The WS protocol is defined explicitly as a Zod discriminated union in `packages/shared`, giving the same type safety guarantees. Reconnection logic is deferred to Phase 7. + +### Auth: OpenAuth (not rolling own JWT) +All auth delegated to OpenAuth service at `auth.yourdomain.com`. Providers: Google, GitHub. The API validates the JWT on every protected request. User rows are created or updated on first login via the `sub` claim as the primary key. + +--- + +## Architecture + +### Express app structure: factory function pattern +`app.ts` exports a `createApp()` factory function. `server.ts` imports it and calls `.listen()`. This allows tests to import the app directly without starting a server, keeping tests isolated and fast. + +### Data model: `terms` + `translations` (not flat word pairs) +Words are modelled as language-neutral concepts with one or more translations per language. Adding a new language pair requires no schema changes — only new rows in `translations` and `language_pairs`. The flat `english/italian` column pattern is explicitly avoided. + +### Multiplayer mechanic: simultaneous answers (not buzz-first) +All players see the same question at the same time and submit independently. The server waits for all answers or a 15-second timeout, then broadcasts the result. This keeps the experience Duolingo-like and symmetric. A buzz-first mechanic was considered and rejected. + +### Room model: room codes (not matchmaking queue) +Players create rooms and share a human-readable code (e.g. `WOLF-42`) to invite friends. Auto-matchmaking via a queue is out of scope for MVP. Valkey is included in the stack and can support a queue in a future phase. + +--- + +## TypeScript Configuration + +### Base config: no `lib`, `module`, or `moduleResolution` +These are intentionally omitted from `tsconfig.base.json` because different packages need different values — `apps/api` uses `NodeNext`, `apps/web` uses `ESNext`/`bundler` (Vite), and mixing them in the base caused errors. Each package declares its own. + +### `outDir: "./dist"` per package +The base config originally had `outDir: "dist"` which resolved relative to the base file location, pointing to the root `dist` folder. Overridden in each package with `"./dist"` to ensure compiled output stays inside the package. + +### `apps/web` tsconfig: deferred to Vite scaffold +The web tsconfig was left as a placeholder and filled in after `pnpm create vite` generated `tsconfig.json`, `tsconfig.app.json`, and `tsconfig.node.json`. The generated files were then trimmed to remove options already covered by the base. + +### `rootDir: "."` on `apps/api` +Set explicitly to allow `vitest.config.ts` (which lives outside `src/`) to be included in the TypeScript program. Without it, TypeScript infers `rootDir` as `src/` and rejects any file outside that directory. + +--- + +## ESLint + +### Two-config approach for `apps/web` +The root `eslint.config.mjs` handles TypeScript linting across all packages. `apps/web/eslint.config.js` is kept as a local addition for React-specific plugins only: `eslint-plugin-react-hooks` and `eslint-plugin-react-refresh`. ESLint flat config merges them automatically by directory proximity — no explicit import between them needed. + +### Coverage config at root only +Vitest coverage configuration lives in the root `vitest.config.ts` only. Individual package configs omit it to produce a single aggregated report rather than separate per-package reports. + +### `globals: true` with `"types": ["vitest/globals"]` +Using Vitest globals (`describe`, `it`, `expect` without imports) requires `"types": ["vitest/globals"]` in each package's tsconfig `compilerOptions`. Added to `apps/api`, `packages/shared`, and `packages/db`. Added to `apps/web/tsconfig.app.json`. + +--- + +## Current State + +### Completed checkboxes (Phase 0) +- [x] Initialise pnpm workspace monorepo: `apps/web`, `apps/api`, `packages/shared`, `packages/db` +- [x] Configure TypeScript project references across packages +- [x] Set up ESLint + Prettier with shared configs in root +- [x] Set up Vitest in `api` and `web` and both packages +- [x] Scaffold Express app with `GET /api/health` +- [x] Scaffold Vite + React app with TanStack Router (single root route) — **in progress** + +### Current checkpoint +Setting up TanStack Router in `apps/web` with a single root route. diff --git a/documentation/roadmap.md b/documentation/roadmap.md index 78add45..c439671 100644 --- a/documentation/roadmap.md +++ b/documentation/roadmap.md @@ -13,13 +13,13 @@ Each phase produces a working, deployable increment. Nothing is built speculativ - [x] Configure TypeScript project references across packages - [x] Set up ESLint + Prettier with shared configs in root - [x] Set up Vitest in `api` and `web` and both packages -- [ ] Scaffold Express app with `GET /api/health` +- [x] Scaffold Express app with `GET /api/health` - [ ] Scaffold Vite + React app with TanStack Router (single root route) - [ ] Configure Drizzle ORM + connection to local PostgreSQL - [ ] Write first migration (empty — just validates the pipeline works) - [ ] `docker-compose.yml` for local dev: `api`, `web`, `postgres`, `valkey` - [ ] `.env.example` files for `apps/api` and `apps/web` -- [ ] testing ts config inheritance with tsx --showConfig +- [ ] update decisions.md --- @@ -37,6 +37,7 @@ Each phase produces a working, deployable increment. Nothing is built speculativ - [ ] Implement `GET /language-pairs` and `GET /terms` endpoints - [ ] Define Zod response schemas in `packages/shared` - [ ] Unit tests for `QuizService` (correct POS filtering, never includes the answer) +- [ ] update decisions.md --- @@ -56,6 +57,7 @@ Each phase produces a working, deployable increment. Nothing is built speculativ - [ ] Frontend: TanStack Router auth guard (redirects unauthenticated users) - [ ] Frontend: TanStack Query `api.ts` attaches token to every request - [ ] Unit tests for JWT middleware +- [ ] update decisions.md --- @@ -71,6 +73,7 @@ Each phase produces a working, deployable increment. Nothing is built speculativ - [ ] `ScoreScreen` component: final score + play-again button - [ ] TanStack Query integration for `GET /terms` - [ ] RTL tests for `QuestionCard` and `OptionButton` +- [ ] update decisions.md --- @@ -93,6 +96,7 @@ Each phase produces a working, deployable increment. Nothing is built speculativ - [ ] Frontend: `/multiplayer/room/:code` — player list, room code display, "Start Game" (host only) - [ ] Frontend: `ws.ts` singleton WS client with reconnect on drop - [ ] Frontend: Zustand `gameStore` handles incoming `room:state` events +- [ ] update decisions.md --- @@ -112,6 +116,7 @@ Each phase produces a working, deployable increment. Nothing is built speculativ - [ ] Frontend: `ScoreBoard` component — live per-player scores after each round - [ ] Frontend: `GameFinished` screen — winner highlight, final scores, "Play Again" button - [ ] Unit tests for `GameService` (round evaluation, tie-breaking, timeout auto-advance) +- [ ] update decisions.md --- @@ -126,6 +131,7 @@ Each phase produces a working, deployable increment. Nothing is built speculativ - [ ] Drizzle migration runs on `api` container start - [ ] Seed production DB (run `seed.ts` once) - [ ] Smoke test: login → solo game → create room → multiplayer game end-to-end +- [ ] update decisions.md --- @@ -141,6 +147,7 @@ Not required to ship, but address before real users arrive. - [ ] Favicon, page titles, Open Graph meta - [ ] CI/CD pipeline (GitHub Actions → SSH deploy on push to `main`) - [ ] Database backups (cron → Hetzner Object Storage) +- [ ] update decisions.md ---