# amrrish21/f1_dashboard architecture

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

- Interactive diagram: https://gitdiagram.com/amrrish21/f1_dashboard
- Repository: https://github.com/amrrish21/f1_dashboard

## Overview

#### Purpose and Entry Point
This is a local Streamlit dashboard for comparing Formula 1 drivers’ session telemetry and lap performance. Start it with `streamlit run app.py`; the UI is hosted by `app.py`, while `data_provider.py` isolates FastF1 access and data preparation.

Paths: `app.py`, `data_provider.py`, `requirements.txt`

#### UI Orchestration
`app.py` owns user interaction and rendering: sidebar controls select season, circuit, and session type; a load action retrieves session data; driver selectors enable a two-driver comparison. It renders KPI summaries and four analysis views: speed trace, lap pace, track map, and sector analysis.

Path: `app.py`

#### Session Acquisition Boundary
`data_provider.py` is the boundary between the application and FastF1. It loads a selected event/session, handles fetch failures by returning `None`, and keeps FastF1 internals out of the Streamlit layer. FastF1 sources historical and live-timing-derived F1 data, including Ergast-backed information.

Path: `data_provider.py`

#### Caching Layers
Raw FastF1 responses persist in a writable `.fastf1_cache` disk directory, avoiding repeated network retrieval after process restarts. Streamlit resource caching retains parsed session objects in memory; data caching retains derived DataFrames for an hour. This is important because initial session loading may take 15–60 seconds.

Paths: `data_provider.py`, `app.py`

#### Data Extraction and Transformation
The provider exposes session results for valid driver selection, fastest-lap lookup for each selected driver, telemetry extraction for distance-indexed channels and circuit coordinates, and all-driver-laps extraction for pace analysis. Derived data is exchanged primarily as pandas DataFrames, with NumPy supporting numerical processing and time/delta calculations.

Path: `data_provider.py`

#### Visualization Pipeline
The UI consumes provider outputs only after checking for missing data. Plotly renders:
- synchronized speed, throttle, and brake traces over lap distance;
- lap-time violin/scatter distributions and chronological pace;
- XY track geometry colored by speed, gear, or throttle;
- sector-time grouped bars and delta-oriented tabular comparison.

Speed traces apply rolling smoothing; track-map axes preserve geometric aspect ratio.

Path: `app.py`

#### Runtime and External Dependencies
The runtime is Python 3.10+ with Streamlit 1.35+, FastF1 3.3+, Plotly 5.22+, pandas, and NumPy. It is intended for local browser access at Streamlit’s default port 8501. External dependency availability and a writable local cache are operational requirements; UI warnings should contain provider/network failures rather than crash rendering.

Paths: `requirements.txt`, `data_provider.py`, `app.py`

