# eisoptrophobicc/f1-app architecture

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

- Interactive diagram: https://gitdiagram.com/eisoptrophobicc/f1-app
- Repository: https://github.com/eisoptrophobicc/f1-app

## Overview

1. **Repository shape**
   This is a two-part system: a **Python CLI/data-processing backend** under `src/` and a separate **React + Vite + PIXI.js replay viewer** under `frontend/`. Most screens render to the terminal; only the replay feature crosses into the browser.

2. **Top-level control flow**
   `src/main.py` is the entrypoint and acts as a **routing layer**, not a domain layer. It selects one screen via CLI flags such as `--screen`, `--season`, `--round`, and `--session`, then delegates to the corresponding module in `src/screens/`.

3. **Shared season/session semantics**
   The common season logic lives outside the screens in `src/utils/season.py` and `src/utils/session_context.py`. This is important architecturally: screens do not decide season defaults themselves. The app distinguishes **standings season semantics** from **calendar season semantics**, and the shared utilities enforce those rules consistently.

4. **Season-based terminal screens**
   `src/screens/driver_standings.py`, `constructor_standings.py`, and `race_calendar.py` are independent terminal screens. They consume season-resolved data and present different domain views:
   - driver standings: driver/team/points ranking
   - constructor standings: team ranking
   - race calendar: season event list, including testing and race weekends  
   These screens are read-only projections over FastF1/JolpicaF1 data.

5. **Race weekend session overview**
   `src/screens/session_overview.py` is the bridge between season-level event selection and session-level detail. It loads the sessions for a specific round or testing event and displays session metadata such as UTC date, status, and top-three fastest laps. This is the screen that moves from calendar semantics into event/session semantics.

6. **Telemetry replay backend**
   `src/screens/session_replay.py` and `src/engines/replay_engine.py` form the replay pipeline. The screen is the orchestration layer; the engine performs the heavy work: loading telemetry, deriving replay state, and exporting a compact binary artifact for visualization. The README indicates a **6-state constant-acceleration Kalman model** is used for replay reconstruction.

7. **Replay data boundary**
   The replay path is the main cross-process boundary in the repo. Python generates the replay dataset, then the browser viewer consumes it. This is different from the other screens, which stay entirely in the CLI/terminal. The binary export format exists specifically to make replay loading efficient and lightweight for the frontend.

8. **Frontend visualization boundary**
   `frontend/src/App.jsx` and `frontend/src/pixi/ReplayScene.jsx` implement the browser-side replay experience. React provides the UI shell, while PIXI.js handles the animated track visualization. This layer is intentionally separate from the FastF1 data fetching and numerical processing, so rendering does not depend on Python runtime internals.

9. **Data sources and domain enrichment**
   The app pulls race/telemetry data from **JolpicaF1 via FastF1** and uses FastF1’s local cache. It also includes `data/nationality_ioc.json`, which maps nationality values to IOC-style country codes for display. These are supporting data sources rather than standalone subsystems, but they materially affect presentation and identity mapping across screens.

10. **Operational characteristics**
   The backend is optimized for **on-demand analytics**: heavy session loading happens only for the screens that need it, session data is cached in memory during runtime, and derived analytics may use parallelism when worthwhile. There is no long-running application server; the main execution model is CLI-driven, with the frontend started separately via Vite for replay playback.

11. **What to show in an architecture diagram**
   A good diagram would show:
   - CLI entrypoint as the router
   - shared season/session utilities feeding all screens
   - three terminal data screens sharing the same data source path
   - session overview as the event/session bridge
   - replay screen handing off to the replay engine
   - replay engine exporting binary telemetry to the React/PIXI viewer
   - FastF1/JolpicaF1 and nationality mapping as external/supporting inputs

