# hnainiamohamedamine29/esp32_mqtt_iot architecture

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

- Interactive diagram: https://gitdiagram.com/hnainiamohamedamine29/esp32_mqtt_iot
- Repository: https://github.com/hnainiamohamedamine29/esp32_mqtt_iot

## Overview

This small ESP32 firmware connects to Wi-Fi, maintains an MQTT connection, publishes `sensor/status`, and handles `device/led` commands by setting the onboard LED. The sampled source shows the main runtime stages and their calls; README documents the broker/client arrangement and reconnection behavior. All firmware responsibilities share `src/main.cpp`; external network components are shown separately.

Main entry points: [`src/main.cpp`](https://github.com/hnainiamohamedamine29/esp32_mqtt_iot/blob/main/src/main.cpp) (MQTT Client), [`include/config.h`](https://github.com/hnainiamohamedamine29/esp32_mqtt_iot/blob/main/include/config.h) (Network Config)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_firmware["ESP32 Firmware"]
  node_device["ESP32 Runtime<br/>[main.cpp]"]
  node_wifi["Wi-Fi Setup<br/>[main.cpp]"]
  node_mqtt["MQTT Client<br/>[main.cpp]"]
  node_led["LED Handler<br/>[main.cpp]"]
  node_config["Network Config<br/>[config.h]"]
end

subgraph group_network["Network Services"]
  node_wireless{{"Wi-Fi Network"}}
  node_broker{{"MQTT Broker"}}
  node_ledhw["GPIO LED"]
end

node_operator(("MQTT Dashboard"))

node_device -->|"starts Wi-Fi"| node_wifi
node_device -->|"configures client"| node_mqtt
node_wifi -->|"reads credentials"| node_config
node_mqtt -->|"reads broker settings"| node_config
node_wifi -->|"connects to"| node_wireless
node_device -->|"checks connection"| node_mqtt
node_mqtt -->|"connects and subscribes"| node_broker
node_mqtt -->|"publishes status"| node_broker
node_operator -->|"sends commands"| node_broker
node_broker -->|"delivers LED command"| node_led
node_led -->|"sets GPIO 2"| node_ledhw

click node_device "https://github.com/hnainiamohamedamine29/esp32_mqtt_iot/blob/main/src/main.cpp"
click node_wifi "https://github.com/hnainiamohamedamine29/esp32_mqtt_iot/blob/main/src/main.cpp"
click node_mqtt "https://github.com/hnainiamohamedamine29/esp32_mqtt_iot/blob/main/src/main.cpp"
click node_led "https://github.com/hnainiamohamedamine29/esp32_mqtt_iot/blob/main/src/main.cpp"
click node_config "https://github.com/hnainiamohamedamine29/esp32_mqtt_iot/blob/main/include/config.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_device,node_wifi,node_mqtt,node_led,node_config toneBlue
class node_wireless,node_broker,node_ledhw toneAmber
class node_operator toneIndigo
```

## Components

### ESP32 Firmware

- [ESP32 Runtime](https://github.com/hnainiamohamedamine29/esp32_mqtt_iot/blob/main/src/main.cpp): `src/main.cpp`
- [Wi-Fi Setup](https://github.com/hnainiamohamedamine29/esp32_mqtt_iot/blob/main/src/main.cpp): `src/main.cpp`
- [MQTT Client](https://github.com/hnainiamohamedamine29/esp32_mqtt_iot/blob/main/src/main.cpp): `src/main.cpp`
- [LED Handler](https://github.com/hnainiamohamedamine29/esp32_mqtt_iot/blob/main/src/main.cpp): `src/main.cpp`
- [Network Config](https://github.com/hnainiamohamedamine29/esp32_mqtt_iot/blob/main/include/config.h): `include/config.h`

### Network Services

- **Wi-Fi Network**
- **MQTT Broker**
- **GPIO LED**

### Other components

- **MQTT Dashboard**

## Connections

- ESP32 Runtime → Wi-Fi Setup: starts Wi-Fi (evidence: `src/main.cpp`)
- ESP32 Runtime → MQTT Client: configures client (evidence: `src/main.cpp`)
- Wi-Fi Setup → Network Config: reads credentials (evidence: `src/main.cpp`)
- MQTT Client → Network Config: reads broker settings (evidence: `src/main.cpp`)
- Wi-Fi Setup → Wi-Fi Network: connects to (evidence: `src/main.cpp`)
- ESP32 Runtime → MQTT Client: checks connection (evidence: `src/main.cpp`)
- MQTT Client → MQTT Broker: connects and subscribes (evidence: `src/main.cpp`)
- MQTT Client → MQTT Broker: publishes status (evidence: `src/main.cpp`)
- MQTT Dashboard → MQTT Broker: sends commands (evidence: `README.md`)
- MQTT Broker → LED Handler: delivers LED command (evidence: `src/main.cpp`)
- LED Handler → GPIO LED: sets GPIO 2 (evidence: `src/main.cpp`)
