# callum-doty/campaign-allocation architecture

> Architecture diagram of the GitHub repository callum-doty/campaign-allocation, 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/callum-doty/campaign-allocation
- Repository: https://github.com/callum-doty/campaign-allocation

## Overview

Campaign Allocation is a research and decision-support pipeline for House campaign spending. Its main workflow fetches public election and finance data, assembles race-level features, forecasts outcomes, then evaluates and reallocates committee budgets; backtests compare those decisions with actual spending. Separate analyses cover spending timing, media markets and channels, national polling and household stress, and the 2026 map. The graph follows the documented runner and sampled source relationships; some analytical modules are represented by their exact paths, but their internal calls were not sampled.

Main entry points: [`run.py`](https://github.com/callum-doty/campaign-allocation/blob/main/run.py) (Pipeline runner), [`campaign/report.py`](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/report.py) (Report and figures), [`campaign/backtest.py`](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/backtest.py) (Cycle backtests), [`campaign/build_races.py`](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/build_races.py) (Race features)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data and features"]
  node_fetch["Fetch public data<br/>[fetch.py]"]
  node_results["Election results<br/>[load_results.py]"]
  node_nominees["Candidate nominees<br/>[load_candidates.py]"]
  node_quality["Challenger quality<br/>[lookup_quality.py]"]
  node_expenditures["Outside spending"]
  node_race_builder["Race features<br/>[build_races.py]"]
end

subgraph group_forecast["Forecasting"]
  node_baseline["Baseline model<br/>[fit_baseline.py]"]
  node_margin["Margin prediction<br/>[predict_margin.py]"]
  node_forecast["2026 forecast<br/>[forecast.py]"]
  node_dated["Dated forecasts<br/>[dated_forecast.py]"]
  node_backtest["Cycle backtests<br/>[backtest.py]"]
end

subgraph group_allocation["Spending analysis"]
  node_allocation["Budget allocation<br/>[allocate.py]"]
  node_game["Committee game<br/>[solve_game.py]"]
  node_coord["Coordinated allocation"]
  node_timing["Ballot timing<br/>[ballot_timing.py]"]
  node_channels["Channel mix<br/>[channel_mix.py]"]
  node_media["Media costs<br/>[media_cost.py]"]
end

subgraph group_outputs["Reports and insights"]
  node_household["Household stress<br/>[household_index.py]"]
  node_national["National polling tests<br/>[national_vote.py]"]
  node_report["Report and figures<br/>[report.py]"]
end

node_user(("Analyst"))
node_runner["Pipeline runner<br/>[run.py]"]

node_user -->|"runs pipeline"| node_runner
node_runner -->|"fetches data"| node_fetch
node_runner -->|"builds races"| node_race_builder
node_runner -->|"backtests cycles"| node_backtest
node_runner -->|"solves game"| node_game
node_runner -->|"analyzes channels"| node_channels
node_runner -->|"prices media"| node_media
node_runner -->|"forecasts cycle"| node_forecast
node_runner -->|"tests polling"| node_national
node_runner -->|"writes report"| node_report
node_race_builder -->|"loads results"| node_results
node_race_builder -->|"loads nominees"| node_nominees
node_race_builder -->|"loads spending"| node_expenditures
node_nominees -->|"checks nominees"| node_quality
node_backtest -->|"fits model"| node_baseline
node_backtest -->|"predicts margins"| node_margin
node_backtest -->|"scores checkpoints"| node_dated
node_backtest -->|"evaluates timing"| node_timing
node_backtest -.->|"compares budgets"| node_allocation
node_forecast -.->|"uses race features"| node_race_builder
node_report -->|"reports mix"| node_channels
node_report -->|"reports stress"| node_household
node_report -->|"reports timing"| node_timing
node_report -->|"reports costs"| node_media
node_report -.->|"reports equilibrium"| node_game
node_report -.->|"reports allocation"| node_coord

click node_fetch "https://github.com/callum-doty/campaign-allocation/blob/main/campaign/fetch.py"
click node_results "https://github.com/callum-doty/campaign-allocation/blob/main/campaign/load_results.py"
click node_nominees "https://github.com/callum-doty/campaign-allocation/blob/main/campaign/load_candidates.py"
click node_quality "https://github.com/callum-doty/campaign-allocation/blob/main/campaign/lookup_quality.py"
click node_expenditures "https://github.com/callum-doty/campaign-allocation/blob/main/campaign/load_expenditures.py"
click node_race_builder "https://github.com/callum-doty/campaign-allocation/blob/main/campaign/build_races.py"
click node_baseline "https://github.com/callum-doty/campaign-allocation/blob/main/campaign/fit_baseline.py"
click node_margin "https://github.com/callum-doty/campaign-allocation/blob/main/campaign/predict_margin.py"
click node_forecast "https://github.com/callum-doty/campaign-allocation/blob/main/campaign/forecast.py"
click node_dated "https://github.com/callum-doty/campaign-allocation/blob/main/campaign/dated_forecast.py"
click node_backtest "https://github.com/callum-doty/campaign-allocation/blob/main/campaign/backtest.py"
click node_allocation "https://github.com/callum-doty/campaign-allocation/blob/main/campaign/allocate.py"
click node_game "https://github.com/callum-doty/campaign-allocation/blob/main/campaign/solve_game.py"
click node_coord "https://github.com/callum-doty/campaign-allocation/blob/main/campaign/coordinated_allocation.py"
click node_timing "https://github.com/callum-doty/campaign-allocation/blob/main/campaign/ballot_timing.py"
click node_channels "https://github.com/callum-doty/campaign-allocation/blob/main/campaign/channel_mix.py"
click node_media "https://github.com/callum-doty/campaign-allocation/blob/main/campaign/media_cost.py"
click node_household "https://github.com/callum-doty/campaign-allocation/blob/main/campaign/household_index.py"
click node_national "https://github.com/callum-doty/campaign-allocation/blob/main/campaign/national_vote.py"
click node_report "https://github.com/callum-doty/campaign-allocation/blob/main/campaign/report.py"
click node_runner "https://github.com/callum-doty/campaign-allocation/blob/main/run.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_fetch,node_results,node_nominees,node_quality,node_expenditures,node_race_builder toneBlue
class node_baseline,node_margin,node_forecast,node_dated,node_backtest toneAmber
class node_allocation,node_game,node_coord,node_timing,node_channels,node_media toneMint
class node_household,node_national,node_report toneRose
class node_user toneIndigo
class node_runner toneTeal
```

## Components

### Data and features

- [Fetch public data](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/fetch.py): `campaign/fetch.py`
- [Election results](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/load_results.py): `campaign/load_results.py`
- [Candidate nominees](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/load_candidates.py): `campaign/load_candidates.py`
- [Challenger quality](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/lookup_quality.py): `campaign/lookup_quality.py`
- [Outside spending](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/load_expenditures.py): `campaign/load_expenditures.py`
- [Race features](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/build_races.py): `campaign/build_races.py`

### Forecasting

- [Baseline model](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/fit_baseline.py): `campaign/fit_baseline.py`
- [Margin prediction](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/predict_margin.py): `campaign/predict_margin.py`
- [2026 forecast](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/forecast.py): `campaign/forecast.py`
- [Dated forecasts](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/dated_forecast.py): `campaign/dated_forecast.py`
- [Cycle backtests](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/backtest.py): `campaign/backtest.py`

### Spending analysis

- [Budget allocation](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/allocate.py): `campaign/allocate.py`
- [Committee game](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/solve_game.py): `campaign/solve_game.py`
- [Coordinated allocation](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/coordinated_allocation.py): `campaign/coordinated_allocation.py`
- [Ballot timing](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/ballot_timing.py): `campaign/ballot_timing.py`
- [Channel mix](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/channel_mix.py): `campaign/channel_mix.py`
- [Media costs](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/media_cost.py): `campaign/media_cost.py`

### Reports and insights

- [Household stress](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/household_index.py): `campaign/household_index.py`
- [National polling tests](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/national_vote.py): `campaign/national_vote.py`
- [Report and figures](https://github.com/callum-doty/campaign-allocation/blob/main/campaign/report.py): `campaign/report.py`

### Other components

- **Analyst**
- [Pipeline runner](https://github.com/callum-doty/campaign-allocation/blob/main/run.py): `run.py`

## Connections

- Analyst → Pipeline runner: runs pipeline (evidence: `run.py`)
- Pipeline runner → Fetch public data: fetches data (evidence: `run.py`)
- Pipeline runner → Race features: builds races (evidence: `run.py`)
- Pipeline runner → Cycle backtests: backtests cycles (evidence: `run.py`)
- Pipeline runner → Committee game: solves game (evidence: `run.py`)
- Pipeline runner → Channel mix: analyzes channels (evidence: `run.py`)
- Pipeline runner → Media costs: prices media (evidence: `run.py`)
- Pipeline runner → 2026 forecast: forecasts cycle (evidence: `run.py`)
- Pipeline runner → National polling tests: tests polling (evidence: `run.py`)
- Pipeline runner → Report and figures: writes report (evidence: `run.py`)
- Race features → Election results: loads results (evidence: `campaign/build_races.py`)
- Race features → Candidate nominees: loads nominees (evidence: `campaign/build_races.py`)
- Race features → Outside spending: loads spending (evidence: `campaign/build_races.py`)
- Candidate nominees → Challenger quality: checks nominees (evidence: `campaign/load_candidates.py`)
- Cycle backtests → Baseline model: fits model (evidence: `campaign/backtest.py`)
- Cycle backtests → Margin prediction: predicts margins (evidence: `campaign/backtest.py`)
- Cycle backtests → Dated forecasts: scores checkpoints (evidence: `campaign/backtest.py`)
- Cycle backtests → Ballot timing: evaluates timing (evidence: `campaign/backtest.py`)
- Cycle backtests → Budget allocation: compares budgets
- 2026 forecast → Race features: uses race features
- Report and figures → Channel mix: reports mix (evidence: `campaign/report.py`)
- Report and figures → Household stress: reports stress (evidence: `campaign/report.py`)
- Report and figures → Ballot timing: reports timing (evidence: `campaign/report.py`)
- Report and figures → Media costs: reports costs (evidence: `campaign/report.py`)
- Report and figures → Committee game: reports equilibrium
- Report and figures → Coordinated allocation: reports allocation