Main entry points: [`src/main.py`](https://github.com/eisoptrophobicc/f1-app/blob/main/src/main.py) (CLI router), [`src/utils/season.py`](https://github.com/eisoptrophobicc/f1-app/blob/main/src/utils/season.py) (Season rules), [`src/screens/session_overview.py`](https://github.com/eisoptrophobicc/f1-app/blob/main/src/screens/session_overview.py) (Session overview), [`src/engines/replay_engine.py`](https://github.com/eisoptrophobicc/f1-app/blob/main/src/engines/replay_engine.py) (Replay engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Python backend"]
  node_src_main["CLI router<br/>entrypoint<br/>[main.py]"]
  node_season_utils["Season rules<br/>shared util<br/>[season.py]"]
  node_session_context["Session context<br/>shared util<br/>[session_context.py]"]
  node_driver_standings["Driver standings<br/>terminal screen"]
  node_constructor_standings["Constructor standings<br/>terminal screen"]
  node_race_calendar["Race calendar<br/>terminal screen<br/>[race_calendar.py]"]
  node_session_overview["Session overview<br/>terminal screen"]
  node_session_replay["Replay screen<br/>terminal screen<br/>[session_replay.py]"]
  node_replay_engine{{"Replay engine<br/>telemetry engine<br/>[replay_engine.py]"}}
end

subgraph group_frontend["Replay frontend"]
  node_frontend_app["Viewer shell<br/>react app<br/>[App.jsx]"]
  node_replay_scene{{"Replay scene<br/>pixi scene<br/>[ReplayScene.jsx]"}}
  node_frontend_boot["Frontend bootstrap<br/>react entry<br/>[main.jsx]"]
end

subgraph group_data["Support data"]
  node_fastf1_jolpica[("FastF1 / JolpicaF1<br/>external data")]
  node_nationality_map["Nationality map<br/>lookup data"]
  node_replay_binary[("Replay binary<br/>export artifact")]
end

node_src_main -->|"resolve season"| node_season_utils
node_src_main -->|"resolve session"| node_session_context
node_src_main -->|"route"| node_driver_standings
node_src_main -->|"route"| node_constructor_standings
node_src_main -->|"route"| node_race_calendar
node_src_main -->|"route"| node_session_overview
node_src_main -->|"route"| node_session_replay
node_driver_standings -->|"season data"| node_season_utils
node_constructor_standings -->|"season data"| node_season_utils
node_race_calendar -->|"season data"| node_season_utils
node_session_overview -->|"season data"| node_season_utils
node_session_overview -->|"session data"| node_session_context
node_driver_standings -->|"load data"| node_fastf1_jolpica
node_constructor_standings -->|"load data"| node_fastf1_jolpica
node_race_calendar -->|"load data"| node_fastf1_jolpica
node_session_overview -->|"load data"| node_fastf1_jolpica
node_session_replay -->|"orchestrate"| node_replay_engine
node_replay_engine -->|"load telemetry"| node_fastf1_jolpica
node_replay_engine -->|"enrich display"| node_nationality_map
node_replay_engine -->|"export"| node_replay_binary
node_frontend_boot -->|"mount"| node_frontend_app
node_frontend_app -->|"render"| node_replay_scene
node_replay_scene -.->|"consume"| node_replay_binary
node_session_replay -.->|"handoff"| node_frontend_app

click node_src_main "https://github.com/eisoptrophobicc/f1-app/blob/main/src/main.py"
click node_season_utils "https://github.com/eisoptrophobicc/f1-app/blob/main/src/utils/season.py"
click node_session_context "https://github.com/eisoptrophobicc/f1-app/blob/main/src/utils/session_context.py"
click node_driver_standings "https://github.com/eisoptrophobicc/f1-app/blob/main/src/screens/driver_standings.py"
click node_constructor_standings "https://github.com/eisoptrophobicc/f1-app/blob/main/src/screens/constructor_standings.py"
click node_race_calendar "https://github.com/eisoptrophobicc/f1-app/blob/main/src/screens/race_calendar.py"
click node_session_overview "https://github.com/eisoptrophobicc/f1-app/blob/main/src/screens/session_overview.py"
click node_session_replay "https://github.com/eisoptrophobicc/f1-app/blob/main/src/screens/session_replay.py"
click node_replay_engine "https://github.com/eisoptrophobicc/f1-app/blob/main/src/engines/replay_engine.py"
click node_nationality_map "https://github.com/eisoptrophobicc/f1-app/blob/main/data/nationality_ioc.json"
click node_frontend_app "https://github.com/eisoptrophobicc/f1-app/blob/main/frontend/src/App.jsx"
click node_replay_scene "https://github.com/eisoptrophobicc/f1-app/blob/main/frontend/src/pixi/ReplayScene.jsx"
click node_frontend_boot "https://github.com/eisoptrophobicc/f1-app/blob/main/frontend/src/main.jsx"

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_src_main,node_season_utils,node_session_context,node_driver_standings,node_constructor_standings,node_race_calendar,node_session_overview,node_session_replay,node_replay_engine toneBlue
class node_frontend_app,node_replay_scene,node_frontend_boot toneAmber
class node_fastf1_jolpica,node_nationality_map,node_replay_binary toneMint
```

## Components

### Python backend

CLI screens, shared season/session logic, and replay generation

- [CLI router](https://github.com/eisoptrophobicc/f1-app/blob/main/src/main.py): entrypoint · Parses screen and season/session flags, then dispatches to a screen · `src/main.py`
- [Season rules](https://github.com/eisoptrophobicc/f1-app/blob/main/src/utils/season.py): shared util · Shared season semantics used across screens · `src/utils/season.py`
- [Session context](https://github.com/eisoptrophobicc/f1-app/blob/main/src/utils/session_context.py): shared util · Resolves and carries session-level selection state · `src/utils/session_context.py`
- [Driver standings](https://github.com/eisoptrophobicc/f1-app/blob/main/src/screens/driver_standings.py): terminal screen · Read-only driver/team points ranking view · `src/screens/driver_standings.py`
- [Constructor standings](https://github.com/eisoptrophobicc/f1-app/blob/main/src/screens/constructor_standings.py): terminal screen · Read-only team ranking view · `src/screens/constructor_standings.py`
- [Race calendar](https://github.com/eisoptrophobicc/f1-app/blob/main/src/screens/race_calendar.py): terminal screen · Season event list with testing and race weekends · `src/screens/race_calendar.py`
- [Session overview](https://github.com/eisoptrophobicc/f1-app/blob/main/src/screens/session_overview.py): terminal screen · Bridges event selection to session metadata and results · `src/screens/session_overview.py`
- [Replay screen](https://github.com/eisoptrophobicc/f1-app/blob/main/src/screens/session_replay.py): terminal screen · Orchestrates replay preparation for a selected session · `src/screens/session_replay.py`
- [Replay engine](https://github.com/eisoptrophobicc/f1-app/blob/main/src/engines/replay_engine.py): telemetry engine · Loads telemetry, derives replay state, and exports compact binary replay data · `src/engines/replay_engine.py`

### Replay frontend

React and PIXI-based browser playback

- [Viewer shell](https://github.com/eisoptrophobicc/f1-app/blob/main/frontend/src/App.jsx): react app · Browser UI shell that hosts the replay experience · `frontend/src/App.jsx`
- [Replay scene](https://github.com/eisoptrophobicc/f1-app/blob/main/frontend/src/pixi/ReplayScene.jsx): pixi scene · PIXI.js animation and track visualization layer · `frontend/src/pixi/ReplayScene.jsx`
- [Frontend bootstrap](https://github.com/eisoptrophobicc/f1-app/blob/main/frontend/src/main.jsx): react entry · Vite/React application entry point · `frontend/src/main.jsx`

### Support data

Static mappings and external data sources

- **FastF1 / JolpicaF1**: external data · Telemetry and session data source with local caching
- [Nationality map](https://github.com/eisoptrophobicc/f1-app/blob/main/data/nationality_ioc.json): lookup data · IOC-style nationality code mapping for display · `data/nationality_ioc.json`
- **Replay binary**: export artifact · Compact dataset consumed by the browser viewer

## Connections

- CLI router → Season rules: resolve season · Normalizes season semantics before screen dispatch
- CLI router → Session context: resolve session · Builds session selection context for session-aware screens
- CLI router → Driver standings: route · Dispatches to the driver standings screen
- CLI router → Constructor standings: route · Dispatches to the constructor standings screen
- CLI router → Race calendar: route · Dispatches to the race calendar screen
- CLI router → Session overview: route · Dispatches to the session overview screen
- CLI router → Replay screen: route · Dispatches to the replay screen
- Driver standings → Season rules: season data · Uses shared season resolution for standings views
- Constructor standings → Season rules: season data · Uses shared season resolution for standings views
- Race calendar → Season rules: season data · Uses shared season resolution for calendar views
- Session overview → Season rules: season data · Uses calendar-season semantics when selecting events
- Session overview → Session context: session data · Consumes round or testing-event context
- Driver standings → FastF1 / JolpicaF1: load data · Fetches standings data from the FastF1/JolpicaF1 source
- Constructor standings → FastF1 / JolpicaF1: load data · Fetches standings data from the FastF1/JolpicaF1 source
- Race calendar → FastF1 / JolpicaF1: load data · Fetches season calendar and event metadata
- Session overview → FastF1 / JolpicaF1: load data · Loads session metadata and lap results
- Replay screen → Replay engine: orchestrate · Delegates heavy replay reconstruction work
- Replay engine → FastF1 / JolpicaF1: load telemetry · Reads session telemetry and timing data
- Replay engine → Nationality map: enrich display · Maps nationality values for presentation
- Replay engine → Replay binary: export · Writes compact binary replay artifact for the browser
- Frontend bootstrap → Viewer shell: mount · Bootstraps the React application shell
- Viewer shell → Replay scene: render · Hands replay playback off to the PIXI scene
- Replay scene → Replay binary: consume · Loads the exported replay dataset for animation
- Replay screen → Viewer shell: handoff · Cross-process boundary between Python replay generation and browser playback
