Add podman compose deployment, dev script and docs
Containerfile + compose (app + Caddy with automatic HTTPS), env-driven domain/limits/ports, VAPID key generation that never prints the key. SPEC updated to match the implementation (Node stdlib server, Svelte SPA, revert by event id, backup contents, push options). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013FYo6JSV1fDU1fm3LU77iF
This commit is contained in:
parent
a78d855886
commit
8c4e37ce4b
9 changed files with 365 additions and 42 deletions
106
SPEC.md
106
SPEC.md
|
|
@ -3,7 +3,7 @@
|
|||
A mobile-first, end-to-end encrypted group expense splitter (a Settle Up
|
||||
clone) that runs in any browser, on phones and desktops alike.
|
||||
|
||||
Status: **v1, agreed** · Last updated: 2026-10-09
|
||||
Status: **v1, implemented** · Last updated: 2026-10-09
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -138,7 +138,7 @@ Decrypted plaintext:
|
|||
| `expense.deleted` / `expense.restored` | expenseId |
|
||||
| `comment.added` / `comment.deleted` | commentId, expenseId, text |
|
||||
| `recurring.created` / `recurring.updated` / `recurring.deleted` | template (see 7.4) |
|
||||
| `revert` | targetSeq — see 6.2 |
|
||||
| `revert` | targetId (an event id) — see 6.2 |
|
||||
|
||||
Updates carry the full new object (not a diff), so the latest event per
|
||||
entity fully defines it. Conflicts resolve **last-writer-wins by server
|
||||
|
|
@ -244,10 +244,12 @@ the minimum in practice, and is easy to reason about.
|
|||
|
||||
- **Restore an expense**: undelete, or roll it back to a chosen earlier
|
||||
version (emits `expense.updated` / `expense.restored` with the old content).
|
||||
- **Rewind the whole group to a point in time**: emits a `revert { targetSeq }`
|
||||
event. Replay treats the state as the state at `targetSeq`, and then applies
|
||||
later events normally. Nothing is ever erased, so a rewind can itself be
|
||||
undone (revert to the seq just before the revert).
|
||||
- **Rewind the whole group to a point in time**: emits a `revert { targetId }`
|
||||
event naming an earlier event. Replay replaces the state with a snapshot
|
||||
taken right after that event, then applies later events normally. Nothing
|
||||
is ever erased, so a rewind can itself be undone (revert to the event just
|
||||
before the revert). Event ids rather than seqs are used so a restored
|
||||
backup, which gets new seqs, keeps working.
|
||||
- The log is append-only on the server; there is no destructive delete API
|
||||
for events (only deleting the entire group, see 8.3).
|
||||
|
||||
|
|
@ -293,8 +295,9 @@ Transfers have their own implicit category.
|
|||
- There is no server-side worker (the server cannot read templates). When any
|
||||
member's client opens the group and a due occurrence is missing, it creates
|
||||
it. The occurrence's expense ID is derived deterministically
|
||||
(`UUIDv5(templateId + occurrenceDate)`), so two clients doing it at once
|
||||
produce the same ID and replay deduplicates it.
|
||||
(`rec-<templateId>-<occurrenceDate>`), so two clients doing it at once
|
||||
produce the same ID; `expense.created` is first-wins on replay, so the
|
||||
duplicate is ignored. Deleted occurrences are not recreated.
|
||||
- Occurrences are normal expenses (editable/deletable individually).
|
||||
|
||||
### 7.5 Statistics
|
||||
|
|
@ -310,17 +313,27 @@ Client-side charts per group, filterable by date range:
|
|||
|
||||
- **CSV export** of expenses (one row per expense, columns per member share)
|
||||
and of current balances.
|
||||
- **Encrypted backup**: full event log + photos as one file, encrypted with
|
||||
the group key. Restoring it recreates the group on the same or a new server.
|
||||
- **Backup file** (JSON): the encrypted event log and photos exactly as the
|
||||
server stores them, **plus the group secret**, so a group can be restored
|
||||
even if every link is lost. The file is therefore as sensitive as the link,
|
||||
and the UI says so. Restoring creates the group on the server (or finds it
|
||||
already there) and re-uploads everything; uploads are idempotent by id, so
|
||||
an interrupted restore can simply be run again.
|
||||
|
||||
### 7.7 Push notifications
|
||||
|
||||
- Opt-in per group per device (Web Push, VAPID).
|
||||
- Because the server cannot read events, the push it sends **contains no
|
||||
content**, just `{ groupId }`. The service worker wakes, fetches new events,
|
||||
decrypts them locally and shows "Anna added Dinner · 120.50 EUR".
|
||||
content**, just `{ g: groupId }` (itself encrypted to the browser per
|
||||
RFC 8291). The service worker wakes, fetches new events, decrypts them
|
||||
locally and shows "Anna: Dinner · 120.50 EUR". It stays quiet if that
|
||||
group is open and focused.
|
||||
- The server skips the device that created the event (`deviceId`).
|
||||
- Notification options: all activity / only expenses involving me.
|
||||
- On/off per group only. An "only expenses involving me" option was dropped:
|
||||
browsers require every push to show a notification, so the worker can't
|
||||
silently discard irrelevant ones.
|
||||
- The server only delivers to known push services (FCM, Mozilla, Apple,
|
||||
Windows), so a registered endpoint can't make it call arbitrary hosts.
|
||||
- iOS: works only when the app is installed to the home screen (iOS 16.4+);
|
||||
the UI explains this.
|
||||
|
||||
|
|
@ -345,13 +358,18 @@ All group endpoints require `Authorization: Bearer <authToken>`.
|
|||
| `POST/DELETE /api/groups/:id/push` | Register/unregister a Web Push subscription. |
|
||||
| `DELETE /api/groups/:id` | Delete group, events and blobs (requires typing the group name client-side as confirmation). |
|
||||
| `GET /api/rates?date=YYYY-MM-DD` | Daily reference rates (no auth). |
|
||||
| `GET /api/config` | Public settings: VAPID public key, size limits (no auth). |
|
||||
| `GET /api/health` | Health check. |
|
||||
|
||||
Unknown groups and wrong tokens both answer `404`, so the API doesn't reveal
|
||||
which group ids exist.
|
||||
|
||||
### 8.2 Exchange rates
|
||||
|
||||
- The server fetches **ECB daily reference rates** (~30 currencies, via
|
||||
Frankfurter or ECB XML directly) once a day and caches them in SQLite,
|
||||
including history for back-dated expenses.
|
||||
- The server fetches **ECB daily reference rates** (~30 currencies, from the
|
||||
ECB's own XML feed) every 6 hours and caches them in SQLite. The first run
|
||||
loads the full history (back to 1999) for back-dated expenses; later runs
|
||||
fetch the last 90 days.
|
||||
- Clients fetch from our server only, so third parties don't learn users' IPs
|
||||
or currency usage. Clients cache rates offline.
|
||||
- Currencies outside the ECB set can be used with a manually entered rate.
|
||||
|
|
@ -364,7 +382,8 @@ All group endpoints require `Authorization: Bearer <authToken>`.
|
|||
- Limits (env variables, see 13): photo blob ≤ 2 MB (`MAX_PHOTO_BYTES`),
|
||||
event ≤ 64 KB (`MAX_EVENT_BYTES`), per-group storage ≤ 200 MB
|
||||
(`MAX_GROUP_BYTES`), group creation rate limit (`GROUP_CREATE_PER_HOUR`).
|
||||
The thumbnail counts as part of its photo.
|
||||
The server enforces the photo limit per uploaded blob; the client keeps a
|
||||
photo and its thumbnail together under it.
|
||||
- Inactive-group retention: none by default (configurable).
|
||||
|
||||
---
|
||||
|
|
@ -461,23 +480,24 @@ Hardening:
|
|||
|
||||
| Layer | Choice | Why |
|
||||
|---|---|---|
|
||||
| Frontend | **SvelteKit** (static adapter, SPA) + TypeScript | Small bundles (fast on phones), simple reactivity |
|
||||
| PWA | Vite PWA plugin (Workbox) | Service worker, offline cache, push handling |
|
||||
| Local storage | IndexedDB (via `idb`) | Groups, events, blobs cache |
|
||||
| Charts | Lightweight library (e.g. Chart.js or LayerCake) | Stats tab |
|
||||
| i18n | `svelte-i18n` or a small typed dictionary | EN/CS |
|
||||
| Backend | **Bun + Hono** + TypeScript | Tiny, fast, shares types with the frontend |
|
||||
| DB | SQLite (`bun:sqlite`) | Zero-ops, single file |
|
||||
| Frontend | **Svelte 5 + Vite** SPA, TypeScript, a ~60-line history router | Small bundle (~65 KB gzipped), simple reactivity; SvelteKit wasn't needed for a static SPA |
|
||||
| PWA | Hand-written service worker, built as a classic script by a second Vite step | Offline shell, push handling; no Workbox dependency |
|
||||
| Local storage | IndexedDB (small hand-written wrapper) | Groups, events, outbox, blobs cache; shared with the service worker |
|
||||
| Charts | Hand-built HTML/CSS bars | Stats tab; no chart library |
|
||||
| i18n | Small typed dictionary (`locales/en.ts`, `cs.ts`) | EN/CS; the type makes missing translations a compile error |
|
||||
| Backend | **Node 24, standard library only** (`node:http`, `node:sqlite`, `node:crypto`), run as TypeScript via type stripping | No npm dependencies on the server; Node was already on the dev box (Bun would have meant another runtime) |
|
||||
| DB | SQLite (`node:sqlite`) | Zero-ops, single file |
|
||||
| Tests | Vitest (money math, replay, crypto), Playwright (E2E on mobile + desktop viewports) | Rounding and replay must be bulletproof |
|
||||
| Proxy/TLS | **Caddy** | Automatic HTTPS (required for WebCrypto, service workers and push) |
|
||||
|
||||
Repo layout (monorepo):
|
||||
|
||||
```
|
||||
apps/web SvelteKit client
|
||||
apps/server Bun + Hono API
|
||||
packages/core shared: types, event schema, money math, replay, crypto
|
||||
deploy/ compose.yaml, Caddyfile, .env.example
|
||||
apps/web Svelte client + service worker
|
||||
apps/server Node API (no dependencies)
|
||||
packages/core shared: types, event schema, money math, replay, settle-up, recurring, stats, CSV
|
||||
deploy/ Containerfile, compose.yaml, Caddyfile, .env.example, README
|
||||
e2e/ Playwright tests
|
||||
```
|
||||
|
||||
---
|
||||
|
|
@ -486,7 +506,7 @@ deploy/ compose.yaml, Caddyfile, .env.example
|
|||
|
||||
`deploy/compose.yaml` runs two services:
|
||||
|
||||
- `app`: the Bun server, which also serves the built static client. Listens
|
||||
- `app`: the Node server, which also serves the built static client. Listens
|
||||
on the internal network only.
|
||||
- `caddy`: TLS termination + reverse proxy, the only service publishing
|
||||
ports (80/443).
|
||||
|
|
@ -497,15 +517,15 @@ Deploy steps (documented in `deploy/README.md`):
|
|||
|
||||
1. Point a DNS A/AAAA record at the VPS.
|
||||
2. `cp deploy/.env.example deploy/.env && chmod 600 deploy/.env`, then set
|
||||
`DOMAIN` (e.g. `oweme.example.com`). `compose.yaml` passes it to both
|
||||
services as `${DOMAIN}`: Caddy uses it for the site address and
|
||||
certificate, and the app uses it for share links and the CSP. Generate
|
||||
VAPID keys with the provided script, which writes them into `.env` without
|
||||
printing them.
|
||||
`DOMAIN` (e.g. `oweme.example.com`); Caddy uses it for the site address
|
||||
and certificate. (The app itself needs no domain: share links use the
|
||||
page's own origin and the CSP is `'self'`.) Generate VAPID keys with
|
||||
`gen-vapid.ts` inside the built image, which writes them into `.env`
|
||||
without printing them.
|
||||
3. Rootless Podman cannot bind ports < 1024 by default: either set
|
||||
`net.ipv4.ip_unprivileged_port_start=80` via sysctl, or publish 8080/8443 and
|
||||
redirect with the firewall — both documented.
|
||||
4. `podman compose up -d`. Updates: `git pull && podman compose up -d --build`.
|
||||
4. `cd deploy && podman compose up -d`. Updates: `git pull && podman compose up -d --build`.
|
||||
5. Backups: copy the data volume. All contents are already encrypted, so
|
||||
backups can be stored anywhere.
|
||||
|
||||
|
|
@ -514,12 +534,14 @@ Environment variables (`deploy/.env`, read by `compose.yaml`):
|
|||
| Variable | Required | Default | Purpose |
|
||||
|---|---|---|---|
|
||||
| `DOMAIN` | yes | — | Public hostname; Caddy site + TLS, share links |
|
||||
| `VAPID_PUBLIC_KEY` / `VAPID_PRIVATE_KEY` | yes | — | Web Push (generated by script) |
|
||||
| `VAPID_SUBJECT` | yes | — | `mailto:` contact for push services |
|
||||
| `VAPID_PUBLIC_KEY` / `VAPID_PRIVATE_KEY` | for push | — | Web Push (generated by script); empty = notifications off |
|
||||
| `VAPID_SUBJECT` | for push | — | `mailto:` contact for push services |
|
||||
| `MAX_PHOTO_BYTES` | no | `2097152` | Per-photo upload cap |
|
||||
| `MAX_EVENT_BYTES` | no | `65536` | Per-event cap |
|
||||
| `MAX_GROUP_BYTES` | no | `209715200` | Per-group storage cap |
|
||||
| `GROUP_CREATE_PER_HOUR` | no | `10` | Group creations per IP per hour |
|
||||
| `BIND_ADDR` | no | `0.0.0.0` | Address Caddy's ports are published on |
|
||||
| `HTTP_PORT` / `HTTPS_PORT` | no | `80` / `443` | Host ports for Caddy |
|
||||
|
||||
Development (on the dev box): servers bind `127.0.0.1` only; preview over an
|
||||
SSH tunnel. Ports and commands go in `AGENTS.md`.
|
||||
|
|
@ -528,12 +550,14 @@ SSH tunnel. Ports and commands go in `AGENTS.md`.
|
|||
|
||||
## 14. Milestones
|
||||
|
||||
All five milestones below shipped together in the first implementation
|
||||
(2026-10-09):
|
||||
|
||||
1. **Core**: crypto, event log, sync, groups (link + QR), members, identity,
|
||||
expenses with all split modes in a single currency, balances, settle-up,
|
||||
transfers, remembered groups, EN/CS, dark/light theme, PWA + offline,
|
||||
podman compose deploy.
|
||||
expenses with all split modes, balances, settle-up, transfers, remembered
|
||||
groups, EN/CS, dark/light theme, PWA + offline, podman compose deploy.
|
||||
2. **Money & media**: multiple currencies + rates service, photos.
|
||||
3. **History**: activity feed, per-expense history, restore, group rewind.
|
||||
4. **Extras**: comments, categories, statistics, recurring expenses, CSV
|
||||
export, encrypted backup/restore.
|
||||
export, backup/restore.
|
||||
5. **Notifications**: Web Push.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue