# czerw0/training-coach-ai architecture

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

- Interactive diagram: https://gitdiagram.com/czerw0/training-coach-ai
- Repository: https://github.com/czerw0/training-coach-ai

## Overview

ApexFit is a Django AI training coach: Garmin and weather data feed persistent athlete records; the web chat assembles a current snapshot, runs a tool-using coach, and stores recommendations and usage. Separate product paths cover sync ingestion, deterministic training-plan checks, calendar/activity/statistics views, and on-demand insights. Edges are limited to relationships shown in excerpts, the source index, or README; unsampled subsystem links are omitted where callers are not evidenced.

Main entry points: [`sync/models.py`](https://github.com/czerw0/training-coach-ai/blob/main/sync/models.py) (Fitness records), [`coach/tools.py`](https://github.com/czerw0/training-coach-ai/blob/main/coach/tools.py) (Agent tools), [`coach/models.py`](https://github.com/czerw0/training-coach-ai/blob/main/coach/models.py) (Coach records), [`coach/context.py`](https://github.com/czerw0/training-coach-ai/blob/main/coach/context.py) (Athlete context)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Data ingestion"]
  node_syncjobs["Garmin sync<br/>[sync_garmin.py]"]
  node_weatherfetch["Weather fetch<br/>[weather.py]"]
  node_syncrecords[("Fitness records<br/>[models.py]")]
  node_syncweather["Weather sync<br/>[sync_weather.py]"]
  node_librarysync["Exercise catalog sync<br/>[sync_exercises.py]"]
end

subgraph group_coach["Coaching engine"]
  node_context["Athlete context<br/>[context.py]"]
  node_agent["AI coach loop<br/>[agent.py]"]
  node_tools["Agent tools<br/>[tools.py]"]
  node_coachrecords[("Coach records<br/>[models.py]")]
end

subgraph group_planning["Training planning"]
  node_rules["Athlete rules<br/>[athlete_rules.py]"]
  node_traininglog["Completed training<br/>[training_log.py]"]
  node_skills["Training skills<br/>[training_skills.py]"]
  node_weekchecker["Week checker<br/>[check_week.py]"]
  node_planner["Planner skill files<br/>[frontmatter.py]"]
end

subgraph group_experience["Athlete experience"]
  node_web["Django web app<br/>[views.py]"]
  node_dashboard["Today dashboard<br/>[dashboard.py]"]
  node_activities["Activity detail<br/>[activity.py]"]
  node_stats["Training statistics<br/>[stats.py]"]
  node_insights["AI insights<br/>[insights.py]"]
  node_profile["Profile settings<br/>[settings_views.py]"]
  node_usage["Usage dashboard<br/>[metrics.py]"]
end

node_athlete(("Athlete"))
node_garmin["Garmin Connect"]
node_openmeteo["Open-Meteo"]

node_athlete -->|"chats with"| node_web
node_garmin -->|"provides activities"| node_syncjobs
node_syncjobs -->|"writes records"| node_syncrecords
node_openmeteo -->|"serves forecasts"| node_weatherfetch
node_weatherfetch -->|"stores forecasts"| node_syncrecords
node_syncweather -->|"fetches forecast"| node_weatherfetch
node_web -->|"calls chat"| node_agent
node_agent -->|"builds snapshot"| node_context
node_agent -->|"dispatches tools"| node_tools
node_context -->|"reads fitness data"| node_syncrecords
node_context -->|"reads coaching data"| node_coachrecords
node_context -->|"loads rules"| node_rules
node_context -->|"uses activity history"| node_traininglog
node_tools -->|"reads and writes"| node_coachrecords
node_tools -->|"reads catalogs"| node_syncrecords
node_tools -->|"checks restrictions"| node_rules
node_tools -->|"validates week"| node_weekchecker
node_tools -->|"loads methodology"| node_skills
node_skills -->|"reads skill files"| node_planner
node_librarysync -->|"loads exercise catalog"| node_syncrecords
node_dashboard -->|"reads metrics"| node_syncrecords
node_dashboard -->|"reads plans and feelings"| node_coachrecords
node_dashboard -->|"uses training summary"| node_traininglog
node_activities -.->|"shows done versus planned"| node_traininglog
node_stats -.->|"summarizes activity"| node_traininglog
node_insights -.->|"analyzes fitness data"| node_syncrecords
node_insights -.->|"stores insights"| node_coachrecords
node_profile -.->|"updates profile"| node_syncrecords
node_usage -->|"reads API usage"| node_coachrecords
node_agent -->|"stores recommendation and trace"| node_coachrecords

click node_syncjobs "https://github.com/czerw0/training-coach-ai/blob/main/sync/management/commands/sync_garmin.py"
click node_weatherfetch "https://github.com/czerw0/training-coach-ai/blob/main/sync/weather.py"
click node_syncrecords "https://github.com/czerw0/training-coach-ai/blob/main/sync/models.py"
click node_syncweather "https://github.com/czerw0/training-coach-ai/blob/main/sync/management/commands/sync_weather.py"
click node_web "https://github.com/czerw0/training-coach-ai/blob/main/coach/views.py"
click node_context "https://github.com/czerw0/training-coach-ai/blob/main/coach/context.py"
click node_agent "https://github.com/czerw0/training-coach-ai/blob/main/coach/agent.py"
click node_tools "https://github.com/czerw0/training-coach-ai/blob/main/coach/tools.py"
click node_coachrecords "https://github.com/czerw0/training-coach-ai/blob/main/coach/models.py"
click node_rules "https://github.com/czerw0/training-coach-ai/blob/main/coach/athlete_rules.py"
click node_traininglog "https://github.com/czerw0/training-coach-ai/blob/main/coach/training_log.py"
click node_skills "https://github.com/czerw0/training-coach-ai/blob/main/coach/training_skills.py"
click node_weekchecker "https://github.com/czerw0/training-coach-ai/blob/main/skills/training-planner/scripts/check_week.py"
click node_librarysync "https://github.com/czerw0/training-coach-ai/blob/main/sync/management/commands/sync_exercises.py"
click node_dashboard "https://github.com/czerw0/training-coach-ai/blob/main/coach/dashboard.py"
click node_activities "https://github.com/czerw0/training-coach-ai/blob/main/coach/activity.py"
click node_stats "https://github.com/czerw0/training-coach-ai/blob/main/coach/stats.py"
click node_insights "https://github.com/czerw0/training-coach-ai/blob/main/coach/insights.py"
click node_profile "https://github.com/czerw0/training-coach-ai/blob/main/coach/settings_views.py"
click node_usage "https://github.com/czerw0/training-coach-ai/blob/main/coach/metrics.py"
click node_planner "https://github.com/czerw0/training-coach-ai/blob/main/skills/training-planner/scripts/frontmatter.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_syncjobs,node_weatherfetch,node_syncrecords,node_syncweather,node_librarysync toneBlue
class node_context,node_agent,node_tools,node_coachrecords toneAmber
class node_rules,node_traininglog,node_skills,node_weekchecker,node_planner toneMint
class node_web,node_dashboard,node_activities,node_stats,node_insights,node_profile,node_usage toneRose
class node_athlete,node_garmin,node_openmeteo toneIndigo
```

## Components

### Data ingestion

- [Garmin sync](https://github.com/czerw0/training-coach-ai/blob/main/sync/management/commands/sync_garmin.py): `sync/management/commands/sync_garmin.py`
- [Weather fetch](https://github.com/czerw0/training-coach-ai/blob/main/sync/weather.py): `sync/weather.py`
- [Fitness records](https://github.com/czerw0/training-coach-ai/blob/main/sync/models.py): `sync/models.py`
- [Weather sync](https://github.com/czerw0/training-coach-ai/blob/main/sync/management/commands/sync_weather.py): `sync/management/commands/sync_weather.py`
- [Exercise catalog sync](https://github.com/czerw0/training-coach-ai/blob/main/sync/management/commands/sync_exercises.py): `sync/management/commands/sync_exercises.py`

### Coaching engine

- [Athlete context](https://github.com/czerw0/training-coach-ai/blob/main/coach/context.py): `coach/context.py`
- [AI coach loop](https://github.com/czerw0/training-coach-ai/blob/main/coach/agent.py): `coach/agent.py`
- [Agent tools](https://github.com/czerw0/training-coach-ai/blob/main/coach/tools.py): `coach/tools.py`
- [Coach records](https://github.com/czerw0/training-coach-ai/blob/main/coach/models.py): `coach/models.py`

### Training planning

- [Athlete rules](https://github.com/czerw0/training-coach-ai/blob/main/coach/athlete_rules.py): `coach/athlete_rules.py`
- [Completed training](https://github.com/czerw0/training-coach-ai/blob/main/coach/training_log.py): `coach/training_log.py`
- [Training skills](https://github.com/czerw0/training-coach-ai/blob/main/coach/training_skills.py): `coach/training_skills.py`
- [Week checker](https://github.com/czerw0/training-coach-ai/blob/main/skills/training-planner/scripts/check_week.py): `skills/training-planner/scripts/check_week.py`
- [Planner skill files](https://github.com/czerw0/training-coach-ai/blob/main/skills/training-planner/scripts/frontmatter.py): `skills/training-planner/scripts/frontmatter.py`

### Athlete experience

- [Django web app](https://github.com/czerw0/training-coach-ai/blob/main/coach/views.py): `coach/views.py`
- [Today dashboard](https://github.com/czerw0/training-coach-ai/blob/main/coach/dashboard.py): `coach/dashboard.py`
- [Activity detail](https://github.com/czerw0/training-coach-ai/blob/main/coach/activity.py): `coach/activity.py`
- [Training statistics](https://github.com/czerw0/training-coach-ai/blob/main/coach/stats.py): `coach/stats.py`
- [AI insights](https://github.com/czerw0/training-coach-ai/blob/main/coach/insights.py): `coach/insights.py`
- [Profile settings](https://github.com/czerw0/training-coach-ai/blob/main/coach/settings_views.py): `coach/settings_views.py`
- [Usage dashboard](https://github.com/czerw0/training-coach-ai/blob/main/coach/metrics.py): `coach/metrics.py`

### Other components

- **Athlete**
- **Garmin Connect**
- **Open-Meteo**

## Connections

- Athlete → Django web app: chats with
- Garmin Connect → Garmin sync: provides activities
- Garmin sync → Fitness records: writes records (evidence: `sync/management/commands/sync_garmin.py`)
- Open-Meteo → Weather fetch: serves forecasts (evidence: `sync/weather.py`)
- Weather fetch → Fitness records: stores forecasts (evidence: `sync/weather.py`)
- Weather sync → Weather fetch: fetches forecast (evidence: `sync/weather.py`)
- Django web app → AI coach loop: calls chat (evidence: `coach/views.py`)
- AI coach loop → Athlete context: builds snapshot (evidence: `coach/agent.py`)
- AI coach loop → Agent tools: dispatches tools (evidence: `coach/agent.py`)
- Athlete context → Fitness records: reads fitness data (evidence: `coach/context.py`)
- Athlete context → Coach records: reads coaching data (evidence: `coach/context.py`)
- Athlete context → Athlete rules: loads rules (evidence: `coach/context.py`)
- Athlete context → Completed training: uses activity history (evidence: `coach/context.py`)
- Agent tools → Coach records: reads and writes (evidence: `coach/tools.py`)
- Agent tools → Fitness records: reads catalogs (evidence: `coach/tools.py`)
- Agent tools → Athlete rules: checks restrictions (evidence: `coach/tools.py`)
- Agent tools → Week checker: validates week (evidence: `coach/tools.py`)
- Agent tools → Training skills: loads methodology (evidence: `coach/tools.py`)
- Training skills → Planner skill files: reads skill files (evidence: `skills/training-planner/scripts/frontmatter.py`)
- Exercise catalog sync → Fitness records: loads exercise catalog (evidence: `sync/management/commands/sync_exercises.py`)
- Today dashboard → Fitness records: reads metrics (evidence: `coach/dashboard.py`)
- Today dashboard → Coach records: reads plans and feelings (evidence: `coach/dashboard.py`)
- Today dashboard → Completed training: uses training summary (evidence: `coach/dashboard.py`)
- Activity detail → Completed training: shows done versus planned
- Training statistics → Completed training: summarizes activity
- AI insights → Fitness records: analyzes fitness data
- AI insights → Coach records: stores insights
- Profile settings → Fitness records: updates profile
- Usage dashboard → Coach records: reads API usage (evidence: `coach/metrics.py`)
- AI coach loop → Coach records: stores recommendation and trace (evidence: `coach/agent.py`)
