# anilmisirlioglu/f1-telemetry-go architecture

> Architecture diagram of the GitHub repository anilmisirlioglu/f1-telemetry-go, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anilmisirlioglu/f1-telemetry-go
- Repository: https://github.com/anilmisirlioglu/f1-telemetry-go

## Overview

##### Main Components
- UDP Listener Module – Represented by files in the “internal/udp” folder. This component is responsible for opening the UDP socket, receiving packets from the F1 game, and doing some low-level decoding (e.g., the “binary.go” files, stats monitoring, etc.).
- Packet Parser – Shown by “pkg/packets”. These files contain logic for parsing different telemetry packets (e.g., car telemetry, car damage, lap data) and converting raw UDP data into structured formats.
- Environment Constants & Models – Found in “pkg/env”. This group of packages provides the constants and string conversion functionality for various telemetry elements (drivers, cars, events, flags, sessions, etc.) that standardize the telemetry data.
- Event Dispatcher – In “internal/event”. The event dispatcher implements the Observer pattern so that client-provided handlers (callbacks) get notified when certain telemetry packets are received.
- Telemetry Client API – Located in “pkg/telemetry”. It ties together the UDP listener, packet parsing, and dispatching to expose a simple API (e.g., “NewClient”, “Run”, “OnEventPacket”, etc.) for external consumer applications.

##### Component Relationships and Data Flow
- Utility Components: The Environment Constants/Models module (from “pkg/env”) and the Math modules (from “pkg/math”) support all the above components, so include them as shared libraries that provide key domain data and operations.

##### Architectural Patterns and Design Principles
- Observer Pattern – The event dispatcher design, which allows dynamic registration of callbacks for particular telemetry events.
- Layered Design – Separation between the network I/O layer (UDP listener), the processing layer (parsers and math computations), and the application integration layer (telemetry client API and public sample-app).
- Modularity – Each domain (car, driver, event, track, etc.) is encapsulated in its own subdirectory within “pkg/env”, enabling clear separation of concerns and easy maintainability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Data Source
    subgraph "External Data Sources"
        FG["F1 Game (UDP Stream)"]:::external
    end

    %% Core Telemetry Processing Components
    subgraph "Core Telemetry Processing"
        UL["UDP Listener"]:::core
        PP["Packet Parser"]:::core
        ED["Event Dispatcher"]:::core
        TA["Telemetry Client API"]:::core
    end

    %% Supporting Libraries
    subgraph "Support Libraries"
        EC["Environment Constants & Models"]:::support
        UM["Utility Math Functions"]:::support
    end

    %% Client Application & Deployments
    subgraph "Client Applications"
        SA["Sample Application & Deployment"]:::client
    end

    %% Data flow connections
    FG -->|"receives"| UL
    UL -->|"parses"| PP
    PP -->|"generates events"| ED
    ED -->|"notifies"| TA
    TA -->|"exposes events"| SA

    %% Support library connections (dashed for utility)
    EC --- PP
    EC --- TA
    UM --- PP
    UM --- UL

    %% Styles
    classDef external fill:#A3E4D7,stroke:#138D75,stroke-width:2px;
    classDef core fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef support fill:#AED6F1,stroke:#3498DB,stroke-width:2px;
    classDef client fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;

    %% Click Events
    click UL "https://github.com/anilmisirlioglu/f1-telemetry-go/tree/master/internal/udp"
    click PP "https://github.com/anilmisirlioglu/f1-telemetry-go/tree/master/pkg/packets"
    click ED "https://github.com/anilmisirlioglu/f1-telemetry-go/tree/master/internal/event"
    click TA "https://github.com/anilmisirlioglu/f1-telemetry-go/tree/master/pkg/telemetry"
    click EC "https://github.com/anilmisirlioglu/f1-telemetry-go/tree/master/pkg/env"
    click UM "https://github.com/anilmisirlioglu/f1-telemetry-go/tree/master/pkg/math"
    click SA "https://github.com/anilmisirlioglu/f1-telemetry-go/tree/master/sample-app"
```
