# jolpica/jolpica-f1 architecture

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

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

## Overview

##### Main Components (Top Level)

a) Client Layer:
- External API consumers
- Web browsers (for API documentation)

b) Application Layer:
- API Gateway/Load Balancer
- Django Web Server (Gunicorn)
- Redis (for rate limiting)

c) Data Layer:
- PostgreSQL Database (with PostGIS extension)
- Data Import System

##### Core Services (Second Level)

a) API Services:
- Ergast Compatible API (`jolpica_api/ergastapi/`)
- Authentication Service (`jolpica_api/authentication/`)
- Rate Limiting System

b) Data Management:
- Formula One Data Manager (`jolpica/formula_one/`)
- Ergast Data Manager (`jolpica/ergast/`)
- Data Import/Update System

##### Key Architectural Elements to Highlight

a) Data Flow:
- How requests flow from clients through authentication/rate limiting
- Data paths between API endpoints and database
- Data import process from Ergast to the new schema

b) Database Structure:
- A simplified version of the database scheme shown in the README
- Models: Circuits, Drivers, Teams, Races, Results
- Relationship between Ergast-compatible models and new schema

##### Specific Implementation Details

- Blue rectangles: External interfaces (API endpoints)
- Green rectangles: Core services
- Red diamonds: Security/authentication components
- Purple rectangles: Data processing systems

##### Important Flows

a) Runtime Flow:
**Client Request → Rate Limiting → Authentication → API Endpoint → Data Access → Response**

b) Data Import Flow:
**Ergast Data Source → Import System → Data Transformation → New Schema Storage**

##### Additional Elements

- Notes about key technologies (Django, PostgreSQL/PostGIS, Redis)
- Environment configurations (dev container, production)

**┌─────────────────────────────────────────┐**
- Client Layer               │
- ┘
- ↓
**┌─────────────────────────────────────────┐**
- Security & Rate Limiting        │
- ┘
- ↓
**┌─────────────────────────────────────────┐**
- API Services Layer           │
- ┘
- ↓
**┌─────────────────────────────────────────┐**
- Data Manager Layer            │
- ┘
- ↓
**┌─────────────────────────────────────────┐**
- Database Layer              │
- ┘

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph CL[Client Layer]
        Client[API Consumers]
        Browser["Web Browser"]
    end

    %% Security Layer
    subgraph SL[Security & Rate Limiting Layer]
        Auth["Authentication Service"]:::auth
        RateLimit["Rate Limiting Service"]:::security
        Redis[(Redis Cache)]:::db
    end

    %% API Layer
    subgraph AL[API Services Layer]
        APIGateway["API Gateway"]:::gateway
        WebServer["Gunicorn Web Server"]:::server
        APIDoc["API Documentation Interface"]:::doc
        ErgastAPI["Ergast Compatible API"]:::api
        URLRouter["URL Router"]:::router
        APIViews["API Views"]:::api
        Serializers["API Serializers"]:::api
    end

    %% Data Management Layer
    subgraph DML[Data Management Layer]
        F1Manager["Formula One Data Manager"]:::manager
        ErgastManager["Ergast Data Manager"]:::manager
        DataImport["Data Import System"]:::import
        DataUpdate["Data Update System"]:::import
    end

    %% Database Layer
    subgraph DBL[Database Layer]
        PostgreSQL[(PostgreSQL + PostGIS)]:::db
        subgraph Models[Database Models]
            Circuit["Circuit Model"]:::model
            Driver["Driver Model"]:::model
            Team["Team Model"]:::model
            Round["Round Model"]:::model
            Session["Session Model"]:::model
            Lap["Lap Model"]:::model
            PitStop["Pit Stop Model"]:::model
        end
    end

    %% Relationships
    Client --> APIGateway
    Browser --> APIDoc
    APIGateway --> Auth
    APIGateway --> RateLimit
    RateLimit --> Redis
    Auth --> WebServer
    RateLimit --> WebServer
    WebServer --> URLRouter
    URLRouter --> ErgastAPI
    ErgastAPI --> APIViews
    APIViews --> Serializers
    Serializers --> F1Manager
    F1Manager --> PostgreSQL
    ErgastManager --> PostgreSQL
    DataImport --> ErgastManager
    DataUpdate --> ErgastManager
    
    %% Styles
    classDef gateway fill:#6E6E6E,stroke:#333,stroke-width:2px
    classDef server fill:#95A5A6,stroke:#333,stroke-width:2px
    classDef api fill:#3498DB,stroke:#333,stroke-width:2px
    classDef auth fill:#E74C3C,stroke:#333,stroke-width:2px
    classDef security fill:#F1C40F,stroke:#333,stroke-width:2px
    classDef db fill:#2ECC71,stroke:#333,stroke-width:2px
    classDef manager fill:#9B59B6,stroke:#333,stroke-width:2px
    classDef import fill:#E67E22,stroke:#333,stroke-width:2px
    classDef model fill:#1ABC9C,stroke:#333,stroke-width:2px
    classDef doc fill:#34495E,stroke:#333,stroke-width:2px
    classDef router fill:#95A5A6,stroke:#333,stroke-width:2px

    %% Click Events
    click APIDoc "https://github.com/jolpica/jolpica-f1/blob/main/jolpica_api/static/index.html"
    click WebServer "https://github.com/jolpica/jolpica-f1/blob/main/gunicorn.conf.py"
    click RateLimit "https://github.com/jolpica/jolpica-f1/blob/main/jolpica_api/authentication/throttles.py"
    click Auth "https://github.com/jolpica/jolpica-f1/tree/main/jolpica_api/authentication/"
    click ErgastAPI "https://github.com/jolpica/jolpica-f1/tree/main/jolpica_api/ergastapi/"
    click F1Manager "https://github.com/jolpica/jolpica-f1/tree/main/jolpica/formula_one/"
    click ErgastManager "https://github.com/jolpica/jolpica-f1/tree/main/jolpica/ergast/"
    click DataImport "https://github.com/jolpica/jolpica-f1/blob/main/jolpica/formula_one/import_from_ergast.py"
    click Redis "https://github.com/jolpica/jolpica-f1/tree/main/.devcontainer/redis/"
    click Circuit "https://github.com/jolpica/jolpica-f1/blob/main/jolpica/formula_one/models/circuit.py"
    click Driver "https://github.com/jolpica/jolpica-f1/blob/main/jolpica/formula_one/models/driver.py"
    click Team "https://github.com/jolpica/jolpica-f1/blob/main/jolpica/formula_one/models/team.py"
    click Round "https://github.com/jolpica/jolpica-f1/blob/main/jolpica/formula_one/models/round.py"
    click Session "https://github.com/jolpica/jolpica-f1/blob/main/jolpica/formula_one/models/session.py"
    click Lap "https://github.com/jolpica/jolpica-f1/blob/main/jolpica/formula_one/models/lap.py"
    click PitStop "https://github.com/jolpica/jolpica-f1/blob/main/jolpica/formula_one/models/pit_stop.py"
    click DataUpdate "https://github.com/jolpica/jolpica-f1/blob/main/jolpica/ergast/management/commands/updateergast.py"
    click Serializers "https://github.com/jolpica/jolpica-f1/blob/main/jolpica_api/ergastapi/serializers.py"
    click APIViews "https://github.com/jolpica/jolpica-f1/blob/main/jolpica_api/ergastapi/views.py"
    click URLRouter "https://github.com/jolpica/jolpica-f1/blob/main/jolpica_api/urls.py"
```
