# PLAN-W6: Android Insights (advanced analytics from the server) ## 1. Goal Show the server's advanced analytics (D-133: per-category averages and trends per month, the 2-month forecast per account) in the Android app as an "Insights" section on S-11, online only (§9.9), consuming W7's `/analytics/*` endpoints. This is a UI-contract change (`:core:model` is a contract file, §14.8) with the data layer, fakes, the feature and goldens. ## 2. Read first 1. SPEC §15.8 and the server agent's D-135 to D-138 (SPEC v0.29: endpoint names, shapes, rounding), AC-14.1 (as revised), FR-14, §9.9, §14.2.4 (the UI contract: `AnalyticsRepository`, `AnalyticsState`, `OnlineResult`), §14.8, §6.2 (layering), §13.3 row S-11, D-128 (v0.27), D-133. 2. `contracts/openapi.yaml` `/analytics/*` and `contracts/examples/` for them (W7). 3. `docs/ux/design-spec.md` S-11 section, §3.10 (charts), §3.6 (offline hints); `docs/ux/strings.csv` (`analytics_*`). 4. Files: `android/core/model/**` (analytics types, `AnalyticsRepository`), `android/data/**` (`KvittApi`, DTOs, the analytics repository), `android/core/fakes/**` (fake analytics repository and scenarios), `android/feature/analytics/**`, `android/core/design/**` (read only), `android/README.md`. 5. `CLAUDE.md` (Android gate, layering, anti-patterns, screenshots, the phone). ## 3. Already established - The numbers are the server's; the app neither computes nor caches them across process restarts beyond what the brief allows (no Room table: a schema change would need its own decision). Offline, the section shows the "Needs connection" hint (`common_needs_connection`, §9.9) and S-11's own offline analytics stay as they are (AC-14.1). - `:core:model` gains the Insights types and repository members (names proposed by this plan, recorded as a decision); `:data` calls the endpoints through `KvittApi` with the common headers (§14.3.1, D-126's app key included) and maps errors as other online reads do; `:core:fakes` gets scenarios for loaded, empty, offline, error and long content; `:feature:analytics` renders the section below S-11's charts (or as the design-spec placement the report proposes) with strings in both languages. - New strings are proposed for `docs/ux/strings.csv` in the report (the docs agent records them; `docs/ux/**` is not this plan's). - Goldens for every new state in the three variants (D-098); open every changed PNG. ## 4. Owned paths From SPEC §14.7 (row W6): `android/feature/analytics/**`, and as a contract-change plan `android/core/model/**`, `android/data/**`, `android/core/fakes/**`. Catalog entries only if needed (`android/gradle/**`). Nothing in `server/**`, `contracts/**`, `web/**`, `docs/**`. ## 5. Deliverables - The `:core:model` additions with `ContractTest` updated; the `:data` client and repository with tests over the contract examples; fakes; the S-11 Insights section; screenshot tests and goldens; unit tests of the state holder. ## 6. Steps 1. Worktree: from `/Users/jhag/projects/kvitt`, `git worktree add .claude/worktrees/agent-w6 -b agent-w6 main`; in it `git reset --hard main`; copy `android/local.properties` and `android/app/google-services.json` from the main checkout (never commit); `tools/install-git-hooks.sh`. 2. Read §2. Confirm W7 has landed (`/analytics/` in `contracts/openapi.yaml` on `main`) and SPEC v0.29 records it; if not, stop and report. 3. `python3 tools/dependency-report/latest.py`; record the lines. 4. Model, data, fakes, feature, goldens. 5. Gate (§7). Commit on `agent-w6`, `git rebase main`, rerun the gate. Never merge, push or remove the worktree. The phone only if the brief names this agent for it. ## 7. Gate The Android gate, from `android/`: `PATH=/opt/homebrew/opt/openjdk@25/bin:$PATH ../tools/gradle-serial.sh check`. Green: `BUILD SUCCESSFUL` in this session, test counts from fresh XML, screenshot verification passing. ## 8. HUMAN steps From SPEC §11.2: look at S-11's Insights on the phone (yes/no), after the orchestrator installs the build and the server image with W7 is deployed. ## 9. Out of scope - The endpoints (W7); the web's W-11 (W4); a Room cache of the insights; any change to S-11's offline analytics or to D-128's line chart. ## 10. Report - Branch `agent-w6`, head commit after rebasing; gate lines; tests; goldens added (names). - Proposed decision entry and §14.2.4 spec text for the contract additions (numbered from the brief); proposed `strings.csv` rows (en, sv). - Dependency-report lines; open questions with SPEC section numbers. ## 11. Numbering Assigned in the start prompt (a decision and a spec version for the UI-contract change); use `TODO(spec)` if none was given.