Main entry points: [`app.py`](https://github.com/amrrish21/f1_dashboard/blob/main/app.py) (Dashboard orchestration), [`data_provider.py`](https://github.com/amrrish21/f1_dashboard/blob/main/data_provider.py) (Provider API), [`requirements.txt`](https://github.com/amrrish21/f1_dashboard/blob/main/requirements.txt) (Python dependencies)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Streamlit UI"]
  node_browser(("Local browser<br/>user client"))
  node_app["Dashboard orchestration<br/>Streamlit app<br/>[app.py]"]
  node_controls["Session and driver controls<br/>UI controls<br/>[app.py]"]
  node_kpis["KPI summaries<br/>UI view<br/>[app.py]"]
  node_speed_view["Speed trace analysis<br/>Plotly view<br/>[app.py]"]
  node_pace_view["Lap pace analysis<br/>Plotly view<br/>[app.py]"]
  node_track_view["Track map analysis<br/>Plotly view<br/>[app.py]"]
  node_sector_view["Sector analysis<br/>Plotly and table view<br/>[app.py]"]
end

subgraph group_provider["Data Provider"]
  node_provider_api{{"Provider API<br/>data boundary<br/>[data_provider.py]"}}
  node_session_loader["Session loader<br/>FastF1 access<br/>[data_provider.py]"]
  node_derived_frames["Telemetry and lap DataFrames<br/>pandas data<br/>[data_provider.py]"]
end

subgraph group_storage["Caching"]
  node_resource_cache[("Parsed session cache<br/>Streamlit resource cache<br/>[app.py]")]
  node_data_cache[("Derived data cache<br/>Streamlit data cache<br/>[data_provider.py]")]
  node_fastf1_disk_cache[("FastF1 disk cache<br/>local cache directory")]
end

subgraph group_external["External Data"]
  node_fastf1{{"FastF1<br/>external library"}}
  node_f1_sources(("F1 timing and Ergast data<br/>external data source"))
end

node_dependencies["Python dependencies<br/>runtime manifest<br/>[requirements.txt]"]

node_browser -->|"uses"| node_app
node_controls -->|"drives load and comparison"| node_app
node_app -->|"renders"| node_controls
node_app -->|"requests session data"| node_provider_api
node_provider_api -->|"loads selected session"| node_session_loader
node_session_loader -->|"calls"| node_fastf1
node_fastf1 -->|"retrieves timing data"| node_f1_sources
node_fastf1 -->|"reads and writes raw responses"| node_fastf1_disk_cache
node_session_loader -->|"stores parsed sessions"| node_resource_cache
node_provider_api -->|"caches derived outputs"| node_data_cache
node_provider_api -->|"extracts and transforms"| node_derived_frames
node_derived_frames -->|"returns validated data"| node_app
node_app -->|"renders"| node_kpis
node_app -->|"renders"| node_speed_view
node_app -->|"renders"| node_pace_view
node_app -->|"renders"| node_track_view
node_app -->|"renders"| node_sector_view
node_dependencies -.->|"provides runtime libraries"| node_app
node_dependencies -.->|"provides data libraries"| node_provider_api

click node_app "https://github.com/amrrish21/f1_dashboard/blob/main/app.py"
click node_controls "https://github.com/amrrish21/f1_dashboard/blob/main/app.py"
click node_kpis "https://github.com/amrrish21/f1_dashboard/blob/main/app.py"
click node_speed_view "https://github.com/amrrish21/f1_dashboard/blob/main/app.py"
click node_pace_view "https://github.com/amrrish21/f1_dashboard/blob/main/app.py"
click node_track_view "https://github.com/amrrish21/f1_dashboard/blob/main/app.py"
click node_sector_view "https://github.com/amrrish21/f1_dashboard/blob/main/app.py"
click node_provider_api "https://github.com/amrrish21/f1_dashboard/blob/main/data_provider.py"
click node_session_loader "https://github.com/amrrish21/f1_dashboard/blob/main/data_provider.py"
click node_derived_frames "https://github.com/amrrish21/f1_dashboard/blob/main/data_provider.py"
click node_resource_cache "https://github.com/amrrish21/f1_dashboard/blob/main/app.py"
click node_data_cache "https://github.com/amrrish21/f1_dashboard/blob/main/data_provider.py"
click node_dependencies "https://github.com/amrrish21/f1_dashboard/blob/main/requirements.txt"

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_browser,node_app,node_controls,node_kpis,node_speed_view,node_pace_view,node_track_view,node_sector_view toneBlue
class node_provider_api,node_session_loader,node_derived_frames toneAmber
class node_resource_cache,node_data_cache,node_fastf1_disk_cache toneMint
class node_fastf1,node_f1_sources toneRose
class node_dependencies toneNeutral
```

## Components

### Streamlit UI

- **Local browser**: user client · Accesses the dashboard on Streamlit's local server.
- [Dashboard orchestration](https://github.com/amrrish21/f1_dashboard/blob/main/app.py): Streamlit app · Coordinates controls, loading, validation, and rendering. · `app.py`
- [Session and driver controls](https://github.com/amrrish21/f1_dashboard/blob/main/app.py): UI controls · Selects season, circuit, session type, and two drivers. · `app.py`
- [KPI summaries](https://github.com/amrrish21/f1_dashboard/blob/main/app.py): UI view · `app.py`
- [Speed trace analysis](https://github.com/amrrish21/f1_dashboard/blob/main/app.py): Plotly view · Plots smoothed speed, throttle, and brake by lap distance. · `app.py`
- [Lap pace analysis](https://github.com/amrrish21/f1_dashboard/blob/main/app.py): Plotly view · Shows lap-time distributions and chronological pace. · `app.py`
- [Track map analysis](https://github.com/amrrish21/f1_dashboard/blob/main/app.py): Plotly view · Colors circuit geometry by telemetry channels. · `app.py`
- [Sector analysis](https://github.com/amrrish21/f1_dashboard/blob/main/app.py): Plotly and table view · Compares sector times and deltas. · `app.py`

### Data Provider

- [Provider API](https://github.com/amrrish21/f1_dashboard/blob/main/data_provider.py): data boundary · Contains FastF1 failures and returns missing data safely. · `data_provider.py`
- [Session loader](https://github.com/amrrish21/f1_dashboard/blob/main/data_provider.py): FastF1 access · Loads the selected event session. · `data_provider.py`
- [Telemetry and lap DataFrames](https://github.com/amrrish21/f1_dashboard/blob/main/data_provider.py): pandas data · Provides results, fastest laps, telemetry, and all-driver laps. · `data_provider.py`

### Caching

- [Parsed session cache](https://github.com/amrrish21/f1_dashboard/blob/main/app.py): Streamlit resource cache · Retains session objects in memory. · `app.py`
- [Derived data cache](https://github.com/amrrish21/f1_dashboard/blob/main/data_provider.py): Streamlit data cache · Caches derived DataFrames for one hour. · `data_provider.py`
- **FastF1 disk cache**: local cache directory · Persists raw FastF1 responses across process restarts.

### External Data

- **FastF1**: external library
- **F1 timing and Ergast data**: external data source

### Other components

- [Python dependencies](https://github.com/amrrish21/f1_dashboard/blob/main/requirements.txt): runtime manifest · Defines Streamlit, FastF1, Plotly, pandas, and NumPy requirements. · `requirements.txt`

## Connections

- Local browser → Dashboard orchestration: uses
- Session and driver controls → Dashboard orchestration: drives load and comparison
- Dashboard orchestration → Session and driver controls: renders
- Dashboard orchestration → Provider API: requests session data
- Provider API → Session loader: loads selected session
- Session loader → FastF1: calls
- FastF1 → F1 timing and Ergast data: retrieves timing data
- FastF1 → FastF1 disk cache: reads and writes raw responses
- Session loader → Parsed session cache: stores parsed sessions
- Provider API → Derived data cache: caches derived outputs
- Provider API → Telemetry and lap DataFrames: extracts and transforms
- Telemetry and lap DataFrames → Dashboard orchestration: returns validated data
- Dashboard orchestration → KPI summaries: renders
- Dashboard orchestration → Speed trace analysis: renders
- Dashboard orchestration → Lap pace analysis: renders
- Dashboard orchestration → Track map analysis: renders
- Dashboard orchestration → Sector analysis: renders
- Python dependencies → Dashboard orchestration: provides runtime libraries
- Python dependencies → Provider API: provides data libraries
