Spaces:
Sleeping
Sleeping
| # Frontend Design Document v2 | |
| ## Habit Journal PWA β Apple-fluid UI + existing API | |
| **Depends on:** Backend live on HF (`docs/BACKEND.md` v2). No new backend features unless blocked. | |
| **Version:** 2.0 | |
| **Scope:** Mobile-first iPhone Safari PWA consuming the Habit Journal API. | |
| --- | |
| ## 0. Composer instructions | |
| 1. Spec wins. Small slices **F0βF8**. | |
| 2. **Mobile-first iPhone Safari PWA**; desktop acceptable, not primary. | |
| 3. Stack: **Vite + Preact + Motion (`motion`)** + plain CSS variables. No heavy component library. | |
| 4. `credentials: 'include'` on all API calls; `401` β login. | |
| 5. SW: **shell only**; **`/api/*` network-only** β never cache API. | |
| 6. Time-to-first-log **< 20s** after login. | |
| 7. Coach: show **SERVER_PICKS** + badge **Rules** | **Model** (not βAI failedβ). | |
| 8. Discrete copy only (βHabit Journalβ). | |
| 9. **Apple motion rules are mandatory** for sheets, nav, presses, toasts. | |
| 10. Respect `prefers-reduced-motion`, `prefers-reduced-transparency`, `prefers-contrast`. | |
| 11. Prototype interactions in code; no static-only βdesign phase.β | |
| 12. Do not block Log on Coach. | |
| 13. Deploy engine first if not already: backend on Space with `/data` before polishing pixels. | |
| --- | |
| ## 1. Product principles | |
| | Apple need | Habit Journal meaning | | |
| |------------|------------------------| | |
| | Safety / predictability | Same controls same place; undo-friendly edits; confirm only on delete | | |
| | Understanding | Every screen: where am I, what next, how out | | |
| | Achievement | One Primary brick / one log feels complete | | |
| | Joy | Calm confidence from craft β not gamification spam | | |
| **Refuse:** social feed, public profiles, coach that replaces tapping **Result**. | |
| **Agency:** User owns `result`. Model suggests; Rules backup never shames. | |
| --- | |
| ## 2. Stack | |
| ``` | |
| frontend/ | |
| package.json | |
| index.html | |
| src/ | |
| main.tsx | |
| api.ts | |
| router.tsx | |
| styles/ tokens.css, reset.css, materials.css | |
| motion/ springs.ts, gestures.ts | |
| components/ Button, Pressable, Toast, β¦ | |
| pages/ Login, Home, Log, β¦ | |
| pwa/ (F8) | |
| dist/ β FastAPI static/ | |
| ``` | |
| --- | |
| ## 3. Routes | |
| | Route | Page | Role | | |
| |-------|------|------| | |
| | `#/login` | Login | Password | | |
| | `#/` | Home | Today + CTA | | |
| | `#/log` | Log | Fast create | | |
| | `#/history` | History | List/filter | | |
| | `#/entry/:id` | Entry | Detail / edit / coach | | |
| | `#/daily` | Daily | Scoreboard | | |
| | `#/stats` | Stats | Server probs | | |
| | `#/coach` | Coach | Suggest + picks | | |
| | `#/remedies` | Remedies | Leaderboard | | |
| | `#/settings` | Settings | Export, install, logout | | |
| **Tab bar (F2+):** Home Β· Log Β· Daily Β· Stats Β· Coach | |
| **Overflow:** History Β· Remedies Β· Settings Β· Logout | |
| --- | |
| ## 4. Design tokens | |
| Dark-first system tokens (`--bg`, `--accent`, materials with blur). | |
| Min tap **44Γ44px**. Screen padding **16β20px**. Card radius **12β16px**. | |
| `prefers-reduced-transparency` β solid surfaces, no blur. | |
| `prefers-contrast: more` β stronger borders. | |
| --- | |
| ## 5. Motion (mandatory) | |
| 1. Feedback on **pointer-down**, not click-up. | |
| 2. 1:1 drag with pointer capture. | |
| 3. Interruptible springs; velocity handoff; project momentum; rubber-band. | |
| 4. Springs for touchable UI; CSS only for trivial color/opacity. | |
| 5. Tab switches: cross-fade; stack: short horizontal spring; reduced-motion β opacity only. | |
| Spring presets: `ui`, `snap`, `flick`, `sheet`, `press`. | |
| Gestures: `project()`, `rubberband()`, velocity samples. | |
| --- | |
| ## 6β7. Components & screens | |
| **F0βF1 required:** Login, me gate, Pressable/Button, Log (happened, emotions, intensity, result, remedy, Save), Toast. | |
| Home may be a minimal CTA shell until F2 TabBar. | |
| Later: History, Entry, Daily, Stats, Coach, Remedies, Settings, Sheet, PWA. | |
| **Log goal:** <20s to save. Secondary fields (activity, tags, notes) collapsed under More. | |
| **Coach badge map:** `backup` / `model_unparsed_fallback` β Rules; `model` β Model. | |
| --- | |
| ## 8. API wrapper | |
| `fetch` with `credentials: 'include'`; `401` β `#/login`; envelope `{ok, data, error}`. | |
| --- | |
| ## 9. PWA (F8) | |
| Manifest + SW shell cache; **never** cache `/api/*`. | |
| Apple meta: capable, black-translucent, viewport-fit=cover. | |
| --- | |
| ## 10β11. Feedback & a11y | |
| Toast for save/copy/error. Focus rings, labels, result chip text (not color alone). | |
| Reduced motion / transparency / contrast wired in components. | |
| --- | |
| ## 12. Implementation slices | |
| | Slice | Deliverable | | |
| |-------|-------------| | |
| | **F0** | Vite+Preact, tokens, materials, router, api, Login, me gate | | |
| | **F1** | Pressable/Button, Log page, save, toast | | |
| | **F2** | Home + TabBar material + safe areas | | |
| | **F3** | History + Entry edit/delete | | |
| | **F4** | Daily | | |
| | **F5** | Stats + Remedies | | |
| | **F6** | Coach + ServerPicks + Badge + copy debug | | |
| | **F7** | Sheet gestures, More menu | | |
| | **F8** | PWA + Settings install + reduced-motion pass | | |
| --- | |
| ## 13. Acceptance (F0βF1 subset) | |
| - [ ] Login cookie works; unauth β login | |
| - [ ] Log entry saves via API; toast on success | |
| - [ ] Buttons react on **press** | |
| - [ ] `prefers-reduced-motion` respected on press/toast | |
| - [ ] FastAPI serves frontend without breaking `/api` | |
| --- | |
| ## 14. Anti-patterns | |
| No press-on-click-only; no API caching in SW; no blocking Log on Coach; no pep-talk empty states. | |
| --- | |
| ## 16. Mental model | |
| ``` | |
| Apple: response β direct manipulation β interruptible springs β materials β type | |
| App: fast Log β honest Result β server math visible β coach optional β debug paste | |
| ``` | |