# ai-chess-training/llm-chesscoach architecture

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

- Interactive diagram: https://gitdiagram.com/ai-chess-training/llm-chesscoach
- Repository: https://github.com/ai-chess-training/llm-chesscoach

## Overview

LLM-ChessCoach accepts chess games for Stockfish and LLM-assisted feedback, and also offers authenticated mobile API workflows for live play, analysis, and purchase-backed game access. The graph separates API orchestration, chess analysis, identity and entitlements, and session state. Relationships reflect the README and shown imports/calls; some API wiring is supported only by the API module’s source-index references, and unsampled details are not expanded.

Main entry points: [`api_server.py`](https://github.com/ai-chess-training/llm-chesscoach/blob/master/api_server.py) (REST and SSE API), [`live_sessions.py`](https://github.com/ai-chess-training/llm-chesscoach/blob/master/live_sessions.py) (Live game sessions), [`auth_service.py`](https://github.com/ai-chess-training/llm-chesscoach/blob/master/auth_service.py) (Backend authentication), [`app_store.py`](https://github.com/ai-chess-training/llm-chesscoach/blob/master/app_store.py) (StoreKit verification)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API workflows"]
  node_api_server["REST and SSE API<br/>[api_server.py]"]
  node_schemas["API models<br/>[schemas.py]"]
end

subgraph group_chess["Chess analysis"]
  node_pipeline["Batch PGN analysis"]
  node_analyze_games["Game analysis<br/>[analyze_games.py]"]
  node_lichess_export["Lichess importer"]
  node_engine["Stockfish analyzer"]
  node_move_analysis["Move feedback logic<br/>[move_analysis.py]"]
  node_coach["LLM and rule coach<br/>[llm_coach.py]"]
end

subgraph group_identity["Identity and access"]
  node_apple_auth["Apple identity verification<br/>[apple_auth.py]"]
  node_auth_service["Backend authentication<br/>[auth_service.py]"]
  node_token_utils["JWT utilities<br/>[token_utils.py]"]
  node_app_store["StoreKit verification<br/>[app_store.py]"]
  node_entitlements[("User and game balances<br/>[entitlements.py]")]
end

subgraph group_state["Session and configuration"]
  node_session_manager["Live game sessions<br/>[live_sessions.py]"]
  node_env_loader["Environment loading<br/>[env_loader.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
end

subgraph group_legacy["Legacy interface"]
  node_legacy_app["Legacy Streamlit UI<br/>[chess_coach_app.py]"]
  node_legacy_react["Legacy React UI<br/>[app.js]"]
end

node_player(("Player / mobile client"))
node_openai["OpenAI-compatible service"]
node_apple["Apple identity / App Store"]
node_redis[("Redis session store")]

node_player -->|"sends requests"| node_api_server
node_api_server -->|"verifies identity"| node_apple_auth
node_apple_auth -->|"verifies token"| node_apple
node_api_server -->|"authenticates requests"| node_auth_service
node_auth_service -->|"loads user"| node_entitlements
node_auth_service -->|"signs and checks"| node_token_utils
node_api_server -->|"verifies purchase"| node_app_store
node_app_store -->|"verifies transaction"| node_apple
node_app_store -->|"uses token helpers"| node_token_utils
node_api_server -->|"checks game balance"| node_entitlements
node_api_server -->|"creates and updates"| node_session_manager
node_session_manager -->|"persists sessions"| node_redis
node_session_manager -->|"analyzes positions"| node_engine
node_session_manager -->|"requests feedback"| node_coach
node_pipeline -->|"analyzes positions"| node_engine
node_pipeline -->|"requests feedback"| node_coach
node_coach -->|"requests coaching"| node_openai
node_lichess_export -->|"fetches Lichess games"| node_apple
node_lichess_export -->|"starts analysis"| node_analyze_games
node_analyze_games -->|"runs analysis"| node_engine
node_api_server -->|"analyzes submitted PGN"| node_pipeline
node_api_server -->|"uses response models"| node_schemas
node_legacy_app -->|"uses importer"| node_lichess_export
node_env_loader -.->|"configures runtime"| node_config

click node_api_server "https://github.com/ai-chess-training/llm-chesscoach/blob/master/api_server.py"
click node_schemas "https://github.com/ai-chess-training/llm-chesscoach/blob/master/schemas.py"
click node_pipeline "https://github.com/ai-chess-training/llm-chesscoach/blob/master/analysis_pipeline.py"
click node_analyze_games "https://github.com/ai-chess-training/llm-chesscoach/blob/master/analyze_games.py"
click node_lichess_export "https://github.com/ai-chess-training/llm-chesscoach/blob/master/export_lichess_games.py"
click node_engine "https://github.com/ai-chess-training/llm-chesscoach/blob/master/stockfish_engine.py"
click node_move_analysis "https://github.com/ai-chess-training/llm-chesscoach/blob/master/move_analysis.py"
click node_coach "https://github.com/ai-chess-training/llm-chesscoach/blob/master/llm_coach.py"
click node_apple_auth "https://github.com/ai-chess-training/llm-chesscoach/blob/master/apple_auth.py"
click node_auth_service "https://github.com/ai-chess-training/llm-chesscoach/blob/master/auth_service.py"
click node_token_utils "https://github.com/ai-chess-training/llm-chesscoach/blob/master/token_utils.py"
click node_app_store "https://github.com/ai-chess-training/llm-chesscoach/blob/master/app_store.py"
click node_entitlements "https://github.com/ai-chess-training/llm-chesscoach/blob/master/entitlements.py"
click node_session_manager "https://github.com/ai-chess-training/llm-chesscoach/blob/master/live_sessions.py"
click node_env_loader "https://github.com/ai-chess-training/llm-chesscoach/blob/master/env_loader.py"
click node_config "https://github.com/ai-chess-training/llm-chesscoach/blob/master/config.py"
click node_legacy_app "https://github.com/ai-chess-training/llm-chesscoach/blob/master/legacy/chess_coach_app.py"
click node_legacy_react "https://github.com/ai-chess-training/llm-chesscoach/blob/master/legacy/react-ui/app.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_api_server,node_schemas,node_player toneBlue
class node_pipeline,node_analyze_games,node_lichess_export,node_engine,node_move_analysis,node_coach,node_redis toneAmber
class node_apple_auth,node_auth_service,node_token_utils,node_app_store,node_entitlements toneMint
class node_session_manager,node_env_loader,node_config toneRose
class node_legacy_app,node_legacy_react,node_openai,node_apple toneIndigo
```

## Components

### API workflows

- [REST and SSE API](https://github.com/ai-chess-training/llm-chesscoach/blob/master/api_server.py): `api_server.py`
- [API models](https://github.com/ai-chess-training/llm-chesscoach/blob/master/schemas.py): `schemas.py`

### Chess analysis

- [Batch PGN analysis](https://github.com/ai-chess-training/llm-chesscoach/blob/master/analysis_pipeline.py): `analysis_pipeline.py`
- [Game analysis](https://github.com/ai-chess-training/llm-chesscoach/blob/master/analyze_games.py): `analyze_games.py`
- [Lichess importer](https://github.com/ai-chess-training/llm-chesscoach/blob/master/export_lichess_games.py): `export_lichess_games.py`
- [Stockfish analyzer](https://github.com/ai-chess-training/llm-chesscoach/blob/master/stockfish_engine.py): `stockfish_engine.py`
- [Move feedback logic](https://github.com/ai-chess-training/llm-chesscoach/blob/master/move_analysis.py): `move_analysis.py`
- [LLM and rule coach](https://github.com/ai-chess-training/llm-chesscoach/blob/master/llm_coach.py): `llm_coach.py`

### Identity and access

- [Apple identity verification](https://github.com/ai-chess-training/llm-chesscoach/blob/master/apple_auth.py): `apple_auth.py`
- [Backend authentication](https://github.com/ai-chess-training/llm-chesscoach/blob/master/auth_service.py): `auth_service.py`
- [JWT utilities](https://github.com/ai-chess-training/llm-chesscoach/blob/master/token_utils.py): `token_utils.py`
- [StoreKit verification](https://github.com/ai-chess-training/llm-chesscoach/blob/master/app_store.py): `app_store.py`
- [User and game balances](https://github.com/ai-chess-training/llm-chesscoach/blob/master/entitlements.py): `entitlements.py`

### Session and configuration

- [Live game sessions](https://github.com/ai-chess-training/llm-chesscoach/blob/master/live_sessions.py): `live_sessions.py`
- [Environment loading](https://github.com/ai-chess-training/llm-chesscoach/blob/master/env_loader.py): `env_loader.py`
- [Runtime configuration](https://github.com/ai-chess-training/llm-chesscoach/blob/master/config.py): `config.py`

### Legacy interface

- [Legacy Streamlit UI](https://github.com/ai-chess-training/llm-chesscoach/blob/master/legacy/chess_coach_app.py): `legacy/chess_coach_app.py`
- [Legacy React UI](https://github.com/ai-chess-training/llm-chesscoach/blob/master/legacy/react-ui/app.js): `legacy/react-ui/app.js`

### Other components

- **Player / mobile client**
- **OpenAI-compatible service**
- **Apple identity / App Store**
- **Redis session store**

## Connections

- Player / mobile client → REST and SSE API: sends requests (evidence: `README.md`)
- REST and SSE API → Apple identity verification: verifies identity (evidence: `api_server.py`)
- Apple identity verification → Apple identity / App Store: verifies token (evidence: `README.md`)
- REST and SSE API → Backend authentication: authenticates requests (evidence: `api_server.py`)
- Backend authentication → User and game balances: loads user (evidence: `auth_service.py`)
- Backend authentication → JWT utilities: signs and checks (evidence: `auth_service.py`)
- REST and SSE API → StoreKit verification: verifies purchase (evidence: `README.md`)
- StoreKit verification → Apple identity / App Store: verifies transaction (evidence: `README.md`)
- StoreKit verification → JWT utilities: uses token helpers (evidence: `app_store.py`)
- REST and SSE API → User and game balances: checks game balance (evidence: `api_server.py`)
- REST and SSE API → Live game sessions: creates and updates (evidence: `README.md`)
- Live game sessions → Redis session store: persists sessions (evidence: `README.md`)
- Live game sessions → Stockfish analyzer: analyzes positions (evidence: `live_sessions.py`)
- Live game sessions → LLM and rule coach: requests feedback (evidence: `live_sessions.py`)
- Batch PGN analysis → Stockfish analyzer: analyzes positions (evidence: `analysis_pipeline.py`)
- Batch PGN analysis → LLM and rule coach: requests feedback (evidence: `analysis_pipeline.py`)
- LLM and rule coach → OpenAI-compatible service: requests coaching (evidence: `llm_coach.py`)
- Lichess importer → Apple identity / App Store: fetches Lichess games (evidence: `export_lichess_games.py`)
- Lichess importer → Game analysis: starts analysis (evidence: `export_lichess_games.py`)
- Game analysis → Stockfish analyzer: runs analysis (evidence: `analyze_games.py`)
- REST and SSE API → Batch PGN analysis: analyzes submitted PGN (evidence: `README.md`)
- REST and SSE API → API models: uses response models (evidence: `api_server.py`)
- Legacy Streamlit UI → Lichess importer: uses importer (evidence: `legacy/chess_coach_app.py`)
- Environment loading → Runtime configuration: configures runtime
