# parthapatel114-rgb/caflife architecture

> Architecture diagram of the GitHub repository parthapatel114-rgb/caflife, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/parthapatel114-rgb/caflife
- Repository: https://github.com/parthapatel114-rgb/caflife

## Overview

CafLife is a caffeine journal and planner: users record drinks and preferences, inspect estimated caffeine levels and history, and can save data locally or sync it with Supabase after signing in. The tracker is the main UI; its hook coordinates authentication and changes, while the store handles browser persistence and remote synchronization. The README also documents saved drinks, backups, and offline support. Some feature internals are unsampled, so those capabilities are represented at the tracker level rather than as inferred modules.

Main entry points: [`components/tracker.tsx`](https://github.com/parthapatel114-rgb/caflife/blob/main/components/tracker.tsx) (Journal and planner), [`components/profile-form.tsx`](https://github.com/parthapatel114-rgb/caflife/blob/main/components/profile-form.tsx) (Preferences form), [`lib/store.ts`](https://github.com/parthapatel114-rgb/caflife/blob/main/lib/store.ts) (Storage and sync), [`lib/model.ts`](https://github.com/parthapatel114-rgb/caflife/blob/main/lib/model.ts) (Caffeine model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Journal experience"]
  node_tracker["Journal and planner<br/>[tracker.tsx]"]
  node_profile["Preferences form<br/>[profile-form.tsx]"]
  node_fields["Form fields<br/>[fields.tsx]"]
  node_curve["Caffeine curve<br/>[curve.tsx]"]
  node_ui["UI primitives<br/>[button.tsx]"]
end

subgraph group_domain["Caffeine domain"]
  node_model["Caffeine model<br/>[model.ts]"]
end

subgraph group_persistence["Data and sync"]
  node_hook["Tracker state and auth<br/>[use-tracker.ts]"]
  node_store["Storage and sync<br/>[store.ts]"]
  node_indexeddb[("Browser IndexedDB")]
  node_supabase[("Supabase service")]
  node_schema["Database schema and policies<br/>[001_caffeine.sql]"]
end

subgraph group_platform["App platform"]
  node_page["App entry page<br/>[page.tsx]"]
  node_config["Public config endpoint<br/>[route.ts]"]
  node_serviceworker["Offline cache<br/>[sw.js]"]
end

node_user(("Journal user"))

node_user -->|"opens app"| node_page
node_page -->|"renders"| node_tracker
node_tracker -->|"uses state"| node_hook
node_tracker -->|"renders"| node_curve
node_tracker -->|"renders"| node_profile
node_profile -->|"uses fields"| node_fields
node_profile -->|"validates with"| node_model
node_fields -->|"uses select"| node_ui
node_curve -->|"calculates with"| node_model
node_tracker -->|"calculates with"| node_model
node_hook -->|"coordinates"| node_store
node_store -->|"reads and writes"| node_indexeddb
node_store -->|"syncs records"| node_supabase
node_schema -->|"defines policies"| node_supabase
node_config -.->|"provides credentials"| node_supabase
node_serviceworker -.->|"supports offline use"| node_user

click node_page "https://github.com/parthapatel114-rgb/caflife/blob/main/app/page.tsx"
click node_config "https://github.com/parthapatel114-rgb/caflife/blob/main/app/api/config/route.ts"
click node_tracker "https://github.com/parthapatel114-rgb/caflife/blob/main/components/tracker.tsx"
click node_profile "https://github.com/parthapatel114-rgb/caflife/blob/main/components/profile-form.tsx"
click node_fields "https://github.com/parthapatel114-rgb/caflife/blob/main/components/fields.tsx"
click node_curve "https://github.com/parthapatel114-rgb/caflife/blob/main/components/curve.tsx"
click node_ui "https://github.com/parthapatel114-rgb/caflife/blob/main/components/ui/button.tsx"
click node_model "https://github.com/parthapatel114-rgb/caflife/blob/main/lib/model.ts"
click node_hook "https://github.com/parthapatel114-rgb/caflife/blob/main/hooks/use-tracker.ts"
click node_store "https://github.com/parthapatel114-rgb/caflife/blob/main/lib/store.ts"
click node_schema "https://github.com/parthapatel114-rgb/caflife/blob/main/supabase/migrations/001_caffeine.sql"
click node_serviceworker "https://github.com/parthapatel114-rgb/caflife/blob/main/public/sw.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_tracker,node_profile,node_fields,node_curve,node_ui,node_user toneBlue
class node_model toneAmber
class node_hook,node_store,node_indexeddb,node_supabase,node_schema toneMint
class node_page,node_config,node_serviceworker toneRose
```

## Components

### Journal experience

- [Journal and planner](https://github.com/parthapatel114-rgb/caflife/blob/main/components/tracker.tsx): `components/tracker.tsx`
- [Preferences form](https://github.com/parthapatel114-rgb/caflife/blob/main/components/profile-form.tsx): `components/profile-form.tsx`
- [Form fields](https://github.com/parthapatel114-rgb/caflife/blob/main/components/fields.tsx): `components/fields.tsx`
- [Caffeine curve](https://github.com/parthapatel114-rgb/caflife/blob/main/components/curve.tsx): `components/curve.tsx`
- [UI primitives](https://github.com/parthapatel114-rgb/caflife/blob/main/components/ui/button.tsx): `components/ui/button.tsx`

### Caffeine domain

- [Caffeine model](https://github.com/parthapatel114-rgb/caflife/blob/main/lib/model.ts): `lib/model.ts`

### Data and sync

- [Tracker state and auth](https://github.com/parthapatel114-rgb/caflife/blob/main/hooks/use-tracker.ts): `hooks/use-tracker.ts`
- [Storage and sync](https://github.com/parthapatel114-rgb/caflife/blob/main/lib/store.ts): `lib/store.ts`
- **Browser IndexedDB**
- **Supabase service**
- [Database schema and policies](https://github.com/parthapatel114-rgb/caflife/blob/main/supabase/migrations/001_caffeine.sql): `supabase/migrations/001_caffeine.sql`

### App platform

- [App entry page](https://github.com/parthapatel114-rgb/caflife/blob/main/app/page.tsx): `app/page.tsx`
- [Public config endpoint](https://github.com/parthapatel114-rgb/caflife/blob/main/app/api/config/route.ts): `app/api/config/route.ts`
- [Offline cache](https://github.com/parthapatel114-rgb/caflife/blob/main/public/sw.js): `public/sw.js`

### Other components

- **Journal user**

## Connections

- Journal user → App entry page: opens app (evidence: `README.md`)
- App entry page → Journal and planner: renders (evidence: `app/page.tsx`)
- Journal and planner → Tracker state and auth: uses state (evidence: `components/tracker.tsx`)
- Journal and planner → Caffeine curve: renders (evidence: `components/tracker.tsx`)
- Journal and planner → Preferences form: renders (evidence: `components/tracker.tsx`)
- Preferences form → Form fields: uses fields (evidence: `components/profile-form.tsx`)
- Preferences form → Caffeine model: validates with (evidence: `components/profile-form.tsx`)
- Form fields → UI primitives: uses select (evidence: `components/fields.tsx`)
- Caffeine curve → Caffeine model: calculates with (evidence: `components/curve.tsx`)
- Journal and planner → Caffeine model: calculates with (evidence: `components/tracker.tsx`)
- Tracker state and auth → Storage and sync: coordinates (evidence: `hooks/use-tracker.ts`)
- Storage and sync → Browser IndexedDB: reads and writes (evidence: `lib/store.ts`)
- Storage and sync → Supabase service: syncs records (evidence: `lib/store.ts`)
- Database schema and policies → Supabase service: defines policies (evidence: `README.md`)
- Public config endpoint → Supabase service: provides credentials
- Offline cache → Journal user: supports offline use (evidence: `README.md`)
