113 lines
8.6 KiB
Markdown
113 lines
8.6 KiB
Markdown
# FamChore v2 — Development Memory
|
|
|
|
## UI Component Architecture (Jul 2026)
|
|
|
|
### Layout Hierarchy
|
|
```
|
|
+layout.svelte ← global styles, meta, favicon
|
|
├── /login, /signup, /join/* ← auth pages (no shell)
|
|
└── [fam]/+layout.svelte ← Shell: Sidebar + TopNav + Footer + claim toast
|
|
├── [fam]/+page.svelte ← fam dashboard
|
|
├── [fam]/{username}/+page.svelte ← parent=admin overview, child=kanban
|
|
├── [fam]/{username}/chores/+page.svelte ← parent only
|
|
├── [fam]/{username}/rewards/+page.svelte ← parent only
|
|
├── [fam]/{username}/bonuses/+page.svelte ← parent only
|
|
├── [fam]/{username}/settings/+page.svelte ← parent only
|
|
└── [fam]/{username}/preferences/+page.svelte ← both roles
|
|
```
|
|
|
|
### Sidebar (collapsible to mini-mode)
|
|
- Header: app name (FamChore)
|
|
- Admin CTAs: Dashboard, Chores, Rewards (badge count), Bonuses
|
|
- Member CTAs: Dashboard, Preferences
|
|
- Footer: family name, Settings (admin only), Log out
|
|
- Role-aware: items differ based on admin vs member route
|
|
|
|
### TopNav
|
|
- Slot `announcement` (center) — system/family messages
|
|
- Slot `actions` (right) — user status, claim/message
|
|
|
|
### Page Content
|
|
- `ViewHeader` — title + subtitle + tool bar (tabs, weeknav, sort)
|
|
- `CardGrid` — 3-column grid, Cards span columns via `cols` prop
|
|
- `Card` — 1/2/3 col span, micro-layout per page
|
|
- `Accordion` — for settings / log sections
|
|
- `Button` — consistent CTAs with `variant` (primary/secondary/ghost/danger) and `size` (sm/md/lg)
|
|
|
|
### Components (frontend/src/lib/components/)
|
|
- `Sidebar.svelte`, `TopNav.svelte`, `Footer.svelte`
|
|
- `ViewHeader.svelte`, `Card.svelte`, `CardGrid.svelte`
|
|
- `Button.svelte`, `Accordion.svelte`
|
|
- `icons.ts` — SVG icon strings (no icon library dep)
|
|
|
|
### Role-Based Auth (Jul 2026)
|
|
|
|
- Members have `role` field (`'parent' | 'child'`, added to `members` collection)
|
|
- Parents authenticate via email/password (PB session JWT), children via device token
|
|
- `/api/admin/signup` now creates a member record for the parent with `role: 'parent'`
|
|
- `/api/admin/login` returns `memberName`, `memberColor`, `role` alongside session info
|
|
- `/api/members/verify-token` returns `role` for the frontend
|
|
- `requireAdmin` middleware unchanged (still checks `fam_admins`)
|
|
- Frontend sidebar is role-aware: `isParent = session !== null`
|
|
- **No more `/admin` prefix** — admin pages live under `/{fam}/{parent-username}/chores` etc.
|
|
|
|
### Routes (Jul 2026)
|
|
|
|
```
|
|
/ Landing (SaaS marketing)
|
|
/signup Signup (creates parent user + member)
|
|
/login Login (returns member info, redirects to /{fam}/{memberName})
|
|
/join/:code Member invite (child)
|
|
/join/:code/:member Member invite with pre-selected name
|
|
/admin Super admin dashboard (unchanged)
|
|
/{fam} Fam dashboard
|
|
/{fam}/{username} Parent → admin overview, Child → kanban
|
|
/{fam}/{username}/chores Parent: chore management
|
|
/{fam}/{username}/rewards Parent: reward ledger
|
|
/{fam}/{username}/bonuses Parent: bonus configs
|
|
/{fam}/{username}/settings Parent: family settings
|
|
/{fam}/{username}/preferences Both: edit name/color
|
|
/api/* Hono proxy
|
|
```
|
|
|
|
### Architecture Decisions
|
|
|
|
### 2026-06-23 — Monorepo & Docker Setup
|
|
|
|
- **Ports**: Frontend = `2080`, Proxy = `3456`, Container ext = `3001`. Port `3000` reserved/conflict.
|
|
- **Shared config**: `config.ts` at root for dev/build-time values (e.g. `PROXY_PORT`). Runtime config via env vars. `.env` tracks ports, `.env.example` committed.
|
|
- **Docker**: 2 Dockerfiles — `Dockerfile` (prod, multi-stage with nginx) and `Dockerfile.dev` (PocketBase for dev).
|
|
- **Nginx**: Prod container uses nginx to route `/api/*` → Hono (`:3456`), `/*` → SvelteKit (`:2080`).
|
|
- **Dev workflow**: `pnpm dev` at root runs SvelteKit + Hono in parallel. PocketBase via `Dockerfile.dev`.
|
|
- **Proxy runtime**: Uses `process.env.PROXY_PORT` instead of importing `config.ts` (avoids `rootDir` issues in `tsc`).
|
|
|
|
### 2026-06-23 — Hono Proxy for All Data; Svelte Reactivity Only
|
|
|
|
- **All data operations** (reads and writes) go through the Hono proxy, never directly to PB SDK.
|
|
- **UI reactivity** is purely Svelte `$state` / `$derived` / `$effect` — no PB SDK `.subscribe()` / SSE.
|
|
- The `/debug` page's PB SDK `subscribe()` was experimental only; final apps fetch via Hono proxy and update Svelte state reactively.
|
|
|
|
### 2026-07-28 — Auth Bug: Join Flow Set Session Cookie for Children
|
|
|
|
- **Bug**: Both `join/[code]/+page.server.ts` and `join/[code]/[member]/+page.server.ts` called `setSessionCookie()` with `userId: memberId` (the child's PB record ID). This made `event.locals.session` truthy for children, causing `[username]/+page.server.ts` to enter the admin branch and call `hono.admin.*` endpoints. The proxy's `requireAdmin` checked `fam_admins` for the child's member ID (which doesn't exist) and returned 401.
|
|
- **Fix**: Removed `setSessionCookie()` from both join pages. Children only get a `device_token` cookie. The session cookie is only for email/password-authenticated parents, set by `/login` and `/signup`.
|
|
- **Lesson**: Children must never get a session cookie. The auth table in AGENTS.md says "Member → device token, no expiry" — the code must match.
|
|
|
|
### 2026-08-03 — Family Timezone Setting + Tz-Aware Week Math
|
|
|
|
- **Feature**: `fams.timezone` (IANA name or `"auto"`) added via `migrate.ts` 5d/5e (field + backfill `"auto"`). Exposed in settings Payday card (dropdown from `COMMON_TIMEZONES`, ~40 entries, + "Auto (detected)"). Set via `PATCH /api/admin/:famId/fam` alongside payday/paydayTime.
|
|
- **Shared module** `timezone.ts` (root, imported by both proxy and frontend): `resolveTz`, `dateStrInTz`, `weekdayInTz`, `todayInTz`, `addDaysStr` (pure UTC), `weekStart(payday, tz)`, `wallClockToUtc` (iterative 4-pass Intl, DST-safe), `COMMON_TIMEZONES`.
|
|
- **Bug fixed** ("5 days left on Monday"): old `mondayOf`/`addDays`/`daysLeft` used local `setDate` + `toISOString()`. On BST Sunday Aug 9 local midnight → UTC Aug 8, so Monday showed 5 days left instead of 6. Now the child page computes `weekStart`/`todayIso`/`daysLeft` via `weekStart(1, famTz)` + `addDaysStr` + `todayInTz`, giving 6. Verified: Mon Aug 3 → weekStart 2026-08-03, weekEnd 2026-08-09, daysLeft 6.
|
|
- **releaseWeek time gate**: now tz-aware. `weekStart(payday, tz)` for idempotency check; `target = new Date(wallClockToUtc(weekStartToday, paydayTime, tz))`. Verified: payday Mon 20:00 Europe/London (BST) → target `2026-08-03T19:00:00Z`; `auto` resolves to server tz. Returns `{settled:false, notYet:true, weekStart, target}` before the time.
|
|
- **Proxy threads `tz`** through weekly-summary, eow-preview, bonus-configs/progress, `evaluateFam`, tallies, manual trigger, complete-week, `releaseWeek`. `my-chores` returns `timezone`; child `+page.server.ts` passes it to `data.timezone`; parent passes `data.fam.timezone`.
|
|
- **Frontend child page**: `rawFamTz = data.timezone || data.fam?.timezone || 'auto'`, `famTz = resolveTz(rawFamTz)`. `todayChild`, `todayIso`, `mondayOf`, `addDays`, `isPaydayToday` (via `weekdayInTz`), `paydayTarget` (via `wallClockToUtc`), `today` all tz-aware. `mondayOf` now delegates to `tzWeekStart(1, famTz)`.
|
|
- **Smoke-tested live** (fam `v56f0f8o147kj1x`): GET fam returns timezone, PATCH sets Europe/London, time-gate returns correct target, `auto` resolves to server tz, settings page SSR shows the dropdown, child page 200. Fam restored to payday=0, paydayTime=18:00, timezone=auto, lastIssued=2026-08-02.
|
|
- **Typecheck**: proxy `tsc --noEmit` 28 errors (all pre-existing rootDir/`.ts`-import/`key: never`/implicit-any baseline); frontend `svelte-check` 9 errors (baseline; no new errors in edited files).
|
|
|
|
### 2026-08-04 — Terminology: "Payday" + Countdown to Settlement Day
|
|
|
|
- **Decision**: Standardize the user-facing term on **"payday"** for the weekly settlement event/day. "EOW" is ambiguous (window-close vs settlement day) and is now dropped from user-facing strings. Keep "week" for the Sun→Sat earning window. Internal identifiers (`eow*`, `simulateEow`, `eowPreview`, CSS `eow-*`) left as-is.
|
|
- **daysLeft now counts to settlement day**: `daysLeft` on the child dashboard counts to `weekStart + 7` (the next payday day) instead of `weekEnd = weekStart + 6`. So Tue Aug 4 with payday=Sun shows 5 days until payday. Hero label updated to "days until payday".
|
|
- **User-facing renames**: hero `days left` → `days until payday`; debug card `Simulate End-of-Week` → `Simulate Payday`; error `Failed to preview EOW` → `Failed to preview payday`; settings hint reworded to lead with "Payday:".
|
|
|