# jhony-saba/smart-home-system architecture

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

- Interactive diagram: https://gitdiagram.com/jhony-saba/smart-home-system
- Repository: https://github.com/jhony-saba/smart-home-system

## Overview

This is an ESP32-based smart-home prototype with a web interface for monitoring sensors and controlling household devices. The main workflow is user login, room or device selection (or a natural-language command), server-side validation and safety checks, command dispatch to the ESP32, and persistence of device state in MySQL. Sensor readings also feed tank-safety behavior and notification thresholds. The README documents broader energy-efficiency and safety goals; source excerpts show only some of those paths, so uncertain wiring is omitted.

Main entry points: [`phpFolder/connection.php`](https://github.com/jhony-saba/smart-home-system/blob/main/phpFolder/connection.php) (Database connection), [`connection/sendData.php`](https://github.com/jhony-saba/smart-home-system/blob/main/connection/sendData.php) (Device command sender), [`phpFolder/Tank.php`](https://github.com/jhony-saba/smart-home-system/blob/main/phpFolder/Tank.php) (Tank and pump safety), [`phpFolder`](https://github.com/jhony-saba/smart-home-system/tree/main/phpFolder) (Room device APIs)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_web_ui["Home interface"]
  node_room_js["Room controls"]
  node_login_ui["Login screen<br/>[Login.html]"]
end

subgraph group_server["Application services"]
  node_login["Login service<br/>[Login.php]"]
  node_main_gate["Session gate<br/>[Main.php]"]
  node_room_services["Room device APIs"]
  node_door_service["Door authorization<br/>[MainDoor.php]"]
  node_tank_service["Tank and pump safety<br/>[Tank.php]"]
  node_command_service["Text command handler<br/>[sendCommand.php]"]
  node_profile_service["Profile management<br/>[profile.php]"]
  node_alert_service["Sensor notifications<br/>[notification.php]"]
  node_sensor_api["Sensor endpoint<br/>[sensor.php]"]
end

subgraph group_device["Device and sensing"]
  node_esp_firmware["ESP32 firmware<br/>[main.cpp]"]
  node_sensors{{"Home sensors"}}
  node_actuators["Home actuators"]
end

subgraph group_data["Persistence and transport"]
  node_command_transport["Device command sender<br/>[sendData.php]"]
  node_db_helpers["Database connection<br/>[connection.php]"]
  node_mysql[("MySQL store")]
  node_sensor_ingest["Sensor data receiver<br/>[sendData.php]"]
end

node_resident(("Resident"))

node_resident -->|"opens"| node_login_ui
node_login_ui -.->|"submits credentials"| node_login
node_login -->|"connects through"| node_db_helpers
node_db_helpers -->|"opens connection"| node_mysql
node_resident -->|"uses"| node_web_ui
node_web_ui -.->|"uses controls"| node_room_js
node_room_js -.->|"requests device actions"| node_room_services
node_room_services -->|"queries and updates"| node_db_helpers
node_room_services -->|"sends commands"| node_command_transport
node_door_service -->|"checks access and state"| node_db_helpers
node_door_service -->|"dispatches door command"| node_command_transport
node_tank_service -->|"reads and updates pump"| node_db_helpers
node_tank_service -->|"forces pump off"| node_command_transport
node_command_service -->|"reads and updates devices"| node_db_helpers
node_command_service -->|"dispatches command"| node_command_transport
node_profile_service -->|"manages user records"| node_db_helpers
node_main_gate -->|"serves after session check"| node_web_ui
node_main_gate -->|"redirects when unauthenticated"| node_login_ui
node_alert_service -->|"reads sensor values"| node_db_helpers
node_sensor_api -->|"uses database"| node_db_helpers
node_command_transport -.->|"HTTP command"| node_esp_firmware
node_esp_firmware -.->|"controls"| node_actuators
node_sensors -.->|"sends readings"| node_sensor_ingest
node_sensor_ingest -.->|"stores readings"| node_mysql
node_tank_service -.->|"checks tank safety"| node_sensors
node_alert_service -.->|"provides alerts"| node_resident

click node_web_ui "https://github.com/jhony-saba/smart-home-system/tree/main/htmlFolder"
click node_room_js "https://github.com/jhony-saba/smart-home-system/tree/main/JsFolder"
click node_login_ui "https://github.com/jhony-saba/smart-home-system/blob/main/htmlFolder/Login.html"
click node_login "https://github.com/jhony-saba/smart-home-system/blob/main/phpFolder/Login.php"
click node_main_gate "https://github.com/jhony-saba/smart-home-system/blob/main/phpFolder/Main.php"
click node_room_services "https://github.com/jhony-saba/smart-home-system/tree/main/phpFolder"
click node_door_service "https://github.com/jhony-saba/smart-home-system/blob/main/phpFolder/MainDoor.php"
click node_tank_service "https://github.com/jhony-saba/smart-home-system/blob/main/phpFolder/Tank.php"
click node_command_service "https://github.com/jhony-saba/smart-home-system/blob/main/phpFolder/sendCommand.php"
click node_profile_service "https://github.com/jhony-saba/smart-home-system/blob/main/phpFolder/profile.php"
click node_alert_service "https://github.com/jhony-saba/smart-home-system/blob/main/phpFolder/notification.php"
click node_sensor_api "https://github.com/jhony-saba/smart-home-system/blob/main/phpFolder/sensor.php"
click node_esp_firmware "https://github.com/jhony-saba/smart-home-system/blob/main/cpp/send/src/main.cpp"
click node_command_transport "https://github.com/jhony-saba/smart-home-system/blob/main/connection/sendData.php"
click node_db_helpers "https://github.com/jhony-saba/smart-home-system/blob/main/phpFolder/connection.php"
click node_sensor_ingest "https://github.com/jhony-saba/smart-home-system/blob/main/connection/sendData.php"

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_web_ui,node_room_js,node_login_ui toneBlue
class node_login,node_main_gate,node_room_services,node_door_service,node_tank_service,node_command_service,node_profile_service,node_alert_service,node_sensor_api toneAmber
class node_esp_firmware,node_sensors,node_actuators toneMint
class node_command_transport,node_db_helpers,node_mysql,node_sensor_ingest toneRose
class node_resident toneIndigo
```

## Components

### Web interface

- [Home interface](https://github.com/jhony-saba/smart-home-system/tree/main/htmlFolder): `htmlFolder`
- [Room controls](https://github.com/jhony-saba/smart-home-system/tree/main/JsFolder): `JsFolder`
- [Login screen](https://github.com/jhony-saba/smart-home-system/blob/main/htmlFolder/Login.html): `htmlFolder/Login.html`

### Application services

- [Login service](https://github.com/jhony-saba/smart-home-system/blob/main/phpFolder/Login.php): `phpFolder/Login.php`
- [Session gate](https://github.com/jhony-saba/smart-home-system/blob/main/phpFolder/Main.php): `phpFolder/Main.php`
- [Room device APIs](https://github.com/jhony-saba/smart-home-system/tree/main/phpFolder): `phpFolder`
- [Door authorization](https://github.com/jhony-saba/smart-home-system/blob/main/phpFolder/MainDoor.php): `phpFolder/MainDoor.php`
- [Tank and pump safety](https://github.com/jhony-saba/smart-home-system/blob/main/phpFolder/Tank.php): `phpFolder/Tank.php`
- [Text command handler](https://github.com/jhony-saba/smart-home-system/blob/main/phpFolder/sendCommand.php): `phpFolder/sendCommand.php`
- [Profile management](https://github.com/jhony-saba/smart-home-system/blob/main/phpFolder/profile.php): `phpFolder/profile.php`
- [Sensor notifications](https://github.com/jhony-saba/smart-home-system/blob/main/phpFolder/notification.php): `phpFolder/notification.php`
- [Sensor endpoint](https://github.com/jhony-saba/smart-home-system/blob/main/phpFolder/sensor.php): `phpFolder/sensor.php`

### Device and sensing

- [ESP32 firmware](https://github.com/jhony-saba/smart-home-system/blob/main/cpp/send/src/main.cpp): `cpp/send/src/main.cpp`
- **Home sensors**
- **Home actuators**

### Persistence and transport

- [Device command sender](https://github.com/jhony-saba/smart-home-system/blob/main/connection/sendData.php): `connection/sendData.php`
- [Database connection](https://github.com/jhony-saba/smart-home-system/blob/main/phpFolder/connection.php): `phpFolder/connection.php`
- **MySQL store**
- [Sensor data receiver](https://github.com/jhony-saba/smart-home-system/blob/main/connection/sendData.php): `connection/sendData.php`

### Other components

- **Resident**

## Connections

- Resident → Login screen: opens (evidence: `README.md`)
- Login screen → Login service: submits credentials
- Login service → Database connection: connects through (evidence: `phpFolder/Login.php`)
- Database connection → MySQL store: opens connection (evidence: `phpFolder/connection.php`)
- Resident → Home interface: uses (evidence: `README.md`)
- Home interface → Room controls: uses controls
- Room controls → Room device APIs: requests device actions
- Room device APIs → Database connection: queries and updates (evidence: `phpFolder/Bedroom.php`)
- Room device APIs → Device command sender: sends commands (evidence: `phpFolder/Bedroom.php`)
- Door authorization → Database connection: checks access and state (evidence: `phpFolder/MainDoor.php`)
- Door authorization → Device command sender: dispatches door command (evidence: `phpFolder/MainDoor.php`)
- Tank and pump safety → Database connection: reads and updates pump (evidence: `phpFolder/Tank.php`)
- Tank and pump safety → Device command sender: forces pump off (evidence: `phpFolder/Tank.php`)
- Text command handler → Database connection: reads and updates devices (evidence: `phpFolder/sendCommand.php`)
- Text command handler → Device command sender: dispatches command (evidence: `phpFolder/sendCommand.php`)
- Profile management → Database connection: manages user records (evidence: `phpFolder/profile.php`)
- Session gate → Home interface: serves after session check (evidence: `phpFolder/Main.php`)
- Session gate → Login screen: redirects when unauthenticated (evidence: `phpFolder/Main.php`)
- Sensor notifications → Database connection: reads sensor values (evidence: `phpFolder/notification.php`)
- Sensor endpoint → Database connection: uses database (evidence: `phpFolder/sensor.php`)
- Device command sender → ESP32 firmware: HTTP command
- ESP32 firmware → Home actuators: controls (evidence: `README.md`)
- Home sensors → Sensor data receiver: sends readings (evidence: `README.md`)
- Sensor data receiver → MySQL store: stores readings
- Tank and pump safety → Home sensors: checks tank safety
- Sensor notifications → Resident: provides alerts (evidence: `README.md`)
