summaryrefslogtreecommitdiff
path: root/CLAUDE.md
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2026-11-08 21:56:29 +0100
committerJoel Klinghed <the_jk@spawned.biz>2026-11-08 21:56:29 +0100
commitf6955e34489c79f6d5b764cb6a39b1387366b433 (patch)
tree83dad99ad81964036820468ad23fdc9ebe5c20a5 /CLAUDE.md
parent0578ed0e5a08e6790a2e02416c4bf79f8c471f2d (diff)
Phase 0: project scaffolding
- server/: Dart game-server package (shelf + WebSocket) with the hello/welcome handshake, ping/pong, error responses, healthz, static SPA serving with SPA fallback, and smoke tests (5/5) - web/: Svelte 5 + TypeScript SPA with the protocol client, connection-status page, vitest and svelte-check; Vite dev server proxies /ws to the Dart server - game data assets copied from the read-only reference app into server/assets/ (data, images, i18n, fonts, testData) - PLAN.md implementation plan and progress tracker; README rewritten for the web app; AGPLv3 LICENSE inherited from the reference app; .gitignore; scripts/ci.sh (full pipeline) - CLAUDE.md project guidance Verified: scripts/ci.sh passes end-to-end; live smoke confirms the server serves the built SPA at / and answers a WebSocket hello with a welcome message.
Diffstat (limited to 'CLAUDE.md')
-rw-r--r--CLAUDE.md100
1 files changed, 100 insertions, 0 deletions
diff --git a/CLAUDE.md b/CLAUDE.md
new file mode 100644
index 0000000..eb90e37
--- /dev/null
+++ b/CLAUDE.md
@@ -0,0 +1,100 @@
+# CLAUDE.md
+
+This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
+
+## What this repository is
+
+This is a **greenfield project** to re-architect **X-haven Assistant** — a companion app for the
+Gloomhaven/Frosthaven board games — as a **server-driven web app**. The existing app is a
+Flutter client where each device runs its own copy of the game and syncs state over an ad-hoc
+local-network socket; that network layer is unreliable (frequent disconnects/desyncs). The goal
+is to move all game state onto a web server, so each player just opens the game page in a browser
+tab and the server is the single source of truth.
+
+The design intent lives in `README.md` at the repo root. The reference implementation (what we are
+re-architecting) lives in `FrosthavenAssistant/`.
+
+## The reference app is READ-ONLY
+
+`FrosthavenAssistant/` is a checkout of the existing upstream app. **Do not modify anything in it.**
+It is also gitignored (see `.gitignore`), so the new web-app code in this repo is kept separate from
+it. Treat it purely as the source of truth for game logic, data files, and behavior to be reproduced.
+
+Reference layout:
+- `frosthaven_assistant/` — the Flutter app (client + embedded server). Entry point `lib/main.dart`.
+- `frosthaven_assistant_server/` — standalone Dart server library (the `GameServer` base class and
+ wire protocol). Path dependency of the app.
+- `room-data-converter/` — one-off Dart tool for reshaping scenario room/monster JSON.
+- `docs/manual/` — user manual (HTML), incl. `09-multiplayer.html` for the networking model.
+
+## Target architecture (the web app we are building)
+
+Key requirements from the root `README.md` — these differ from the existing app and should drive design:
+
+- **Server owns all state.** The web server runs the app and is the authoritative source of game
+ state. Clients do **not** keep or sync their own state.
+- **Clients send input only.** A player's browser submits user actions to the server; it does not
+ carry game state locally.
+- **Spectator clients.** Beyond the players, other clients may open the page just to view the
+ current state (read-only observers).
+- **Per-player secret data.** Some data must be visible only on the owning player's browser until
+ a game event reveals it. The canonical example: each player's initiative/"priority" input is shown
+ only in their own tab until *all* players have entered and the draw-action is tapped. (The existing
+ app already does this — see "secret initiative" below — so the web version needs an equivalent
+ server-gated, per-connection visibility model.)
+
+## Reference app architecture (source of truth for game logic)
+
+The Flutter app uses a **Command pattern + ValueNotifier** hybrid:
+
+- **All state mutations go through `Command` objects** in `frosthaven_assistant/lib/Resource/commands/`
+ (77 files: `AddMonsterCommand`, `DrawCommand`, `ChangeHealthCommand`, etc.). Each implements
+ `execute()`/`undo()`/`describe()`. Mutation methods are gated by a private `_StateModifier`
+ capability token, so only commands can mutate state. Never mutate state directly.
+- **State is exposed as `ValueNotifier`s** (`ValueListenable<T>` getters); the UI rebuilds via
+ `ValueListenableBuilder`. `GameState` (in `lib/Resource/state/`) is the central holder, split
+ across `part` files.
+- **`ActionHandler`** provides undo/redo (deep command history + `GameSaveState` snapshots) and is
+ network-aware.
+- **Dependency injection via GetIt** (`getIt<ClassName>()`), set up in
+ `lib/services/service_locator.dart` (`setupGetIt()`). Singletons: `GameData`, `Settings`,
+ `GameState`, `Communication`, `Network`, `Connection`, `Client`.
+- **`GameData`** (repository pattern) loads campaign/monster/ability/scenario data from JSON assets
+ under `frosthaven_assistant/assets/data/` (`editions/`, `rooms/`). Test fixtures mirror this in
+ `assets/testData/`.
+
+Existing networking (what we are replacing) is in `lib/services/network/` plus the
+`frosthaven_assistant_server` package:
+- **Wire protocol:** messages framed as `S3nD:<payload>[EOM]` over a raw TCP socket (default port
+ 4567). State updates travel in a JSON envelope `{i: index, d: description, e: event, s: state}` —
+ a monotonically-increasing **command index** plus a full serialized state string, with mismatch
+ recovery (a client that drifts is overwritten by server state).
+- **Secret initiative:** `InitiativeWidgetViewModel.isSecret` hides an initiative value on a
+ connected device unless that device is the one that made the change (tracked by
+ `CharacterWidgetInternal.localCharacterInitChanges`). This is the model to generalize into the
+ server-gated per-player visibility for the web app.
+
+## Commands (for the reference Flutter app)
+
+Run these from inside `FrosthavenAssistant/frosthaven_assistant/`:
+
+```bash
+flutter run # run the app
+flutter doctor # verify Flutter toolchain
+flutter test # run all unit tests
+flutter test test/path/file.dart # run a single test file
+flutter analyze # static analysis
+```
+
+Unit tests depend on **mockito** codegen — generate mocks before running tests:
+
+```bash
+dart run build_runner build # REQUIRED: generates .mocks.dart
+flutter test
+```
+
+If `build_runner` errors, try `dart pub upgrade` then re-run the build.
+
+The standalone server package is plain Dart (`dart run`/`dart test` from
+`FrosthavenAssistant/frosthaven_assistant_server/`); it is also the base for the Dockerized
+`ghcr.io/tarmslitaren/x-haven-server` (default port 4567).