# enghuss20/aghe architecture

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

- Interactive diagram: https://gitdiagram.com/enghuss20/aghe
- Repository: https://github.com/enghuss20/aghe

## Overview

##### Main Components
- Two core hardware modules:
- Arduino Mega Parking Management System – responsible for handling RFID entry/exit, slot monitoring with LDR sensors, emergency detection (via gas and flame sensors), gate control via servo motors, and display updates.
- ESP32 Communication System – tasked with receiving JSON data from the Arduino Mega over the serial interface and uploading this data to ThingSpeak for remote monitoring.
- Peripheral hardware (sensors, displays, RFID readers, servos, etc.) integrated with the Arduino Mega.
- External services (e.g., ThingSpeak for data visualization and remote monitoring).

##### Out Relationships and Data Flows
- Bidirectional communications for debugging or configuration (e.g., Serial debugging lines) if necessary.

##### Architectural Patterns and Technologies
- Separation of concerns: Arduino Mega focuses on real-time sensor data acquisition and local control logic while the ESP32 is dedicated to connectivity and cloud integration.
- That each microcontroller uses its own set of Arduino libraries:
- Arduino Mega uses libraries such as SPI, MFRC522, Servo, ArduinoJson, LiquidCrystal_I2C.
- ESP32 uses libraries like ArduinoJson, WiFi, and ThingSpeak.
- These indicate a modular design where both controlled hardware components and external services are clearly demarcated.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Sensors & Actuators
    subgraph "Sensors & Actuators"
        RFID["RFID Reader (Pins: 52,51,50,7/10,6/9)"]:::sensor
        LDR["LDR Sensors (Analog A0-A4)"]:::sensor
        GasFlame["Gas Sensor (A5) / Flame Sensor (A6)"]:::sensor
        Servo["Servo Motors (Entrance:3, Exit:4, Emergency:2)"]:::actuator
        Displays["Displays (LCD_I2C, LED, 7-Segment)"]:::actuator
    end

    %% Arduino Mega System
    subgraph "Arduino Mega System"
        AM["Arduino Mega Controller"]:::microcontroller
        MegaCode["Mega Code"]:::code
        MegaReadme["Mega README"]:::doc
    end

    %% ESP32 Communication System
    subgraph "ESP32 Communication System"
        ESP["ESP32 Communication Controller"]:::microcontroller
        ESPCode["ESP32 Code"]:::code
        ESPReadme["ESP32 README"]:::doc
        ThingSpeakModule["ThingSpeak Upload Module"]:::comm
    end

    %% Simulation & Testing
    subgraph "Simulation & Testing"
        MATSim["MATLAB/ASP Simulation"]:::simulation
        TestData["Test Data Configuration"]:::test
    end

    %% External Cloud
    TS["ThingSpeak Cloud"]:::cloud

    %% Data Flows from Sensors to Arduino Mega
    RFID -->|"Sensor_Data"| AM
    LDR -->|"Sensor_Data"| AM
    GasFlame -->|"Sensor_Data"| AM
    Servo -->|"Actuation_Signal"| AM
    Displays -->|"Display_Update"| AM

    %% Arduino Mega processing and communication
    MegaCode -->|"Internal_Code"| AM
    MegaReadme -->|"Docs"| AM

    %% Serial communication from Arduino Mega to ESP32
    AM -->|"Serial_JSON_Data"| ESP

    %% ESP32 processing and uploading to cloud
    ESPCode -->|"Internal_Code"| ESP
    ESPReadme -->|"Docs"| ESP
    ESP -->|"Data_Upload"| ThingSpeakModule
    ThingSpeakModule -->|"Upload"| TS

    %% Simulation & Testing flows
    TestData -->|"Test_Config"| MATSim
    MATSim -->|"Simulated_Input"| AM

    %% Click Events
    click MegaCode "https://github.com/enghuss20/aghe/blob/main/Arduino_Mega/Mega_Comm_2/Mega_Comm_2.ino"
    click MegaReadme "https://github.com/enghuss20/aghe/blob/main/Arduino_Mega/README.md"
    click ESPCode "https://github.com/enghuss20/aghe/blob/main/ESP32/ESP32_Comm_2/ESP32_Comm_2.ino"
    click ESPReadme "https://github.com/enghuss20/aghe/blob/main/ESP32/README.md"
    click MATSim "https://github.com/enghuss20/aghe/blob/main/parking_system_matlap_asp_project.m"
    click TestData "https://github.com/enghuss20/aghe/blob/main/testData.json"

    %% Class Definitions
    classDef sensor fill:#f0e68c,stroke:#b8860b,stroke-width:2px;
    classDef actuator fill:#ffd700,stroke:#daa520,stroke-width:2px;
    classDef microcontroller fill:#add8e6,stroke:#00008b,stroke-width:2px;
    classDef code fill:#90ee90,stroke:#006400,stroke-width:2px;
    classDef doc fill:#ffb6c1,stroke:#8b0000,stroke-width:2px;
    classDef comm fill:#ffa07a,stroke:#cd5c5c,stroke-width:2px;
    classDef cloud fill:#d3d3d3,stroke:#696969,stroke-width:2px;
    classDef simulation fill:#e6e6fa,stroke:#8a2be2,stroke-width:2px;
    classDef test fill:#fafad2,stroke:#d2691e,stroke-width:2px;
    
    class RFID,LDR,GasFlame sensor;
    class Servo,Displays actuator;
    class AM,ESP microcontroller;
    class MegaCode,ESPCode code;
    class MegaReadme,ESPReadme doc;
    class ThingSpeakModule comm;
    class TS cloud;
    class MATSim simulation;
    class TestData test;
```
