# usrr961/statbotics architecture

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

- Interactive diagram: https://gitdiagram.com/usrr961/statbotics
- Repository: https://github.com/usrr961/statbotics

## Overview

Statbotics computes historical and realtime FRC Expected Points Added (EPA), then exposes those results through a website, REST endpoints, and a Python API. The main workflow is TBA data ingestion, per-year processing and EPA calculation, publication as Parquet/site data to Google Cloud Storage, DuckDB-backed querying, and presentation in the website. The README documents these broad capabilities; source excerpts and the SOURCE INDEX support selected implementation links. Some frontend-to-service and ingestion details are therefore shown only where documented, not inferred from names.

Main entry points: [`backend/src/data/main.py`](https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/data/main.py) (Year data pipeline), [`frontend/src/pagesContent/team/main.tsx`](https://github.com/usrr961/statbotics/blob/cph-staging/frontend/src/pagesContent/team/main.tsx) (FRC analytics pages), [`backend/src/db_duckdb/main.py`](https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/db_duckdb/main.py) (DuckDB query layer), [`backend/main.py`](https://github.com/usrr961/statbotics/blob/cph-staging/backend/main.py) (REST and site API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_compute["Ingestion and ratings"]
  node_pipeline["Year data pipeline<br/>[main.py]"]
  node_tba_ingest["TBA ingestion<br/>[tba.py]"]
  node_epa_calc["EPA processing<br/>[main.py]"]
  node_epa_model["EPA rating model<br/>[main.py]"]
  node_trailing["Realtime updates<br/>[trailing.py]"]
end

subgraph group_serving["Storage and APIs"]
  node_parquet["Parquet artifacts<br/>[parquet.py]"]
  node_publisher["Artifact publishing<br/>[publish.py]"]
  node_gcs[("Google Cloud Storage<br/>[storage.py]")]
  node_duckdb["DuckDB query layer<br/>[main.py]"]
  node_entities["Entity models<br/>[main.py]"]
  node_api["REST and site API<br/>[main.py]"]
  node_api_queries["Entity query handlers<br/>[query.py]"]
end

subgraph group_web["Website experience"]
  node_frontend_api["Frontend data access<br/>[storage.tsx]"]
  node_pages["FRC analytics pages<br/>[main.tsx]"]
  node_visuals["Tables and visualizations<br/>[MatchTable.tsx]"]
  node_simulation["Event simulation<br/>[worker.ts]"]
end

subgraph group_modeling["Model experimentation"]
  node_model_runner["Model runner<br/>[runner.py]"]
  node_epa_model_package["EPA model package<br/>[epa_model.py]"]
  node_wins_model["Wins model<br/>[wins_model.py]"]
end

node_tba(("The Blue Alliance"))
node_public_users(("API and Python users"))

node_tba -->|"provides data"| node_tba_ingest
node_pipeline -->|"runs ingestion"| node_tba_ingest
node_pipeline -->|"processes years"| node_epa_calc
node_epa_calc -.->|"calculates ratings"| node_epa_model
node_pipeline -->|"updates realtime"| node_trailing
node_pipeline -->|"creates artifacts"| node_parquet
node_parquet -->|"publishes data"| node_publisher
node_publisher -->|"writes blobs"| node_gcs
node_gcs -->|"downloads artifacts"| node_duckdb
node_duckdb -->|"maps query rows"| node_entities
node_api -->|"routes requests"| node_api_queries
node_api_queries -.->|"queries entities"| node_duckdb
node_public_users -->|"requests statistics"| node_api
node_frontend_api -.->|"fetches data"| node_api
node_pages -->|"loads team data"| node_frontend_api
node_pages -.->|"renders analytics"| node_visuals
node_pages -.->|"offers event simulation"| node_simulation
node_model_runner -->|"runs model"| node_epa_model_package
node_model_runner -->|"runs model"| node_wins_model

click node_pipeline "https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/data/main.py"
click node_tba_ingest "https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/data/tba.py"
click node_epa_calc "https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/data/epa/main.py"
click node_epa_model "https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/models/epa/main.py"
click node_trailing "https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/data/trailing.py"
click node_parquet "https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/google/parquet.py"
click node_publisher "https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/google/publish.py"
click node_gcs "https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/google/storage.py"
click node_duckdb "https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/db_duckdb/main.py"
click node_entities "https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/db/models/main.py"
click node_api "https://github.com/usrr961/statbotics/blob/cph-staging/backend/main.py"
click node_api_queries "https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/api/query.py"
click node_frontend_api "https://github.com/usrr961/statbotics/blob/cph-staging/frontend/src/api/storage.tsx"
click node_pages "https://github.com/usrr961/statbotics/blob/cph-staging/frontend/src/pagesContent/team/main.tsx"
click node_visuals "https://github.com/usrr961/statbotics/blob/cph-staging/frontend/src/components/MatchTable.tsx"
click node_simulation "https://github.com/usrr961/statbotics/blob/cph-staging/frontend/src/pagesContent/event/%5Bevent_id%5D/worker.ts"
click node_model_runner "https://github.com/usrr961/statbotics/blob/cph-staging/models/runner.py"
click node_epa_model_package "https://github.com/usrr961/statbotics/blob/cph-staging/models/epa_model.py"
click node_wins_model "https://github.com/usrr961/statbotics/blob/cph-staging/models/wins_model.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_pipeline,node_tba_ingest,node_epa_calc,node_epa_model,node_trailing,node_public_users toneBlue
class node_parquet,node_publisher,node_gcs,node_duckdb,node_entities,node_api,node_api_queries toneAmber
class node_frontend_api,node_pages,node_visuals,node_simulation toneMint
class node_model_runner,node_epa_model_package,node_wins_model toneRose
class node_tba toneIndigo
```

## Components

### Ingestion and ratings

- [Year data pipeline](https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/data/main.py): `backend/src/data/main.py`
- [TBA ingestion](https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/data/tba.py): `backend/src/data/tba.py`
- [EPA processing](https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/data/epa/main.py): `backend/src/data/epa/main.py`
- [EPA rating model](https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/models/epa/main.py): `backend/src/models/epa/main.py`
- [Realtime updates](https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/data/trailing.py): `backend/src/data/trailing.py`

### Storage and APIs

- [Parquet artifacts](https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/google/parquet.py): `backend/src/google/parquet.py`
- [Artifact publishing](https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/google/publish.py): `backend/src/google/publish.py`
- [Google Cloud Storage](https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/google/storage.py): `backend/src/google/storage.py`
- [DuckDB query layer](https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/db_duckdb/main.py): `backend/src/db_duckdb/main.py`
- [Entity models](https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/db/models/main.py): `backend/src/db/models/main.py`
- [REST and site API](https://github.com/usrr961/statbotics/blob/cph-staging/backend/main.py): `backend/main.py`
- [Entity query handlers](https://github.com/usrr961/statbotics/blob/cph-staging/backend/src/api/query.py): `backend/src/api/query.py`

### Website experience

- [Frontend data access](https://github.com/usrr961/statbotics/blob/cph-staging/frontend/src/api/storage.tsx): `frontend/src/api/storage.tsx`
- [FRC analytics pages](https://github.com/usrr961/statbotics/blob/cph-staging/frontend/src/pagesContent/team/main.tsx): `frontend/src/pagesContent/team/main.tsx`
- [Tables and visualizations](https://github.com/usrr961/statbotics/blob/cph-staging/frontend/src/components/MatchTable.tsx): `frontend/src/components/MatchTable.tsx`
- [Event simulation](https://github.com/usrr961/statbotics/blob/cph-staging/frontend/src/pagesContent/event/%5Bevent_id%5D/worker.ts): `frontend/src/pagesContent/event/[event_id]/worker.ts`

### Model experimentation

- [Model runner](https://github.com/usrr961/statbotics/blob/cph-staging/models/runner.py): `models/runner.py`
- [EPA model package](https://github.com/usrr961/statbotics/blob/cph-staging/models/epa_model.py): `models/epa_model.py`
- [Wins model](https://github.com/usrr961/statbotics/blob/cph-staging/models/wins_model.py): `models/wins_model.py`

### Other components

- **The Blue Alliance**
- **API and Python users**

## Connections

- The Blue Alliance → TBA ingestion: provides data
- Year data pipeline → TBA ingestion: runs ingestion (evidence: `backend/src/data/main.py`)
- Year data pipeline → EPA processing: processes years (evidence: `backend/src/data/main.py`)
- EPA processing → EPA rating model: calculates ratings
- Year data pipeline → Realtime updates: updates realtime (evidence: `backend/main.py`)
- Year data pipeline → Parquet artifacts: creates artifacts (evidence: `backend/src/data/main.py`)
- Parquet artifacts → Artifact publishing: publishes data (evidence: `backend/src/google/parquet.py`)
- Artifact publishing → Google Cloud Storage: writes blobs (evidence: `backend/src/google/storage.py`)
- Google Cloud Storage → DuckDB query layer: downloads artifacts (evidence: `backend/src/db_duckdb/main.py`)
- DuckDB query layer → Entity models: maps query rows (evidence: `backend/src/db_duckdb/main.py`)
- REST and site API → Entity query handlers: routes requests (evidence: `backend/main.py`)
- Entity query handlers → DuckDB query layer: queries entities
- API and Python users → REST and site API: requests statistics
- Frontend data access → REST and site API: fetches data
- FRC analytics pages → Frontend data access: loads team data (evidence: `frontend/src/pagesContent/team/main.tsx`)
- FRC analytics pages → Tables and visualizations: renders analytics
- FRC analytics pages → Event simulation: offers event simulation
- Model runner → EPA model package: runs model (evidence: `models/runner.py`)
- Model runner → Wins model: runs model (evidence: `models/runner.py`)
