# gernotfound/logbook architecture

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

- Interactive diagram: https://gitdiagram.com/gernotfound/logbook
- Repository: https://github.com/gernotfound/logbook

## Overview

TheLogBook is an offline-first PWA for workout training, nutrition, and body-composition tracking. Users record and review those domains in the app; changes are persisted locally first and, for authenticated accounts, replicated to Firestore. The graph also preserves the documented catalog, backup/export, PWA, analytics, and account-deletion capabilities. Several subsystem links are supported only by the README or source-index references; unsampled implementation details are not inferred.

Main entry points: [`src/App.tsx`](https://github.com/gernotfound/logbook/blob/main/src/App.tsx) (App shell), [`src/store/useAppStore.ts`](https://github.com/gernotfound/logbook/blob/main/src/store/useAppStore.ts) (App state), [`src/contexts/AuthContext.tsx`](https://github.com/gernotfound/logbook/blob/main/src/contexts/AuthContext.tsx) (Authentication), [`src/lib/sync/localRepository.ts`](https://github.com/gernotfound/logbook/blob/main/src/lib/sync/localRepository.ts) (Local repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["App experience"]
  node_app["App shell<br/>[App.tsx]"]
  node_auth["Authentication<br/>[AuthContext.tsx]"]
end

subgraph group_domains["Health domains"]
  node_training["Training"]
  node_nutrition["Nutrition"]
  node_bodydata["Body data"]
  node_analytics["Progress analytics"]
  node_catalog["Exercise and food catalog<br/>[catalogService.ts]"]
  node_backup["Backup and export<br/>[backup.ts]"]
end

subgraph group_sync["Offline-first data"]
  node_appstate["App state<br/>[useAppStore.ts]"]
  node_operations["Domain operations"]
  node_repository["Local repository<br/>[localRepository.ts]"]
  node_localstore[("Local persistence<br/>[db.ts]")]
  node_syncsession["Sync session<br/>[session.ts]"]
end

subgraph group_services["Account and services"]
  node_firestore[("Cloud replica<br/>[firebase.ts]")]
  node_accountdelete["Account deletion"]
  node_deletionapi["Deletion API"]
end

subgraph group_operations["PWA and insights"]
  node_pwa["Service worker<br/>[sw.ts]"]
  node_reload["Safe update barrier<br/>[safeReload.ts]"]
  node_telemetry["Technical telemetry<br/>[telemetryHub.ts]"]
  node_ga["Opt-in analytics<br/>[googleAnalytics.ts]"]
end

node_user(("User"))
node_firebaseauth["Firebase services"]

node_user -->|"uses"| node_app
node_app -->|"opens"| node_training
node_app -->|"uses"| node_auth
node_user -->|"records meals"| node_nutrition
node_user -->|"records measures"| node_bodydata
node_user -->|"reviews progress"| node_analytics
node_training -.->|"updates state"| node_appstate
node_nutrition -.->|"updates state"| node_appstate
node_bodydata -.->|"updates state"| node_appstate
node_analytics -.->|"reads state"| node_appstate
node_training -.->|"uses exercises"| node_catalog
node_nutrition -.->|"uses foods"| node_catalog
node_auth -->|"loads catalog"| node_catalog
node_appstate -.->|"dispatches mutations"| node_operations
node_operations -->|"compiles and applies"| node_repository
node_repository -->|"persists envelope"| node_localstore
node_repository -->|"reads cached catalog"| node_catalog
node_auth -->|"hydrates account data"| node_repository
node_auth -->|"establishes sync"| node_syncsession
node_syncsession -->|"replicates data"| node_firestore
node_firestore -->|"uses Firebase"| node_firebaseauth
node_user -->|"exports or imports"| node_backup
node_user -->|"requests deletion"| node_deletionapi
node_deletionapi -.->|"routes request"| node_accountdelete
node_accountdelete -->|"uses Firebase Admin"| node_firebaseauth
node_app -->|"runs as PWA"| node_pwa
node_app -->|"guards update reload"| node_reload
node_app -.->|"reports technical issues"| node_telemetry
node_user -->|"opts in"| node_ga

click node_app "https://github.com/gernotfound/logbook/blob/main/src/App.tsx"
click node_auth "https://github.com/gernotfound/logbook/blob/main/src/contexts/AuthContext.tsx"
click node_training "https://github.com/gernotfound/logbook/tree/main/src/components/Training"
click node_nutrition "https://github.com/gernotfound/logbook/tree/main/src/components/Nutrition"
click node_bodydata "https://github.com/gernotfound/logbook/tree/main/src/components/Data"
click node_analytics "https://github.com/gernotfound/logbook/tree/main/src/components/analytics"
click node_catalog "https://github.com/gernotfound/logbook/blob/main/src/lib/catalog/catalogService.ts"
click node_backup "https://github.com/gernotfound/logbook/blob/main/src/lib/backup.ts"
click node_appstate "https://github.com/gernotfound/logbook/blob/main/src/store/useAppStore.ts"
click node_operations "https://github.com/gernotfound/logbook/tree/main/src/lib/sync/domainOperations"
click node_repository "https://github.com/gernotfound/logbook/blob/main/src/lib/sync/localRepository.ts"
click node_localstore "https://github.com/gernotfound/logbook/blob/main/src/lib/db.ts"
click node_syncsession "https://github.com/gernotfound/logbook/blob/main/src/lib/sync/session.ts"
click node_firestore "https://github.com/gernotfound/logbook/blob/main/src/lib/firebase.ts"
click node_accountdelete "https://github.com/gernotfound/logbook/tree/main/server/accountDeletion"
click node_deletionapi "https://github.com/gernotfound/logbook/blob/main/api/account-deletion.ts"
click node_pwa "https://github.com/gernotfound/logbook/blob/main/src/sw.ts"
click node_reload "https://github.com/gernotfound/logbook/blob/main/src/lib/sync/safeReload.ts"
click node_telemetry "https://github.com/gernotfound/logbook/blob/main/src/lib/telemetryHub.ts"
click node_ga "https://github.com/gernotfound/logbook/blob/main/src/lib/googleAnalytics.ts"

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_app,node_auth,node_user toneBlue
class node_training,node_nutrition,node_bodydata,node_analytics,node_catalog,node_backup toneAmber
class node_appstate,node_operations,node_repository,node_localstore,node_syncsession toneMint
class node_firestore,node_accountdelete,node_deletionapi toneRose
class node_pwa,node_reload,node_telemetry,node_ga,node_firebaseauth toneIndigo
```

## Components

### App experience

- [App shell](https://github.com/gernotfound/logbook/blob/main/src/App.tsx): `src/App.tsx`
- [Authentication](https://github.com/gernotfound/logbook/blob/main/src/contexts/AuthContext.tsx): `src/contexts/AuthContext.tsx`

### Health domains

- [Training](https://github.com/gernotfound/logbook/tree/main/src/components/Training): `src/components/Training`
- [Nutrition](https://github.com/gernotfound/logbook/tree/main/src/components/Nutrition): `src/components/Nutrition`
- [Body data](https://github.com/gernotfound/logbook/tree/main/src/components/Data): `src/components/Data`
- [Progress analytics](https://github.com/gernotfound/logbook/tree/main/src/components/analytics): `src/components/analytics`
- [Exercise and food catalog](https://github.com/gernotfound/logbook/blob/main/src/lib/catalog/catalogService.ts): `src/lib/catalog/catalogService.ts`
- [Backup and export](https://github.com/gernotfound/logbook/blob/main/src/lib/backup.ts): `src/lib/backup.ts`

### Offline-first data

- [App state](https://github.com/gernotfound/logbook/blob/main/src/store/useAppStore.ts): `src/store/useAppStore.ts`
- [Domain operations](https://github.com/gernotfound/logbook/tree/main/src/lib/sync/domainOperations): `src/lib/sync/domainOperations`
- [Local repository](https://github.com/gernotfound/logbook/blob/main/src/lib/sync/localRepository.ts): `src/lib/sync/localRepository.ts`
- [Local persistence](https://github.com/gernotfound/logbook/blob/main/src/lib/db.ts): `src/lib/db.ts`
- [Sync session](https://github.com/gernotfound/logbook/blob/main/src/lib/sync/session.ts): `src/lib/sync/session.ts`

### Account and services

- [Cloud replica](https://github.com/gernotfound/logbook/blob/main/src/lib/firebase.ts): `src/lib/firebase.ts`
- [Account deletion](https://github.com/gernotfound/logbook/tree/main/server/accountDeletion): `server/accountDeletion`
- [Deletion API](https://github.com/gernotfound/logbook/blob/main/api/account-deletion.ts): `api/account-deletion.ts`

### PWA and insights

- [Service worker](https://github.com/gernotfound/logbook/blob/main/src/sw.ts): `src/sw.ts`
- [Safe update barrier](https://github.com/gernotfound/logbook/blob/main/src/lib/sync/safeReload.ts): `src/lib/sync/safeReload.ts`
- [Technical telemetry](https://github.com/gernotfound/logbook/blob/main/src/lib/telemetryHub.ts): `src/lib/telemetryHub.ts`
- [Opt-in analytics](https://github.com/gernotfound/logbook/blob/main/src/lib/googleAnalytics.ts): `src/lib/googleAnalytics.ts`

### Other components

- **User**
- **Firebase services**

## Connections

- User → App shell: uses (evidence: `README.md`)
- App shell → Training: opens (evidence: `src/App.tsx`)
- App shell → Authentication: uses (evidence: `src/App.tsx`)
- User → Nutrition: records meals (evidence: `README.md`)
- User → Body data: records measures (evidence: `README.md`)
- User → Progress analytics: reviews progress (evidence: `README.md`)
- Training → App state: updates state
- Nutrition → App state: updates state
- Body data → App state: updates state
- Progress analytics → App state: reads state
- Training → Exercise and food catalog: uses exercises
- Nutrition → Exercise and food catalog: uses foods
- Authentication → Exercise and food catalog: loads catalog (evidence: `src/contexts/AuthContext.tsx`)
- App state → Domain operations: dispatches mutations
- Domain operations → Local repository: compiles and applies (evidence: `src/lib/sync/localRepository.ts`)
- Local repository → Local persistence: persists envelope (evidence: `README.md`)
- Local repository → Exercise and food catalog: reads cached catalog (evidence: `src/lib/sync/localRepository.ts`)
- Authentication → Local repository: hydrates account data (evidence: `src/contexts/AuthContext.tsx`)
- Authentication → Sync session: establishes sync (evidence: `src/contexts/AuthContext.tsx`)
- Sync session → Cloud replica: replicates data (evidence: `README.md`)
- Cloud replica → Firebase services: uses Firebase (evidence: `src/lib/firebase.ts`)
- User → Backup and export: exports or imports (evidence: `README.md`)
- User → Deletion API: requests deletion (evidence: `README.md`)
- Deletion API → Account deletion: routes request
- Account deletion → Firebase services: uses Firebase Admin (evidence: `README.md`)
- App shell → Service worker: runs as PWA (evidence: `README.md`)
- App shell → Safe update barrier: guards update reload (evidence: `src/App.tsx`)
- App shell → Technical telemetry: reports technical issues
- User → Opt-in analytics: opts in (evidence: `README.md`)
