feat(api): viewer read-only API — epic E4 (TASK-33…40) #4
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/api"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Complete viewer REST API per
docs/spec/05-api/viewer-api.mdand the OpenAPIcontract
docs/contracts/api/viewer-api.openapi.yaml— 8 endpoints, read-only(CON-002, NFR-031, D-18): metadata from PostgreSQL, events from JSONL journals
in the named volume (D-62). No game logic, no calls into game-core.
Endpoints (base path
/api/v1, D-72)GET /health— liveness probe;GET /sessions/current— active session ornext_scheduled_atfromSessionScheduled.planned_at (FR-040, D-84);
GET /sessions— finished sessions, offset pagination, newest first;GET /sessions/{id}— metadata, roster with roles (D-43),events_count;GET /sessions/{id}/events— event page viaafter/limitcursor,last_seq,session_status(polling stop signal, D-73); single mechanismfor live and replay (FR-031, ADR-004), no visibility filtering (D-43);
GET /players,GET /players/{id}— catalog-consistent attributes (FR-020),public memory (D-52), stats history (D-66);
GET /stats/overview— six D-20 metrics (draft D-74, TODO in code);GET /sessions/test— journal fixturedata/fixtures/test-session.jsonlunder the
/sessions/{id}/eventscontract (FR-044, D-63, D-75).Key decisions
JournalReader(TASK-34): cursor paging withseq > after, parsing only viadomain
JournalLine.from_json(CON-003), tolerant of a live file beingappended (broken tail line skipped, D-62); reused by
/sessions/testunchanged (D-75).
serialization happens in the route layer.
{"error": {code, message}}— 400 (invalidparameters), 404 (not found), 500 without internals plus an ERROR log entry
(NFR-040); request metrics middleware (method/path/status/latency_ms) in
structured JSON logs (D-82).
Tests and checks
endpoints, error-code table, p95 reader benchmark (NFR-012 ≤ 500 ms),
fixture coverage of every event type.
ruff check,ruff format --check,ty check,uv run pytest,nix flake check— all green.Traceability
FR-030, FR-031, FR-040, FR-043, FR-044; D-16, D-43, D-51, D-52, D-53, D-62,
D-63, D-66, D-72, D-73, D-75; NFR-012, NFR-031, NFR-040; ADR-004.
Open notes:
TODO(D-74)inStatsRepository(the/stats/overviewfieldcomposition is finalized together with the frontend epic E5 / TASK-48).