Merge Phase 2 into the UI branch, so auth is built on top of it

Phase 3 auth is next, and this branch's server/ was still at Phase 1. Building
sessions here without merging first would have meant writing them against a
config.py with credentials still defaulted, no deps.py device auth to follow as
a pattern, and - the one that actually matters - no rate limiter, leaving a
login endpoint brute-forceable until the branches finally met.

So the branches meet now, while the only conflict is a documentation one, rather
than later on top of an auth implementation.

TODO.md was the single conflict: both sides had edited Phase 3, which is exactly
what should happen when one branch finishes Phase 2 and the other starts the UI.
Both sides' content is kept - the Phase 2 ticks and the UI decisions in 3.0 -
and the resolution fixed two things a purely textual merge leaves broken:

  - "Minimal gallery page, no auth yet" is struck. SPEC 3.3 requires image
    serving to be auth-checked, so that is not a state the gallery can
    legitimately pass through, and the scaffold's System page already proves the
    browser-to-Postgres path that item existed to prove.
  - The themes line appeared twice, once ticked by the scaffold and once not.
    The genuinely open half is persisting the choice per user, which needs
    accounts, so that is what it now says.

web/ is untouched by the merge: it had no files at the merge base and none on
the server branch, so that side contributes no deletion. Verified - 27 files
before and after.

Verified both halves after resolving: server 194 passed, ruff clean, alembic
clean; UI typecheck clean, build green, 36 contrast pairs across 3 themes with
no failures.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Thomas KarnerandClaude Opus 5 committed 2026-09-21 17:48:55 +02:00
commit 89ebe99bed
44 files changed
+6751 -95

No files matched your search

