# salamzantout/smart-traffic-light architecture

> Architecture diagram of the GitHub repository salamzantout/smart-traffic-light, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/salamzantout/smart-traffic-light
- Repository: https://github.com/salamzantout/smart-traffic-light

## Overview

##### Project type and purpose
- This is an IoT-enabled Smart Traffic Light System prototype.
- It uses Arduino Uno boards to sense real-world traffic via distance/vehicle-counting sensors, processes that data, and adjusts traffic light behavior dynamically. There’s also a simple web component (FinalIndex.php) for data display or control.

##### File structure
Top-level artifacts:
- Final Report & Presentation PDFs (documentation)
- README.md (project overview)
- Raw Data/ (experimental & real street datasets)
- Software Code/ (all Arduino sketches and a PHP endpoint)
Under Software Code/:
- CarCountingSensor/CarCountingSensor.ino – counts vehicles
- IncDec/IncDec.pde – incremental/decremental logic (traffic density algorithm)
- InternetConnection/InternetConnection.ino – handles Wi-Fi or serial link to server
- RecFromArd/RecFromArd.pde + data/ – receives and logs data on a host device
- FinalIndex.php – simple web interface for viewing or controlling the system

##### Extract insights from the README
- Purpose: Replace fixed traffic-light cycles with data-driven cycles.
- Hardware: Arduino Uno chosen for sufficiency and simplicity.
- Future: Inter-light communication and V2X (vehicle-to-everything).

##### Main components & their interactions
a. Edge Sensing Layer (Hardware)
- Ultrasonic/vehicle-counting sensor + Arduino Uno (CarCountingSensor)
- Additional Arduino boards for Inc/Dec logic and Internet connectivity
b. Communication Layer
- Arduino → HTTP POST or serial over InternetConnection.ino
- RecFromArd sketch on a gateway device or PC that aggregates incoming data
c. Data Persistence & Processing
- Raw Data files stored locally (Excel, TXT) or in a simple database (optional)
- IncDec logic applies thresholds or statistical models to decide light phases
d. Presentation Layer
- FinalIndex.php: Web interface showing real-time or historical traffic metrics
e. System Documentation
- PDFs (report + presentation) and demo video for stakeholders

##### Key architectural patterns & design principles
- Edge-cloud split: sensing and pre-processing on Arduino (edge), storage/visualization on server (cloud).
- Modular firmware: separate sketches for counting, communication, and control logic.
- Data-driven control loop: measurement → analysis (IncDec) → actuation (traffic light).

##### Technologies & frameworks
- Arduino IDE (C/C++ sketches: .ino, .pde)
- PHP (web endpoint)
- HTTP or serial protocols for IoT messaging
- Excel/TXT for offline data analysis

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Edge Sensing Layer
    subgraph "Edge Sensing Layer"
        direction TB
        Sensor["Ultrasonic Sensor + Arduino\nCarCountingSensor.ino"]:::edge
        Control["Control Logic Module\nIncDec.pde"]:::edge
        Comm["Communication Module\nInternetConnection.ino"]:::edge
    end

    %% Gateway/Processing
    subgraph "Gateway/Processing"
        direction TB
        Aggregator["Data Aggregator\nRecFromArd.pde"]:::server
        RecData["Logged Data\ndata.txt"]:::storage
    end

    %% Storage & Presentation
    Storage["Raw Data Store\n(Raw Data/)"]:::storage
    Web["Web Server\nFinalIndex.php"]:::web
    Browser["Browser UI"]:::web

    %% Documentation
    subgraph "System Documentation"
        direction TB
        Report["Final Report"]:::doc
        Presentation["Presentation"]:::doc
        Overview["Project Overview\nREADME.md"]:::doc
    end

    %% Future Extension
    Future["Neighbor Traffic Lights & Vehicles"]:::future

    %% Connections
    Sensor --> Control
    Control --> Comm
    Comm -->|"HTTP POST / Serial"| Aggregator
    Aggregator --> RecData
    RecData --> Storage
    Storage --> Web
    Web --> Browser
    Future -.-> Comm
    Future -.-> Browser

    %% Click Events
    click Sensor "https://github.com/salamzantout/smart-traffic-light/blob/master/Software Code/CarCountingSensor/CarCountingSensor.ino"
    click Control "https://github.com/salamzantout/smart-traffic-light/blob/master/Software Code/IncDec/IncDec.pde"
    click Comm "https://github.com/salamzantout/smart-traffic-light/blob/master/Software Code/InternetConnection/InternetConnection.ino"
    click Aggregator "https://github.com/salamzantout/smart-traffic-light/blob/master/Software Code/RecFromArd/RecFromArd.pde"
    click RecData "https://github.com/salamzantout/smart-traffic-light/blob/master/Software Code/RecFromArd/data/data.txt"
    click Storage "https://github.com/salamzantout/smart-traffic-light/tree/master/Raw Data/"
    click Web "https://github.com/salamzantout/smart-traffic-light/blob/master/Software Code/FinalIndex.php"
    click Report "https://github.com/salamzantout/smart-traffic-light/blob/master/Final Report-TrafficLightController.pdf"
    click Presentation "https://github.com/salamzantout/smart-traffic-light/blob/master/Presentation-TrafficLightController.pdf"
    click Overview "https://github.com/salamzantout/smart-traffic-light/blob/master/README.md"

    %% Styles
    classDef edge fill:#9f6,stroke:#070,stroke-width:2px;
    classDef server fill:#6cf,stroke:#039,stroke-width:2px;
    classDef web fill:#6c9,stroke:#093,stroke-width:2px;
    classDef storage fill:#f96,stroke:#f60,stroke-width:2px;
    classDef doc fill:#ccc,stroke:#999,stroke-width:1px;
    classDef future fill:transparent,stroke:#f00,stroke-dasharray:5 5;
```
