# xander-coetzee/whooshcoach architecture

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

- Interactive diagram: https://gitdiagram.com/xander-coetzee/whooshcoach
- Repository: https://github.com/xander-coetzee/whooshcoach

## Overview

WhooshCoach is a self-hosted cycling-coaching app: athletes use its calendar and settings UI, the API stores ride and training data, and the coach combines deterministic load/readiness calculations with Gemini to generate and adapt plans. The calendar also tracks races, rest days, and protected manual events; background sync imports completed rides from MyWhoosh and Zwift. The README documents these capabilities, while source excerpts confirm selected call paths. Some API, scheduler-startup, and external-service details are not fully shown, so uncertain connections are omitted.

Main entry points: [`app/main.py`](https://github.com/xander-coetzee/whooshcoach/blob/main/app/main.py) (HTTP API), [`app/gemini_coach.py`](https://github.com/xander-coetzee/whooshcoach/blob/main/app/gemini_coach.py) (AI plan generation), [`app/database.py`](https://github.com/xander-coetzee/whooshcoach/blob/main/app/database.py) (SQLite training store), [`app/scheduler.py`](https://github.com/xander-coetzee/whooshcoach/blob/main/app/scheduler.py) (Periodic sync scheduler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Athlete experience"]
  node_browser["Web calendar UI<br/>[app.js]"]
end

subgraph group_api["Application API"]
  node_api_server["HTTP API<br/>[main.py]"]
  node_calendar["Calendar and race events<br/>[main.py]"]
end

subgraph group_coaching["Coaching engine"]
  node_context["Athlete context<br/>[context_engine.py]"]
  node_load["Load and readiness<br/>[physiology.py]"]
  node_plan["AI plan generation<br/>[gemini_coach.py]"]
  node_adaptation["Post-ride adaptation<br/>[gemini_coach.py]"]
end

subgraph group_sync["Ride synchronization"]
  node_scheduler["Periodic sync scheduler<br/>[scheduler.py]"]
  node_mywhoosh_sync["MyWhoosh ride sync"]
  node_zwift_sync["Zwift ride sync<br/>[zwift_service.py]"]
end

subgraph group_state["Training data"]
  node_catalog["Workout catalog<br/>[database.py]"]
  node_db[("SQLite training store<br/>[database.py]")]
end

node_athlete(("Athlete"))
node_mywhoosh["MyWhoosh cloud"]
node_zwift["Zwift cloud"]
node_gemini["Gemini model"]

node_athlete -->|"uses"| node_browser
node_browser -->|"requests"| node_api_server
node_api_server -->|"routes events"| node_calendar
node_api_server -.->|"reads and writes"| node_db
node_api_server -->|"requests plans"| node_plan
node_api_server -->|"uses"| node_context
node_api_server -->|"uses"| node_load
node_api_server -.->|"starts"| node_scheduler
node_context -->|"reads"| node_db
node_context -->|"calculates metrics"| node_load
node_plan -->|"builds context"| node_context
node_plan -->|"uses metrics"| node_load
node_plan -.->|"reads and writes"| node_db
node_plan -->|"resolves workouts"| node_catalog
node_plan -.->|"requests plan"| node_gemini
node_adaptation -.->|"requests adjustment"| node_gemini
node_scheduler -->|"loads athletes"| node_db
node_scheduler -->|"dispatches sync"| node_mywhoosh_sync
node_scheduler -->|"dispatches sync"| node_zwift_sync
node_mywhoosh_sync -->|"fetches activities"| node_mywhoosh
node_mywhoosh_sync -.->|"stores rides"| node_db
node_zwift_sync -->|"fetches activities"| node_zwift
node_zwift_sync -->|"stores rides"| node_db
node_mywhoosh_sync -.->|"requests adaptation"| node_adaptation
node_zwift_sync -->|"requests adaptation"| node_adaptation
node_calendar -.->|"stores events"| node_db

click node_browser "https://github.com/xander-coetzee/whooshcoach/blob/main/app/static/app.js"
click node_api_server "https://github.com/xander-coetzee/whooshcoach/blob/main/app/main.py"
click node_calendar "https://github.com/xander-coetzee/whooshcoach/blob/main/app/main.py"
click node_scheduler "https://github.com/xander-coetzee/whooshcoach/blob/main/app/scheduler.py"
click node_context "https://github.com/xander-coetzee/whooshcoach/blob/main/app/context_engine.py"
click node_load "https://github.com/xander-coetzee/whooshcoach/blob/main/app/physiology.py"
click node_plan "https://github.com/xander-coetzee/whooshcoach/blob/main/app/gemini_coach.py"
click node_adaptation "https://github.com/xander-coetzee/whooshcoach/blob/main/app/gemini_coach.py"
click node_catalog "https://github.com/xander-coetzee/whooshcoach/blob/main/app/database.py"
click node_db "https://github.com/xander-coetzee/whooshcoach/blob/main/app/database.py"
click node_mywhoosh_sync "https://github.com/xander-coetzee/whooshcoach/blob/main/app/mywhoosh_service.py"
click node_zwift_sync "https://github.com/xander-coetzee/whooshcoach/blob/main/app/zwift_service.py"

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_browser toneBlue
class node_api_server,node_calendar toneAmber
class node_context,node_load,node_plan,node_adaptation toneMint
class node_scheduler,node_mywhoosh_sync,node_zwift_sync toneRose
class node_catalog,node_db,node_athlete,node_mywhoosh,node_zwift,node_gemini toneIndigo
```

## Components

### Athlete experience

- [Web calendar UI](https://github.com/xander-coetzee/whooshcoach/blob/main/app/static/app.js): `app/static/app.js`

### Application API

- [HTTP API](https://github.com/xander-coetzee/whooshcoach/blob/main/app/main.py): `app/main.py`
- [Calendar and race events](https://github.com/xander-coetzee/whooshcoach/blob/main/app/main.py): `app/main.py`

### Coaching engine

- [Athlete context](https://github.com/xander-coetzee/whooshcoach/blob/main/app/context_engine.py): `app/context_engine.py`
- [Load and readiness](https://github.com/xander-coetzee/whooshcoach/blob/main/app/physiology.py): `app/physiology.py`
- [AI plan generation](https://github.com/xander-coetzee/whooshcoach/blob/main/app/gemini_coach.py): `app/gemini_coach.py`
- [Post-ride adaptation](https://github.com/xander-coetzee/whooshcoach/blob/main/app/gemini_coach.py): `app/gemini_coach.py`

### Ride synchronization

- [Periodic sync scheduler](https://github.com/xander-coetzee/whooshcoach/blob/main/app/scheduler.py): `app/scheduler.py`
- [MyWhoosh ride sync](https://github.com/xander-coetzee/whooshcoach/blob/main/app/mywhoosh_service.py): `app/mywhoosh_service.py`
- [Zwift ride sync](https://github.com/xander-coetzee/whooshcoach/blob/main/app/zwift_service.py): `app/zwift_service.py`

### Training data

- [Workout catalog](https://github.com/xander-coetzee/whooshcoach/blob/main/app/database.py): `app/database.py`
- [SQLite training store](https://github.com/xander-coetzee/whooshcoach/blob/main/app/database.py): `app/database.py`

### Other components

- **Athlete**
- **MyWhoosh cloud**
- **Zwift cloud**
- **Gemini model**

## Connections

- Athlete → Web calendar UI: uses (evidence: `README.md`)
- Web calendar UI → HTTP API: requests (evidence: `app/static/app.js`)
- HTTP API → Calendar and race events: routes events (evidence: `app/main.py`)
- HTTP API → SQLite training store: reads and writes (evidence: `app/main.py`)
- HTTP API → AI plan generation: requests plans (evidence: `app/main.py`)
- HTTP API → Athlete context: uses (evidence: `app/main.py`)
- HTTP API → Load and readiness: uses (evidence: `app/main.py`)
- HTTP API → Periodic sync scheduler: starts (evidence: `app/main.py`)
- Athlete context → SQLite training store: reads (evidence: `app/context_engine.py`)
- Athlete context → Load and readiness: calculates metrics (evidence: `app/context_engine.py`)
- AI plan generation → Athlete context: builds context (evidence: `app/gemini_coach.py`)
- AI plan generation → Load and readiness: uses metrics (evidence: `app/gemini_coach.py`)
- AI plan generation → SQLite training store: reads and writes (evidence: `app/gemini_coach.py`)
- AI plan generation → Workout catalog: resolves workouts (evidence: `app/gemini_coach.py`)
- AI plan generation → Gemini model: requests plan
- Post-ride adaptation → Gemini model: requests adjustment
- Periodic sync scheduler → SQLite training store: loads athletes (evidence: `app/scheduler.py`)
- Periodic sync scheduler → MyWhoosh ride sync: dispatches sync (evidence: `app/scheduler.py`)
- Periodic sync scheduler → Zwift ride sync: dispatches sync (evidence: `app/scheduler.py`)
- MyWhoosh ride sync → MyWhoosh cloud: fetches activities (evidence: `app/mywhoosh_service.py`)
- MyWhoosh ride sync → SQLite training store: stores rides (evidence: `app/mywhoosh_service.py`)
- Zwift ride sync → Zwift cloud: fetches activities (evidence: `app/zwift_service.py`)
- Zwift ride sync → SQLite training store: stores rides (evidence: `app/zwift_service.py`)
- MyWhoosh ride sync → Post-ride adaptation: requests adaptation (evidence: `app/mywhoosh_service.py`)
- Zwift ride sync → Post-ride adaptation: requests adaptation (evidence: `app/zwift_service.py`)
- Calendar and race events → SQLite training store: stores events (evidence: `app/main.py`)
