# draichi/formula1-ai architecture

> Architecture diagram of the GitHub repository draichi/formula1-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/draichi/formula1-ai
- Repository: https://github.com/draichi/formula1-ai

## Overview

##### Main Components

A. Data Layer
- FastF1 Telemetry Data Source
- SQLite Databases (shown in /db folder)
- Data Storage Components

B. Core Processing Layer
- ReAct Agent (main intelligence component)
- SQL Query Engine
- Machine Learning Models

C. Analysis Tools Layer
- Driver Performance Analysis
- Event Performance Analysis
- Telemetry Analysis
- Tyre Performance Analysis
- Weather Impact Analysis

D. User Interface Layer
- Gradio Web Interface
- Jupyter Notebooks Interface

##### Component Relationships

**[External Data Sources] → [Data Layer] → [Core Processing Layer] → [Analysis Tools Layer] → [User Interface Layer]**

##### Specific Implementation Details

- Bahrain_2023_Q.db and other potential race databases

- Processing Components (rectangles):
- ReAct Agent (central component)
- SQL Query Engine
- Machine Learning Models (Random Forest, Gradient Boosted Decision Trees)

- Analysis Modules (hexagons):
- Tools/ directory components
- Connection to SQL queries (/tools/sql/)

- User Interfaces (rounded rectangles):
- Gradio Web Interface
- Jupyter Notebooks

##### Important Elements to Highlight

- The ReAct Agent as the central orchestrator
- Machine Learning Pipeline for predictions
- Database connections and query flow
- Analysis tools integration
- User interface options

##### Technical Stack Indicators

Technology labels:
- Python 3.11
- Gradio 5.4.0
- SQLite
- FastF1 Library
- Machine Learning Libraries

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and Classes
    classDef database fill:#b3d1ff,stroke:#333
    classDef processing fill:#90EE90,stroke:#333
    classDef analysis fill:#FFB347,stroke:#333
    classDef interface fill:#DDA0DD,stroke:#333
    classDef external fill:#D3D3D3,stroke:#333

    %% External Data Sources
    ExternalData["FastF1 Telemetry Data"]:::external

    %% Data Layer
    subgraph DataLayer["Data Layer"]
        DB1[(Bahrain 2023 Q DB)]:::database
        DBConn[Database Connection Handler]:::database
        DBMgmt[Database Management]:::database
        DataStorage[Data Storage Management]:::database
    end

    %% Core Processing Layer
    subgraph ProcessingLayer["Core Processing Layer"]
        ReAct[ReAct Agent]:::processing
        SQLEngine[SQL Query Engine]:::processing
        MLModels[Machine Learning Models]:::processing
    end

    %% Analysis Tools Layer
    subgraph AnalysisLayer["Analysis Tools Layer"]
        DriverPerf[Driver Performance Analysis]:::analysis
        EventPerf[Event Performance Analysis]:::analysis
        TelemetryA[Telemetry Analysis]:::analysis
        TyrePerf[Tyre Performance Analysis]:::analysis
        WeatherImpact[Weather Impact Analysis]:::analysis
    end

    %% User Interface Layer
    subgraph UILayer["User Interface Layer"]
        Gradio[Gradio Web Interface]:::interface
        Jupyter[Jupyter Notebooks]:::interface
    end

    %% Relationships
    ExternalData --> DataStorage
    DataStorage --> DB1
    DB1 --> DBConn
    DBConn --> DBMgmt
    DBMgmt --> SQLEngine
    SQLEngine --> ReAct
    ReAct --> MLModels
    
    MLModels --> DriverPerf
    MLModels --> EventPerf
    MLModels --> TelemetryA
    MLModels --> TyrePerf
    MLModels --> WeatherImpact
    
    DriverPerf --> Gradio
    EventPerf --> Gradio
    TelemetryA --> Gradio
    TyrePerf --> Gradio
    WeatherImpact --> Gradio
    
    DriverPerf --> Jupyter
    EventPerf --> Jupyter
    TelemetryA --> Jupyter
    TyrePerf --> Jupyter
    WeatherImpact --> Jupyter

    %% Click Events
    click DB1 "https://github.com/Draichi/formula1-AI/blob/main/db/Bahrain_2023_Q.db"
    click DBConn "https://github.com/Draichi/formula1-AI/blob/main/db/connection.py"
    click DBMgmt "https://github.com/Draichi/formula1-AI/blob/main/db/formula1_databases.py"
    click ReAct "https://github.com/Draichi/formula1-AI/blob/main/agent_prompt.txt"
    click MLModels "https://github.com/Draichi/formula1-AI/tree/main/regression-models"
    click DriverPerf "https://github.com/Draichi/formula1-AI/blob/main/tools/driver_performance.py"
    click EventPerf "https://github.com/Draichi/formula1-AI/blob/main/tools/event_performance.py"
    click TelemetryA "https://github.com/Draichi/formula1-AI/blob/main/tools/telemetry_analysis.py"
    click TyrePerf "https://github.com/Draichi/formula1-AI/blob/main/tools/tyre_performance.py"
    click WeatherImpact "https://github.com/Draichi/formula1-AI/blob/main/tools/weather_impact.py"
    click Gradio "https://github.com/Draichi/formula1-AI/blob/main/app.py"
    click DataStorage "https://github.com/Draichi/formula1-AI/blob/main/db/save_data_database.ipynb"

    %% Legend
    subgraph Legend
        L1[(Database)]:::database
        L2[Processing]:::processing
        L3[Analysis Tool]:::analysis
        L4[User Interface]:::interface
        L5[External System]:::external
    end
```