+40 -15
View File
@@ -26,10 +26,10 @@ Anything here that contradicts SPEC means SPEC needs an edit, not a workaround.
| Area | State |
|---|---|
| Firmware | Written, compiles, **never run on hardware**. Known gaps below. |
| Device↔server contract | Specified in full (`firmware/API.md`). Nothing implements the server half. |
| Data model | Designed (SPEC §3) + §0 additions. No migration written. |
| Server | Phase 1 skeleton in [`server/`](server/) — config, schema, health, job queue, scheduler, systemd units. Verified end to end on Python 3.14.7 against PostgreSQL 17: 12/12 tests, migrations applied, API serving, worker draining the queue. Not yet on the real host. |
| WebUI | **Nothing exists.** |
| Device↔server contract | Specified in full (`firmware/API.md`). Server half of the **device** endpoints implemented (Phase 2); the operator-facing half (firmware upload, device management) waits on user auth in Phase 3. |
| Data model | Designed (SPEC §3) + §0 additions, migration written and applied, guarded by a drift test. |
| Server | Phases 1 and 2 in [`server/`](server/) — config, schema, health, job queue, scheduler, systemd units, and every device endpoint the firmware calls. Verified on Python 3.14.7 against PostgreSQL 17: 194 tests, migrations applied, real HTTP ingest through the worker to a WebP thumbnail on disk. Not yet on the real host, and **never yet spoken to by real firmware**. |
| WebUI | **Nothing exists** beyond the Vite scaffold on `feature/UI_Basic_implementation`. |
---
@@ -89,7 +89,7 @@ written vs. what still needs doing on the real host:
- [ ] PostgreSQL 17 from the distro or PGDG repo; dedicated role + database; **loopback TCP with `scram-sha-256`, not a Unix socket** (see 1.2)
- [ ] Caddy DNS provider plugin build (`caddy add-package …`) and a real hostname
- [ ] Tailscale for remote access
- [ ] Image store at `/srv/poorbird/images/YYYY/MM/DD/<uuid>.jpg`, thumbs alongside as `_400.webp` (SPEC §3.3) — paths configured, writer is Phase 2
- [x] Image store at `/srv/poorbird/images/YYYY/MM/DD/<uuid>.jpg`, thumbs alongside as `_400.webp` (SPEC §3.3) — writer landed with Phase 2; writes are atomic (`.part` then `os.replace`) so a crash cannot leave a half-JPEG that a thumbnail job would then fail on
- [ ] journald log retention capped, disk usage alarmed
### 1.1 Schema — SPEC §3 plus the §0 additions
@@ -126,15 +126,30 @@ cheap today and most are the better native choice regardless.
The first milestone worth celebrating. Nothing below this line matters until a real
bird photo appears in a browser.
- [ ] `POST /api/v1/enroll` — bootstrap secret in, per-device `reenroll_secret` + token out.
- [x] `POST /api/v1/enroll` — bootstrap secret in, per-device `reenroll_secret` + token out.
**Re-enrolling a known `device_uid` must return the existing row with a fresh token, never a duplicate.**
- [ ] `POST /api/v1/ingest` — multipart image + JSON meta, honour `X-Pre-Trigger`, dedupe on sha256
- [ ] `POST /api/v1/heartbeat` and `POST /status` — full conditions report into `device_status`
- [ ] `GET /api/v1/config` — enums by name not number, `config_version` bump semantics
- [ ] Response envelope + `server_time` in **every** response (SPEC C7: `received_at` stays authoritative)
- [ ] Thumbnail job on ingest
- [ ] Minimal gallery page, no auth yet, purely to prove the path
- [ ] **End-to-end test on real hardware:** bird walks past → burst uploads → visible in browser
Accepts the shared secret *or* that device's own `reenroll_secret`; checking only the
shared one would lock out every device already enrolled. Hardware facts (`mac`,
`hw_revision`, `fw_version`) refresh on every enrollment, the operator's `name` does not.
- [x] `POST /api/v1/ingest` — **raw JPEG body with metadata in headers, not multipart.**
`firmware/API.md` and `uploader.cpp` send the bytes directly; multipart was a
misreading. Honours `X-Pre-Trigger`, dedupes on sha256 per device.
- [x] `POST /api/v1/heartbeat` and `POST /status` — full conditions report into `device_status`
- [x] `GET /api/v1/config` — enums by name not number, `config_version` bump semantics.
Column-backed keys win over stale JSONB copies, so an operator rename actually reaches
the device; the device's own `config_version` never overwrites the server's.
- [x] Response envelope + `server_time` (SPEC C7: `received_at` stays authoritative).
On `/heartbeat` and `/ingest`. **Not** on `/status`, which is 204 with no body per
`firmware/API.md` — "every response" was not compatible with the firmware contract.
- [x] Thumbnail job on ingest — 400px WebP, decode kept off the request path
- [x] Device authentication, rate limiting, `POST /commands/{id}/ack`, `GET /firmware/{v}.bin`
— not in the original list, but the firmware calls them (see `docs/reviews/`)
- [~] Minimal gallery page purely to prove the path — **superseded.** The scaffold's System page
already proves browser → proxy → FastAPI → Postgres, and SPEC §3.3 requires image serving
to be auth-checked, so "no auth yet" is not a state the gallery can legitimately pass
through. The real grid is Phase 3, behind sessions.
- [ ] **End-to-end test on real hardware:** bird walks past → burst uploads → visible in browser.
Blocked on Phase 0: the server side is proven only against synthetic uploads.
---
@@ -155,10 +170,16 @@ and the System page reads live data through the Vite proxy.
- [ ] Observation editor — `captures` 1—n `observations`, so a photo can hold two species or none
- [ ] Taxon autocomplete; seed `taxa` with 60–80 Central European garden species incl. GBIF keys, `name_de` + `name_en`, `is_local_common` ranking first
- [ ] Tags, favourite/reject (`kept`), review flag
- [ ] Three themes — light, dark, blue — as design tokens → CSS custom properties, persisted per user
- [ ] Persist the theme choice **per user** (`users.theme`) rather than in localStorage — the
tokens and the switcher are done (above); this is the half that needs accounts to exist
- [ ] Auth: session cookies, Argon2id, CSRF, RBAC per SPEC §3.1 (viewer / editor / admin), `audit_log` on every mutation
- [ ] **Auth-checked image serving** — the app authorizes, Caddy serves the bytes. An unguessable URL is not access control
- [ ] TOTP 2FA — see 3.0 for the policy
- [ ] **Revisit CORS.** Deliberately not configured in Phase 2: Caddy serves the built UI and the
API from one origin, so there is no cross-origin request to permit, and adding permissive
headers "for the UI" would only weaken that. The Vite dev server proxies `/api` for the
same reason, so development matches production. Decide it properly only if the UI is ever
served from somewhere else — *then* it matters.
### 3.0 UI decisions (2026-09-21)
@@ -231,7 +252,11 @@ brings real captures, which is the only test that counts.
- [ ] Device list with live/awake state, last seen, RSSI, heap/PSRAM, ring depth
- [ ] Settings editor writing the `devices` settings surface → `apply_config` → `config_version`
- [ ] Command queue UI: `wake_and_hold`, `capture_now`, `apply_config`, `ota_update`, `stream_start`, `reboot`; commands ride along on the ingest response
- [ ] Firmware upload, SHA-256, target marking, per-device staged rollout
- [ ] Firmware upload, SHA-256, target marking, per-device staged rollout.
`GET /firmware/{version}.bin` already serves the bytes; the upload half was left out of
Phase 2 because it needs operator auth. **Constrain `firmware.is_target` to a single row
while doing this** — nothing enforces it today, and the lookup takes the first match, so
two target rows would pick non-deterministically between them.
- [ ] Verify the full OTA path on hardware: **trial boot and automatic rollback**. The camera is unreachable once mounted — this is the one feature with no recovery if it is broken
- [ ] Document that rotating the shared bootstrap secret server-side without shipping new firmware **removes the last-resort escape hatch**