# qqqqdh/kbl architecture

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

- Interactive diagram: https://gitdiagram.com/qqqqdh/kbl
- Repository: https://github.com/qqqqdh/kbl

## Overview

KBL Analytics is a Go basketball data and forecasting system. Its main workflow collects official game and player data, validates and persists it, then serves player and team projections, standings, matchup and season simulations, and backtests through a CLI or REST API. The repository also contains a separate AI debate web app and a standalone GS/40 research analysis. Links reflect README statements and the supplied source index or excerpts; unsampled internals are not treated as inspected, so uncertain connections are omitted.

Main entry points: [`internal/projection/marcel.go`](https://github.com/qqqqdh/kbl/blob/main/internal/projection/marcel.go) (Player Projection), [`cmd/kbl/main.go`](https://github.com/qqqqdh/kbl/blob/main/cmd/kbl/main.go) (Analytics CLI), [`internal/http/server.go`](https://github.com/qqqqdh/kbl/blob/main/internal/http/server.go) (REST API), [`internal/repository/sqlite.go`](https://github.com/qqqqdh/kbl/blob/main/internal/repository/sqlite.go) (SQLite Repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry Points"]
  node_cli["Analytics CLI<br/>[main.go]"]
  node_rest["REST API<br/>[server.go]"]
  node_collector["Data Collector<br/>[main.go]"]
end

subgraph group_data["Data Pipeline"]
  node_config["Model Config<br/>[config.go]"]
  node_fetch["API Client<br/>[client.go]"]
  node_ingest["Season Ingestion<br/>[ingest.go]"]
  node_validate["Game Validation<br/>[ingest.go]"]
  node_sqlite[("SQLite Repository<br/>[sqlite.go]")]
  node_dataset["Dataset Loading<br/>[dataset.go]"]
end

subgraph group_models["Projection Models"]
  node_metrics["Advanced Metrics<br/>[calculator.go]"]
  node_marcel["Player Projection<br/>[marcel.go]"]
  node_intervals["Conformal Intervals<br/>[conformal.go]"]
  node_team["Team Projection<br/>[team.go]"]
  node_backtest["Rolling Backtest<br/>[backtest.go]"]
  node_simulation["Season Simulation<br/>[simulation.go]"]
end

subgraph group_research["Research Tools"]
  node_gs_research["GS/40 Analysis"]
  node_components["GS Components"]
  node_measurement["GS Measurement"]
end

subgraph group_debate["Debate Arena"]
  node_debate_web["Debate Server<br/>[server.py]"]
  node_session["Debate Engine<br/>[debate_engine.py]"]
end

node_kbl_api["Official KBL API"]
node_analyst(("Analyst"))
node_debate_user(("Debate User"))
node_llm["LLM Providers"]

node_analyst -->|"runs commands"| node_cli
node_analyst -->|"uses API"| node_rest
node_cli -->|"loads parameters"| node_config
node_cli -->|"opens repository"| node_sqlite
node_cli -->|"starts ingestion"| node_ingest
node_cli -->|"runs projections"| node_marcel
node_cli -->|"starts server"| node_rest
node_collector -->|"collects responses"| node_fetch
node_fetch -->|"requests data"| node_kbl_api
node_ingest -->|"fetches game data"| node_fetch
node_ingest -->|"saves official games"| node_validate
node_validate -->|"writes records"| node_sqlite
node_dataset -->|"loads history"| node_sqlite
node_rest -->|"dispatches projections"| node_marcel
node_rest -->|"reads repository"| node_sqlite
node_marcel -->|"loads training data"| node_dataset
node_marcel -->|"uses parameters"| node_config
node_marcel -->|"uses calculations"| node_metrics
node_marcel -.->|"calibrates intervals"| node_intervals
node_team -->|"projects players"| node_marcel
node_backtest -.->|"evaluates projections"| node_marcel
node_simulation -.->|"uses team forecasts"| node_team
node_analyst -->|"runs analysis"| node_gs_research
node_gs_research -->|"uses components"| node_components
node_components -->|"references measurement"| node_measurement
node_debate_user -->|"starts debate"| node_debate_web
node_debate_web -->|"steps session"| node_session
node_session -.->|"requests responses"| node_llm

click node_cli "https://github.com/qqqqdh/kbl/blob/main/cmd/kbl/main.go"
click node_rest "https://github.com/qqqqdh/kbl/blob/main/internal/http/server.go"
click node_collector "https://github.com/qqqqdh/kbl/blob/main/cmd/collect/main.go"
click node_config "https://github.com/qqqqdh/kbl/blob/main/internal/config/config.go"
click node_fetch "https://github.com/qqqqdh/kbl/blob/main/internal/ingestion/client.go"
click node_ingest "https://github.com/qqqqdh/kbl/blob/main/internal/ingestion/ingest.go"
click node_validate "https://github.com/qqqqdh/kbl/blob/main/internal/repository/ingest.go"
click node_sqlite "https://github.com/qqqqdh/kbl/blob/main/internal/repository/sqlite.go"
click node_dataset "https://github.com/qqqqdh/kbl/blob/main/internal/repository/dataset.go"
click node_metrics "https://github.com/qqqqdh/kbl/blob/main/internal/metrics/calculator.go"
click node_marcel "https://github.com/qqqqdh/kbl/blob/main/internal/projection/marcel.go"
click node_intervals "https://github.com/qqqqdh/kbl/blob/main/internal/projection/conformal.go"
click node_team "https://github.com/qqqqdh/kbl/blob/main/internal/projection/team.go"
click node_backtest "https://github.com/qqqqdh/kbl/blob/main/internal/projection/backtest.go"
click node_simulation "https://github.com/qqqqdh/kbl/blob/main/internal/projection/simulation.go"
click node_gs_research "https://github.com/qqqqdh/kbl/blob/main/tools/analyze_gs40_context.py"
click node_components "https://github.com/qqqqdh/kbl/blob/main/tools/analyze_gs40_components.py"
click node_measurement "https://github.com/qqqqdh/kbl/blob/main/tools/analyze_gs40_measurement.py"
click node_debate_web "https://github.com/qqqqdh/kbl/blob/main/debate_arena/server.py"
click node_session "https://github.com/qqqqdh/kbl/blob/main/debate_arena/debate_engine.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_cli,node_rest,node_collector,node_debate_user toneBlue
class node_config,node_fetch,node_ingest,node_validate,node_sqlite,node_dataset toneAmber
class node_metrics,node_marcel,node_intervals,node_team,node_backtest,node_simulation,node_kbl_api toneMint
class node_gs_research,node_components,node_measurement toneRose
class node_debate_web,node_session,node_analyst,node_llm toneIndigo
```

## Components

### Entry Points

- [Analytics CLI](https://github.com/qqqqdh/kbl/blob/main/cmd/kbl/main.go): `cmd/kbl/main.go`
- [REST API](https://github.com/qqqqdh/kbl/blob/main/internal/http/server.go): `internal/http/server.go`
- [Data Collector](https://github.com/qqqqdh/kbl/blob/main/cmd/collect/main.go): `cmd/collect/main.go`

### Data Pipeline

- [Model Config](https://github.com/qqqqdh/kbl/blob/main/internal/config/config.go): `internal/config/config.go`
- [API Client](https://github.com/qqqqdh/kbl/blob/main/internal/ingestion/client.go): `internal/ingestion/client.go`
- [Season Ingestion](https://github.com/qqqqdh/kbl/blob/main/internal/ingestion/ingest.go): `internal/ingestion/ingest.go`
- [Game Validation](https://github.com/qqqqdh/kbl/blob/main/internal/repository/ingest.go): `internal/repository/ingest.go`
- [SQLite Repository](https://github.com/qqqqdh/kbl/blob/main/internal/repository/sqlite.go): `internal/repository/sqlite.go`
- [Dataset Loading](https://github.com/qqqqdh/kbl/blob/main/internal/repository/dataset.go): `internal/repository/dataset.go`

### Projection Models

- [Advanced Metrics](https://github.com/qqqqdh/kbl/blob/main/internal/metrics/calculator.go): `internal/metrics/calculator.go`
- [Player Projection](https://github.com/qqqqdh/kbl/blob/main/internal/projection/marcel.go): `internal/projection/marcel.go`
- [Conformal Intervals](https://github.com/qqqqdh/kbl/blob/main/internal/projection/conformal.go): `internal/projection/conformal.go`
- [Team Projection](https://github.com/qqqqdh/kbl/blob/main/internal/projection/team.go): `internal/projection/team.go`
- [Rolling Backtest](https://github.com/qqqqdh/kbl/blob/main/internal/projection/backtest.go): `internal/projection/backtest.go`
- [Season Simulation](https://github.com/qqqqdh/kbl/blob/main/internal/projection/simulation.go): `internal/projection/simulation.go`

### Research Tools

- [GS/40 Analysis](https://github.com/qqqqdh/kbl/blob/main/tools/analyze_gs40_context.py): `tools/analyze_gs40_context.py`
- [GS Components](https://github.com/qqqqdh/kbl/blob/main/tools/analyze_gs40_components.py): `tools/analyze_gs40_components.py`
- [GS Measurement](https://github.com/qqqqdh/kbl/blob/main/tools/analyze_gs40_measurement.py): `tools/analyze_gs40_measurement.py`

### Debate Arena

- [Debate Server](https://github.com/qqqqdh/kbl/blob/main/debate_arena/server.py): `debate_arena/server.py`
- [Debate Engine](https://github.com/qqqqdh/kbl/blob/main/debate_arena/debate_engine.py): `debate_arena/debate_engine.py`

### Other components

- **Official KBL API**
- **Analyst**
- **Debate User**
- **LLM Providers**

## Connections

- Analyst → Analytics CLI: runs commands (evidence: `cmd/kbl/main.go`)
- Analyst → REST API: uses API
- Analytics CLI → Model Config: loads parameters (evidence: `cmd/kbl/main.go`)
- Analytics CLI → SQLite Repository: opens repository (evidence: `cmd/kbl/main.go`)
- Analytics CLI → Season Ingestion: starts ingestion (evidence: `cmd/kbl/main.go`)
- Analytics CLI → Player Projection: runs projections (evidence: `cmd/kbl/main.go`)
- Analytics CLI → REST API: starts server (evidence: `cmd/kbl/main.go`)
- Data Collector → API Client: collects responses (evidence: `cmd/collect/main.go`)
- API Client → Official KBL API: requests data
- Season Ingestion → API Client: fetches game data (evidence: `internal/ingestion/ingest.go`)
- Season Ingestion → Game Validation: saves official games (evidence: `internal/ingestion/ingest.go`)
- Game Validation → SQLite Repository: writes records (evidence: `internal/repository/ingest.go`)
- Dataset Loading → SQLite Repository: loads history (evidence: `internal/repository/dataset.go`)
- REST API → Player Projection: dispatches projections (evidence: `internal/http/server.go`)
- REST API → SQLite Repository: reads repository (evidence: `internal/http/server.go`)
- Player Projection → Dataset Loading: loads training data (evidence: `internal/projection/marcel.go`)
- Player Projection → Model Config: uses parameters (evidence: `internal/projection/marcel.go`)
- Player Projection → Advanced Metrics: uses calculations (evidence: `internal/projection/marcel.go`)
- Player Projection → Conformal Intervals: calibrates intervals
- Team Projection → Player Projection: projects players (evidence: `internal/projection/team.go`)
- Rolling Backtest → Player Projection: evaluates projections
- Season Simulation → Team Projection: uses team forecasts
- Analyst → GS/40 Analysis: runs analysis (evidence: `tools/analyze_gs40_context.py`)
- GS/40 Analysis → GS Components: uses components (evidence: `tools/analyze_gs40_context.py`)
- GS Components → GS Measurement: references measurement (evidence: `tools/analyze_gs40_components.py`)
- Debate User → Debate Server: starts debate (evidence: `debate_arena/server.py`)
- Debate Server → Debate Engine: steps session (evidence: `debate_arena/server.py`)
- Debate Engine → LLM Providers: requests responses (evidence: `debate_arena/debate_engine.py`)
