# aaronnn05/f1-apex-pace architecture

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

- Interactive diagram: https://gitdiagram.com/aaronnn05/f1-apex-pace
- Repository: https://github.com/aaronnn05/f1-apex-pace

## Overview

ApexPace predicts the next Formula 1 lap time from recent lap and tyre-state features. Its main workflow collects race laps, stores them in DuckDB, builds point-in-time features, then compares baselines and tunes an XGBoost model with temporal validation. The resulting model is saved and loaded by a FastAPI endpoint, which validates feature values and returns a prediction. The graph includes README-documented capabilities such as FastF1 ingestion and experiment tracking; links to unsampled subsystems rely on that documentation.

Main entry points: [`src/apex_pace/models/tune.py`](https://github.com/aaronnn05/f1-apex-pace/blob/main/src/apex_pace/models/tune.py) (Model tuning), [`scripts/build_pipeline.py`](https://github.com/aaronnn05/f1-apex-pace/blob/main/scripts/build_pipeline.py) (Ingest and build), [`src/apex_pace/api/main.py`](https://github.com/aaronnn05/f1-apex-pace/blob/main/src/apex_pace/api/main.py) (Prediction API), [`data/processed/features_v1.parquet`](https://github.com/aaronnn05/f1-apex-pace/blob/main/data/processed/features_v1.parquet) (Processed features)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_builder["Ingest and build<br/>[build_pipeline.py]"]
  node_lapdb[("Raw lap store<br/>[db.py]")]
  node_features["Feature engineering<br/>[pipeline.py]"]
  node_featurefile["Processed features"]
end

subgraph group_experiments["Model experiments"]
  node_baselines["Baseline comparison<br/>[baseline.py]"]
  node_temporal["Temporal split<br/>[tune.py]"]
  node_tuning["Model tuning<br/>[tune.py]"]
  node_xgboost["XGBoost training<br/>[tune.py]"]
  node_optuna["Optuna"]
  node_wandb["W&amp;B tracking"]
  node_artifact["Tuned model"]
end

subgraph group_serving["Prediction serving"]
  node_api["Prediction API<br/>[main.py]"]
  node_prediction["Lap-time result<br/>[main.py]"]
end

node_fastf1["FastF1"]
node_user(("API client"))

node_builder -->|"downloads laps"| node_fastf1
node_builder -->|"writes laps"| node_lapdb
node_builder -->|"builds features"| node_features
node_builder -->|"reads laps"| node_lapdb
node_features -->|"produces features"| node_featurefile
node_baselines -->|"reads features"| node_featurefile
node_temporal -->|"reads features"| node_featurefile
node_temporal -->|"supplies splits"| node_tuning
node_tuning -->|"optimizes trials"| node_optuna
node_tuning -->|"trains model"| node_xgboost
node_tuning -->|"logs results"| node_wandb
node_tuning -->|"saves model"| node_artifact
node_user -->|"sends features"| node_api
node_artifact -->|"loads model"| node_api
node_api -->|"returns prediction"| node_prediction

click node_builder "https://github.com/aaronnn05/f1-apex-pace/blob/main/scripts/build_pipeline.py"
click node_lapdb "https://github.com/aaronnn05/f1-apex-pace/blob/main/src/apex_pace/data/db.py"
click node_features "https://github.com/aaronnn05/f1-apex-pace/blob/main/src/apex_pace/features/pipeline.py"
click node_featurefile "https://github.com/aaronnn05/f1-apex-pace/blob/main/data/processed/features_v1.parquet"
click node_baselines "https://github.com/aaronnn05/f1-apex-pace/blob/main/src/apex_pace/models/baseline.py"
click node_temporal "https://github.com/aaronnn05/f1-apex-pace/blob/main/src/apex_pace/models/tune.py"
click node_tuning "https://github.com/aaronnn05/f1-apex-pace/blob/main/src/apex_pace/models/tune.py"
click node_xgboost "https://github.com/aaronnn05/f1-apex-pace/blob/main/src/apex_pace/models/tune.py"
click node_api "https://github.com/aaronnn05/f1-apex-pace/blob/main/src/apex_pace/api/main.py"
click node_prediction "https://github.com/aaronnn05/f1-apex-pace/blob/main/src/apex_pace/api/main.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_builder,node_lapdb,node_features,node_featurefile,node_user toneBlue
class node_baselines,node_temporal,node_tuning,node_xgboost,node_optuna,node_wandb,node_artifact toneAmber
class node_api,node_prediction toneMint
class node_fastf1 toneIndigo
```

## Components

### Data preparation

- [Ingest and build](https://github.com/aaronnn05/f1-apex-pace/blob/main/scripts/build_pipeline.py): `scripts/build_pipeline.py`
- [Raw lap store](https://github.com/aaronnn05/f1-apex-pace/blob/main/src/apex_pace/data/db.py): `src/apex_pace/data/db.py`
- [Feature engineering](https://github.com/aaronnn05/f1-apex-pace/blob/main/src/apex_pace/features/pipeline.py): `src/apex_pace/features/pipeline.py`
- [Processed features](https://github.com/aaronnn05/f1-apex-pace/blob/main/data/processed/features_v1.parquet): `data/processed/features_v1.parquet`

### Model experiments

- [Baseline comparison](https://github.com/aaronnn05/f1-apex-pace/blob/main/src/apex_pace/models/baseline.py): `src/apex_pace/models/baseline.py`
- [Temporal split](https://github.com/aaronnn05/f1-apex-pace/blob/main/src/apex_pace/models/tune.py): `src/apex_pace/models/tune.py`
- [Model tuning](https://github.com/aaronnn05/f1-apex-pace/blob/main/src/apex_pace/models/tune.py): `src/apex_pace/models/tune.py`
- [XGBoost training](https://github.com/aaronnn05/f1-apex-pace/blob/main/src/apex_pace/models/tune.py): `src/apex_pace/models/tune.py`
- **Optuna**
- **W&B tracking**
- **Tuned model**

### Prediction serving

- [Prediction API](https://github.com/aaronnn05/f1-apex-pace/blob/main/src/apex_pace/api/main.py): `src/apex_pace/api/main.py`
- [Lap-time result](https://github.com/aaronnn05/f1-apex-pace/blob/main/src/apex_pace/api/main.py): `src/apex_pace/api/main.py`

### Other components

- **FastF1**
- **API client**

## Connections

- Ingest and build → FastF1: downloads laps (evidence: `scripts/build_pipeline.py`)
- Ingest and build → Raw lap store: writes laps (evidence: `scripts/build_pipeline.py`)
- Ingest and build → Feature engineering: builds features (evidence: `scripts/build_pipeline.py`)
- Ingest and build → Raw lap store: reads laps (evidence: `scripts/build_pipeline.py`)
- Feature engineering → Processed features: produces features
- Baseline comparison → Processed features: reads features (evidence: `src/apex_pace/models/baseline.py`)
- Temporal split → Processed features: reads features (evidence: `src/apex_pace/models/tune.py`)
- Temporal split → Model tuning: supplies splits (evidence: `src/apex_pace/models/tune.py`)
- Model tuning → Optuna: optimizes trials (evidence: `src/apex_pace/models/tune.py`)
- Model tuning → XGBoost training: trains model (evidence: `src/apex_pace/models/tune.py`)
- Model tuning → W&B tracking: logs results (evidence: `src/apex_pace/models/tune.py`)
- Model tuning → Tuned model: saves model (evidence: `src/apex_pace/models/tune.py`)
- API client → Prediction API: sends features (evidence: `README.md`)
- Tuned model → Prediction API: loads model (evidence: `src/apex_pace/api/main.py`)
- Prediction API → Lap-time result: returns prediction (evidence: `src/apex_pace/api/main.py`)
