# haarshadd/blunder-buffer architecture

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

- Interactive diagram: https://gitdiagram.com/haarshadd/blunder-buffer
- Repository: https://github.com/haarshadd/blunder-buffer

## Overview

Blunder Buffer is a chess forecasting system with historical training and a live tournament path. Live sources normalize pairings and results into game events; the worker tracks changes, requests T0 forecasts, and resolves completed predictions. Staged prediction also supports a separate ECO-conditioned T1 update. Predictions and outcomes feed the ledger and replay sampler; training evaluates challengers and uses the registry for champion promotion. The README documents historical baseline/ECO/momentum experts, meta learning, and ACPL research, but sampled source does not establish every expert’s runtime wiring.

Main entry points: [`workers/realtime_chess.py`](https://github.com/haarshadd/blunder-buffer/blob/main/workers/realtime_chess.py) (Realtime worker), [`live/staged_predict.py`](https://github.com/haarshadd/blunder-buffer/blob/main/live/staged_predict.py) (Staged prediction API), [`core/ledger.py`](https://github.com/haarshadd/blunder-buffer/blob/main/core/ledger.py) (Prediction ledger), [`workers/adapters/chess_results.py`](https://github.com/haarshadd/blunder-buffer/blob/main/workers/adapters/chess_results.py) (Results adapter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_live["Live tournament"]
  node_adapter["Results adapter<br/>[chess_results.py]"]
  node_event["Normalized game event<br/>[events.py]"]
  node_worker["Realtime worker<br/>[realtime_chess.py]"]
  node_config["Tournament config<br/>[config.py]"]
end

subgraph group_forecast["Forecasting"]
  node_staged["Staged prediction API<br/>[staged_predict.py]"]
  node_features["Live features<br/>[features_live.py]"]
  node_pregame["Pregame meta<br/>[pregame.py]"]
  node_eco["ECO expert<br/>[eco.py]"]
  node_opening["Opening update<br/>[opening_update.py]"]
  node_baseline["Baseline expert"]
  node_acpl["ACPL research<br/>[chess_analysis.py]"]
end

subgraph group_learning["Learning governance"]
  node_ledger[("Prediction ledger<br/>[ledger.py]")]
  node_replay["Experience replay<br/>[replay_buffer.py]"]
  node_training["Meta training<br/>[train_meta.py]"]
  node_orchestrator["Promotion gate<br/>[orchestrator.py]"]
  node_registry[("Model registry<br/>[registry.py]")]
  node_backfill["Ledger backfill<br/>[backfill_ledger.py]"]
end

node_operator(("Tournament operator"))
node_provider["Chess-Results"]

node_operator -->|"starts polling"| node_worker
node_worker -->|"fetches games"| node_adapter
node_adapter -->|"fetches pages"| node_provider
node_adapter -->|"normalizes rows"| node_event
node_worker -->|"tracks changes"| node_event
node_worker -->|"uses settings"| node_config
node_worker -->|"requests T0"| node_staged
node_staged -->|"builds features"| node_features
node_staged -->|"runs T0 meta"| node_pregame
node_staged -->|"gets ECO probabilities"| node_eco
node_staged -->|"runs T1 meta"| node_opening
node_features -.->|"uses historical features"| node_baseline
node_staged -->|"logs predictions"| node_ledger
node_worker -->|"resolves outcomes"| node_ledger
node_ledger -->|"supplies resolved examples"| node_replay
node_training -->|"samples batch"| node_replay
node_training -->|"submits metrics"| node_orchestrator
node_orchestrator -->|"registers and promotes"| node_registry
node_backfill -->|"writes historical entries"| node_ledger

click node_adapter "https://github.com/haarshadd/blunder-buffer/blob/main/workers/adapters/chess_results.py"
click node_event "https://github.com/haarshadd/blunder-buffer/blob/main/live/events.py"
click node_worker "https://github.com/haarshadd/blunder-buffer/blob/main/workers/realtime_chess.py"
click node_config "https://github.com/haarshadd/blunder-buffer/blob/main/live/config.py"
click node_staged "https://github.com/haarshadd/blunder-buffer/blob/main/live/staged_predict.py"
click node_features "https://github.com/haarshadd/blunder-buffer/blob/main/live/features_live.py"
click node_pregame "https://github.com/haarshadd/blunder-buffer/blob/main/live/pregame.py"
click node_eco "https://github.com/haarshadd/blunder-buffer/blob/main/live/eco.py"
click node_opening "https://github.com/haarshadd/blunder-buffer/blob/main/live/opening_update.py"
click node_baseline "https://github.com/haarshadd/blunder-buffer/blob/main/others/twic_historical_loop.py"
click node_acpl "https://github.com/haarshadd/blunder-buffer/blob/main/workers/chess_analysis.py"
click node_ledger "https://github.com/haarshadd/blunder-buffer/blob/main/core/ledger.py"
click node_replay "https://github.com/haarshadd/blunder-buffer/blob/main/core/replay_buffer.py"
click node_training "https://github.com/haarshadd/blunder-buffer/blob/main/train_meta.py"
click node_orchestrator "https://github.com/haarshadd/blunder-buffer/blob/main/core/orchestrator.py"
click node_registry "https://github.com/haarshadd/blunder-buffer/blob/main/core/registry.py"
click node_backfill "https://github.com/haarshadd/blunder-buffer/blob/main/core/backfill_ledger.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_adapter,node_event,node_worker,node_config toneBlue
class node_staged,node_features,node_pregame,node_eco,node_opening,node_baseline,node_acpl toneAmber
class node_ledger,node_replay,node_training,node_orchestrator,node_registry,node_backfill toneMint
class node_operator,node_provider toneIndigo
```

## Components

### Live tournament

- [Results adapter](https://github.com/haarshadd/blunder-buffer/blob/main/workers/adapters/chess_results.py): `workers/adapters/chess_results.py`
- [Normalized game event](https://github.com/haarshadd/blunder-buffer/blob/main/live/events.py): `live/events.py`
- [Realtime worker](https://github.com/haarshadd/blunder-buffer/blob/main/workers/realtime_chess.py): `workers/realtime_chess.py`
- [Tournament config](https://github.com/haarshadd/blunder-buffer/blob/main/live/config.py): `live/config.py`

### Forecasting

- [Staged prediction API](https://github.com/haarshadd/blunder-buffer/blob/main/live/staged_predict.py): `live/staged_predict.py`
- [Live features](https://github.com/haarshadd/blunder-buffer/blob/main/live/features_live.py): `live/features_live.py`
- [Pregame meta](https://github.com/haarshadd/blunder-buffer/blob/main/live/pregame.py): `live/pregame.py`
- [ECO expert](https://github.com/haarshadd/blunder-buffer/blob/main/live/eco.py): `live/eco.py`
- [Opening update](https://github.com/haarshadd/blunder-buffer/blob/main/live/opening_update.py): `live/opening_update.py`
- [Baseline expert](https://github.com/haarshadd/blunder-buffer/blob/main/others/twic_historical_loop.py): `others/twic_historical_loop.py`
- [ACPL research](https://github.com/haarshadd/blunder-buffer/blob/main/workers/chess_analysis.py): `workers/chess_analysis.py`

### Learning governance

- [Prediction ledger](https://github.com/haarshadd/blunder-buffer/blob/main/core/ledger.py): `core/ledger.py`
- [Experience replay](https://github.com/haarshadd/blunder-buffer/blob/main/core/replay_buffer.py): `core/replay_buffer.py`
- [Meta training](https://github.com/haarshadd/blunder-buffer/blob/main/train_meta.py): `train_meta.py`
- [Promotion gate](https://github.com/haarshadd/blunder-buffer/blob/main/core/orchestrator.py): `core/orchestrator.py`
- [Model registry](https://github.com/haarshadd/blunder-buffer/blob/main/core/registry.py): `core/registry.py`
- [Ledger backfill](https://github.com/haarshadd/blunder-buffer/blob/main/core/backfill_ledger.py): `core/backfill_ledger.py`

### Other components

- **Tournament operator**
- **Chess-Results**

## Connections

- Tournament operator → Realtime worker: starts polling (evidence: `workers/realtime_chess.py`)
- Realtime worker → Results adapter: fetches games (evidence: `workers/realtime_chess.py`)
- Results adapter → Chess-Results: fetches pages (evidence: `workers/adapters/chess_results.py`)
- Results adapter → Normalized game event: normalizes rows (evidence: `workers/adapters/chess_results.py`)
- Realtime worker → Normalized game event: tracks changes (evidence: `workers/realtime_chess.py`)
- Realtime worker → Tournament config: uses settings (evidence: `workers/realtime_chess.py`)
- Realtime worker → Staged prediction API: requests T0 (evidence: `workers/realtime_chess.py`)
- Staged prediction API → Live features: builds features (evidence: `live/staged_predict.py`)
- Staged prediction API → Pregame meta: runs T0 meta (evidence: `live/staged_predict.py`)
- Staged prediction API → ECO expert: gets ECO probabilities (evidence: `live/staged_predict.py`)
- Staged prediction API → Opening update: runs T1 meta (evidence: `live/staged_predict.py`)
- Live features → Baseline expert: uses historical features
- Staged prediction API → Prediction ledger: logs predictions (evidence: `live/staged_predict.py`)
- Realtime worker → Prediction ledger: resolves outcomes (evidence: `workers/realtime_chess.py`)
- Prediction ledger → Experience replay: supplies resolved examples (evidence: `core/replay_buffer.py`)
- Meta training → Experience replay: samples batch (evidence: `train_meta.py`)
- Meta training → Promotion gate: submits metrics (evidence: `train_meta.py`)
- Promotion gate → Model registry: registers and promotes (evidence: `core/orchestrator.py`)
- Ledger backfill → Prediction ledger: writes historical entries (evidence: `core/backfill_ledger.py`)
