# zabogdan/trafficmonitoring architecture

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

- Interactive diagram: https://gitdiagram.com/zabogdan/trafficmonitoring
- Repository: https://github.com/zabogdan/trafficmonitoring

## Overview

##### Main Components

A. Client Side:
- Sensors Module
- GPS Sensor
- Speed Sensor
- Client Commands Handler
- Client Communication Layer (TCP)

B. Server Side:
- Server Core
- Database Handler
- Broadcaster
- Token Management
- Models Layer
- Server Commands Handler

C. Shared Components:
- Communication Protocol (TCP)
- Logger
- Utilities
- Common Types and Structures

**[Client Tier] <---> [Server Tier] <---> [Database Tier]**

##### Detailed Component Relationships

A. Client Architecture:
**[Sensors] -> [StorageBox] -> [Client Commands] -> [TCP Communication]**
- GPS and Speed sensor feeds
- Metric collection flow
- Command processing pipeline

B. Server Architecture:
**[TCP Communication] -> [Server Commands] -> [Models] -> [Database Handler]**
- > [Broadcaster] -> [Token Management]
- Authentication flow
- Broadcast message distribution
- Database interactions

##### Key Features to Emphasize

a) Security Layer:
- Token-based authentication
- Login/Logout flow
- Token invalidation process

b) Data Flow:
- Metric collection and transmission
- Incident reporting
- Settings management
- Broadcast messaging

##### Database Structure
- Main tables (Users, Metrics, Incidents, Preferences, Tokens)
- Relationships between tables
- Data flow directions

##### Implementation Details

Use these symbols:
- Rectangles: Main components
- Diamonds: Decision points

##### Additional Elements

Specialized sections for:
- CPV (Command Pattern Variant) implementation
- Entertainment system integration
- Incident management system
- Metrics collection and analysis

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef client fill:#b3d9ff,stroke:#333,stroke-width:2px
    classDef server fill:#90EE90,stroke:#333,stroke-width:2px
    classDef shared fill:#FFE5B4,stroke:#333,stroke-width:2px
    classDef database fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef security fill:#FFB6C6,stroke:#333,stroke-width:2px

    %% Client Layer
    subgraph ClientLayer
        Sensors["Sensors Module"]
        GPS["GPS Sensor"]:::client
        Speed["Speed Sensor"]:::client
        StorageBox["Storage Box"]:::client
        ClientCommands["Client Commands Handler"]:::client
        ClientComm["Client Communication Layer"]:::client

        Sensors --> |Data| GPS
        Sensors --> |Data| Speed
        GPS & Speed --> StorageBox
        StorageBox --> ClientCommands
        ClientCommands --> ClientComm
    end

    %% Server Layer
    subgraph ServerLayer
        ServerCore["Server Core"]:::server
        DBHandler["Database Handler"]:::server
        Broadcaster["Broadcaster"]:::server
        TokenMgmt["Token Management"]:::security
        ServerCommands["Server Commands Handler"]:::server
        Models["Models Layer"]:::server

        ServerCore --> ServerCommands
        ServerCommands --> Models
        Models --> DBHandler
        ServerCore --> Broadcaster
        TokenMgmt --> ServerCore
    end

    %% Database Layer
    subgraph DatabaseLayer
        DB[(Database)]:::database
        Users[("Users")]:::database
        Metrics[("Metrics")]:::database
        Incidents[("Incidents")]:::database
        Preferences[("Preferences")]:::database
        Tokens[("Tokens")]:::database

        DB --> Users & Metrics & Incidents & Preferences & Tokens
    end

    %% Shared Components
    subgraph SharedComponents
        TCP["Communication Protocol"]:::shared
        Logger["Logger"]:::shared
        Utils["Utilities"]:::shared
        CommonTypes["Common Types"]:::shared
    end

    %% Connections
    ClientComm <--> |TCP| ServerCore
    DBHandler --> DB
    SharedComponents --> ClientLayer
    SharedComponents --> ServerLayer

    %% Click Events
    click GPS "https://github.com/zaBogdan/TrafficMonitoring/blob/master/src/client/lib/includes/sensors/GPSSensor.h"
    click Speed "https://github.com/zaBogdan/TrafficMonitoring/blob/master/src/client/lib/includes/sensors/SpeedSensor.h"
    click StorageBox "https://github.com/zaBogdan/TrafficMonitoring/blob/master/src/client/lib/includes/StorageBox.h"
    click ClientCommands "https://github.com/zaBogdan/TrafficMonitoring/tree/master/src/client/lib/sources/commands/"
    click ServerCore "https://github.com/zaBogdan/TrafficMonitoring/blob/master/src/server/lib/includes/Server.h"
    click DBHandler "https://github.com/zaBogdan/TrafficMonitoring/blob/master/src/server/lib/includes/DBHandler.h"
    click Broadcaster "https://github.com/zaBogdan/TrafficMonitoring/blob/master/src/server/lib/includes/Broadcaster.h"
    click TokenMgmt "https://github.com/zaBogdan/TrafficMonitoring/blob/master/src/server/lib/includes/Tokens.h"
    click Models "https://github.com/zaBogdan/TrafficMonitoring/tree/master/src/server/lib/includes/models/"
    click ServerCommands "https://github.com/zaBogdan/TrafficMonitoring/tree/master/src/server/lib/sources/commands/"
    click TCP "https://github.com/zaBogdan/TrafficMonitoring/blob/master/src/shared/lib/includes/protocols/TCP.h"
    click Logger "https://github.com/zaBogdan/TrafficMonitoring/blob/master/src/shared/lib/includes/Logger.h"
    click CommonTypes "https://github.com/zaBogdan/TrafficMonitoring/blob/master/src/shared/lib/includes/static/structures.h"
    click Utils "https://github.com/zaBogdan/TrafficMonitoring/blob/master/src/shared/lib/includes/Utils.h"

    %% Legend
    subgraph Legend
        Client[Client Components]:::client
        Server[Server Components]:::server
        Shared[Shared Components]:::shared
        Security[Security Components]:::security
        DB2[Database Components]:::database
    end
```
