# jon-becker/prediction-market-analysis architecture

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

- Interactive diagram: https://gitdiagram.com/jon-becker/prediction-market-analysis
- Repository: https://github.com/jon-becker/prediction-market-analysis

## Overview

Prediction Market Analysis collects Kalshi and Polymarket market/trade data, stores it as Parquet, and runs venue-specific research analyses that produce figures and statistical outputs. The main command-line entry point discovers and dispatches indexers or analyses. The README documents the broad collection-to-storage and analysis workflow; sampled source verifies several dispatches and shared clients, but not every indexer’s persistence or analysis data-loading details.

Main entry points: [`src/common/analysis.py`](https://github.com/jon-becker/prediction-market-analysis/blob/main/src/common/analysis.py) (Analysis framework), [`main.py`](https://github.com/jon-becker/prediction-market-analysis/blob/main/main.py) (CLI commands), [`src/indexers/polymarket`](https://github.com/jon-becker/prediction-market-analysis/tree/main/src/indexers/polymarket) (Polymarket indexers), [`src/common/indexer.py`](https://github.com/jon-becker/prediction-market-analysis/blob/main/src/common/indexer.py) (Indexer framework)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Application entry"]
  node_main["CLI commands<br/>[main.py]"]
end

subgraph group_collection["Data collection"]
  node_indexer_base["Indexer framework<br/>[indexer.py]"]
  node_kalshi_indexers["Kalshi indexers"]
  node_kalshi_client["Kalshi API client<br/>[client.py]"]
  node_kalshi_models["Kalshi data models<br/>[models.py]"]
  node_polymarket_indexers["Polymarket indexers"]
  node_polymarket_client["Polymarket API client<br/>[client.py]"]
  node_polymarket_models["Polymarket data models<br/>[models.py]"]
  node_polygon_fetcher["Polygon trade fetcher<br/>[blockchain.py]"]
  node_http_client["Shared HTTP client<br/>[client.py]"]
end

subgraph group_storage["Data storage"]
  node_parquet_store[("Parquet storage<br/>[storage.py]")]
end

subgraph group_research["Research analyses"]
  node_analysis_base["Analysis framework<br/>[analysis.py]"]
  node_kalshi_analysis["Kalshi analyses"]
  node_category_rules["Market categories<br/>[categories.py]"]
  node_polymarket_analysis["Polymarket analyses"]
  node_comparison_analysis["Cross-venue comparison"]
  node_chart_config["Chart interface<br/>[chart.py]"]
end

node_researcher(("Researcher"))
node_kalshi_api["Kalshi API"]
node_polymarket_api["Polymarket API"]
node_polygon_rpc["Polygon RPC"]
node_analysis_outputs["Figures and statistics"]
node_data_archive["Packaged data archive"]

node_researcher -->|"runs commands"| node_main
node_main -->|"discovers analyses"| node_analysis_base
node_main -->|"discovers indexers"| node_indexer_base
node_main -->|"saves outputs"| node_analysis_outputs
node_main -->|"packages data"| node_data_archive
node_indexer_base -.->|"loads implementations"| node_kalshi_indexers
node_indexer_base -.->|"loads implementations"| node_polymarket_indexers
node_kalshi_indexers -->|"uses client"| node_kalshi_client
node_kalshi_indexers -->|"implements"| node_indexer_base
node_kalshi_indexers -->|"persists data"| node_parquet_store
node_kalshi_client -->|"makes requests"| node_http_client
node_kalshi_client -->|"parses responses"| node_kalshi_models
node_kalshi_client -->|"requests market data"| node_kalshi_api
node_polymarket_indexers -->|"uses client"| node_polymarket_client
node_polymarket_indexers -->|"fetches chain data"| node_polygon_fetcher
node_polymarket_indexers -->|"implements"| node_indexer_base
node_polymarket_indexers -->|"persists data"| node_parquet_store
node_polymarket_client -->|"makes requests"| node_http_client
node_polymarket_client -->|"parses responses"| node_polymarket_models
node_polymarket_client -->|"requests markets"| node_polymarket_api
node_polygon_fetcher -->|"fetches chain events"| node_polygon_rpc
node_kalshi_analysis -->|"extends framework"| node_analysis_base
node_kalshi_analysis -->|"uses categories"| node_category_rules
node_polymarket_analysis -->|"extends framework"| node_analysis_base
node_comparison_analysis -->|"uses framework"| node_analysis_base
node_analysis_base -->|"uses chart types"| node_chart_config
node_kalshi_analysis -.->|"reads stored data"| node_parquet_store
node_polymarket_analysis -.->|"reads stored data"| node_parquet_store
node_comparison_analysis -.->|"reads stored data"| node_parquet_store
node_analysis_base -->|"exports results"| node_analysis_outputs

click node_main "https://github.com/jon-becker/prediction-market-analysis/blob/main/main.py"
click node_indexer_base "https://github.com/jon-becker/prediction-market-analysis/blob/main/src/common/indexer.py"
click node_kalshi_indexers "https://github.com/jon-becker/prediction-market-analysis/tree/main/src/indexers/kalshi"
click node_kalshi_client "https://github.com/jon-becker/prediction-market-analysis/blob/main/src/indexers/kalshi/client.py"
click node_kalshi_models "https://github.com/jon-becker/prediction-market-analysis/blob/main/src/indexers/kalshi/models.py"
click node_polymarket_indexers "https://github.com/jon-becker/prediction-market-analysis/tree/main/src/indexers/polymarket"
click node_polymarket_client "https://github.com/jon-becker/prediction-market-analysis/blob/main/src/indexers/polymarket/client.py"
click node_polymarket_models "https://github.com/jon-becker/prediction-market-analysis/blob/main/src/indexers/polymarket/models.py"
click node_polygon_fetcher "https://github.com/jon-becker/prediction-market-analysis/blob/main/src/indexers/polymarket/blockchain.py"
click node_http_client "https://github.com/jon-becker/prediction-market-analysis/blob/main/src/common/client.py"
click node_parquet_store "https://github.com/jon-becker/prediction-market-analysis/blob/main/src/common/storage.py"
click node_analysis_base "https://github.com/jon-becker/prediction-market-analysis/blob/main/src/common/analysis.py"
click node_kalshi_analysis "https://github.com/jon-becker/prediction-market-analysis/tree/main/src/analysis/kalshi"
click node_category_rules "https://github.com/jon-becker/prediction-market-analysis/blob/main/src/analysis/kalshi/util/categories.py"
click node_polymarket_analysis "https://github.com/jon-becker/prediction-market-analysis/tree/main/src/analysis/polymarket"
click node_comparison_analysis "https://github.com/jon-becker/prediction-market-analysis/blob/main/src/analysis/comparison/win_rate_by_price_animated.py"
click node_chart_config "https://github.com/jon-becker/prediction-market-analysis/blob/main/src/common/interfaces/chart.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_main toneBlue
class node_indexer_base,node_kalshi_indexers,node_kalshi_client,node_kalshi_models,node_polymarket_indexers,node_polymarket_client,node_polymarket_models,node_polygon_fetcher,node_http_client toneAmber
class node_parquet_store,node_kalshi_api,node_polymarket_api toneMint
class node_analysis_base,node_kalshi_analysis,node_category_rules,node_polymarket_analysis,node_comparison_analysis,node_chart_config toneRose
class node_researcher,node_polygon_rpc,node_analysis_outputs,node_data_archive toneIndigo
```

## Components

### Application entry

- [CLI commands](https://github.com/jon-becker/prediction-market-analysis/blob/main/main.py): `main.py`

### Data collection

- [Indexer framework](https://github.com/jon-becker/prediction-market-analysis/blob/main/src/common/indexer.py): `src/common/indexer.py`
- [Kalshi indexers](https://github.com/jon-becker/prediction-market-analysis/tree/main/src/indexers/kalshi): `src/indexers/kalshi`
- [Kalshi API client](https://github.com/jon-becker/prediction-market-analysis/blob/main/src/indexers/kalshi/client.py): `src/indexers/kalshi/client.py`
- [Kalshi data models](https://github.com/jon-becker/prediction-market-analysis/blob/main/src/indexers/kalshi/models.py): `src/indexers/kalshi/models.py`
- [Polymarket indexers](https://github.com/jon-becker/prediction-market-analysis/tree/main/src/indexers/polymarket): `src/indexers/polymarket`
- [Polymarket API client](https://github.com/jon-becker/prediction-market-analysis/blob/main/src/indexers/polymarket/client.py): `src/indexers/polymarket/client.py`
- [Polymarket data models](https://github.com/jon-becker/prediction-market-analysis/blob/main/src/indexers/polymarket/models.py): `src/indexers/polymarket/models.py`
- [Polygon trade fetcher](https://github.com/jon-becker/prediction-market-analysis/blob/main/src/indexers/polymarket/blockchain.py): `src/indexers/polymarket/blockchain.py`
- [Shared HTTP client](https://github.com/jon-becker/prediction-market-analysis/blob/main/src/common/client.py): `src/common/client.py`

### Data storage

- [Parquet storage](https://github.com/jon-becker/prediction-market-analysis/blob/main/src/common/storage.py): `src/common/storage.py`

### Research analyses

- [Analysis framework](https://github.com/jon-becker/prediction-market-analysis/blob/main/src/common/analysis.py): `src/common/analysis.py`
- [Kalshi analyses](https://github.com/jon-becker/prediction-market-analysis/tree/main/src/analysis/kalshi): `src/analysis/kalshi`
- [Market categories](https://github.com/jon-becker/prediction-market-analysis/blob/main/src/analysis/kalshi/util/categories.py): `src/analysis/kalshi/util/categories.py`
- [Polymarket analyses](https://github.com/jon-becker/prediction-market-analysis/tree/main/src/analysis/polymarket): `src/analysis/polymarket`
- [Cross-venue comparison](https://github.com/jon-becker/prediction-market-analysis/blob/main/src/analysis/comparison/win_rate_by_price_animated.py): `src/analysis/comparison/win_rate_by_price_animated.py`
- [Chart interface](https://github.com/jon-becker/prediction-market-analysis/blob/main/src/common/interfaces/chart.py): `src/common/interfaces/chart.py`

### Other components

- **Researcher**
- **Kalshi API**
- **Polymarket API**
- **Polygon RPC**
- **Figures and statistics**
- **Packaged data archive**

## Connections

- Researcher → CLI commands: runs commands (evidence: `README.md`)
- CLI commands → Analysis framework: discovers analyses (evidence: `main.py`)
- CLI commands → Indexer framework: discovers indexers (evidence: `main.py`)
- CLI commands → Figures and statistics: saves outputs (evidence: `main.py`)
- CLI commands → Packaged data archive: packages data (evidence: `main.py`)
- Indexer framework → Kalshi indexers: loads implementations (evidence: `src/indexers/kalshi/trades.py`)
- Indexer framework → Polymarket indexers: loads implementations (evidence: `src/indexers/polymarket/fpmm_trades.py`)
- Kalshi indexers → Kalshi API client: uses client (evidence: `src/indexers/kalshi/markets.py`)
- Kalshi indexers → Indexer framework: implements (evidence: `src/indexers/kalshi/markets.py`)
- Kalshi indexers → Parquet storage: persists data (evidence: `README.md`)
- Kalshi API client → Shared HTTP client: makes requests (evidence: `src/indexers/kalshi/client.py`)
- Kalshi API client → Kalshi data models: parses responses (evidence: `src/indexers/kalshi/client.py`)
- Kalshi API client → Kalshi API: requests market data (evidence: `src/indexers/kalshi/client.py`)
- Polymarket indexers → Polymarket API client: uses client (evidence: `src/indexers/polymarket/markets.py`)
- Polymarket indexers → Polygon trade fetcher: fetches chain data (evidence: `src/indexers/polymarket/trades.py`)
- Polymarket indexers → Indexer framework: implements (evidence: `src/indexers/polymarket/markets.py`)
- Polymarket indexers → Parquet storage: persists data (evidence: `README.md`)
- Polymarket API client → Shared HTTP client: makes requests (evidence: `src/indexers/polymarket/client.py`)
- Polymarket API client → Polymarket data models: parses responses (evidence: `src/indexers/polymarket/client.py`)
- Polymarket API client → Polymarket API: requests markets (evidence: `src/indexers/polymarket/client.py`)
- Polygon trade fetcher → Polygon RPC: fetches chain events (evidence: `src/indexers/polymarket/blockchain.py`)
- Kalshi analyses → Analysis framework: extends framework (evidence: `src/analysis/kalshi/statistical_tests.py`)
- Kalshi analyses → Market categories: uses categories (evidence: `src/analysis/kalshi/statistical_tests.py`)
- Polymarket analyses → Analysis framework: extends framework (evidence: `src/analysis/polymarket/polymarket_win_rate_by_price.py`)
- Cross-venue comparison → Analysis framework: uses framework (evidence: `src/analysis/comparison/win_rate_by_price_animated.py`)
- Analysis framework → Chart interface: uses chart types (evidence: `src/common/analysis.py`)
- Kalshi analyses → Parquet storage: reads stored data
- Polymarket analyses → Parquet storage: reads stored data
- Cross-venue comparison → Parquet storage: reads stored data
- Analysis framework → Figures and statistics: exports results (evidence: `src/common/analysis.py`)
