Spaces:
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
- Spec wins. Small slices F0→F8.
- Mobile-first iPhone Safari PWA; desktop acceptable, not primary.
- Stack: Vite + Preact + Motion (
motion) + plain CSS variables. No heavy component library. credentials: 'include'on all API calls;401→ login.- SW: shell only;
/api/*network-only — never cache API. - Time-to-first-log < 20s after login.
- Coach: show SERVER_PICKS + badge Rules | Model (not “AI failed”).
- Discrete copy only (“Habit Journal”).
- Apple motion rules are mandatory for sheets, nav, presses, toasts.
- Respect
prefers-reduced-motion,prefers-reduced-transparency,prefers-contrast. - Prototype interactions in code; no static-only “design phase.”
- Do not block Log on Coach.
- Deploy engine first if not already: backend on Space with
/databefore 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)
- Feedback on pointer-down, not click-up.
- 1:1 drag with pointer capture.
- Interruptible springs; velocity handoff; project momentum; rubber-band.
- Springs for touchable UI; CSS only for trivial color/opacity.
- 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-motionrespected 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