# cb240002-create/esp32_mc_db architecture

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

- Interactive diagram: https://gitdiagram.com/cb240002-create/esp32_mc_db
- Repository: https://github.com/cb240002-create/esp32_mc_db

## Overview

This repository implements an ESP32 HVAC/SCADA monitor with a PHP web dashboard, HTTP endpoints, and MySQL-backed live readings and history. The main visible workflow is the dashboard issuing a COM1 relay command, which the endpoint validates and stores; the ESP32 reporting sensor and actuator state is also represented by an ingestion endpoint that updates live state and periodically records history. The dashboard excerpt shows live controls and chart/log features, but not all their requests. Device-to-server wiring is therefore unverified; the Arduino source is present in the tree but was not sampled.

Main entry points: [`database.php`](https://github.com/cb240002-create/esp32_mc_db/blob/main/database.php) (PDO connection), [`updateSCD40data_and_recordtable.php`](https://github.com/cb240002-create/esp32_mc_db/blob/main/updateSCD40data_and_recordtable.php) (Reading ingestion), [`updateCOM1.php`](https://github.com/cb240002-create/esp32_mc_db/blob/main/updateCOM1.php) (COM1 command), [`recordtable.php`](https://github.com/cb240002-create/esp32_mc_db/blob/main/recordtable.php) (Audit log view)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Dashboard"]
  node_entry["Web entry redirect<br/>[index.php]"]
  node_dashboard["HVAC dashboard<br/>[home.php]"]
  node_audit["Audit log view<br/>[recordtable.php]"]
end

subgraph group_api["HTTP endpoints"]
  node_live_api["Live readings API<br/>[get_scd40_data.php]"]
  node_legacy_api["Legacy readings API<br/>[getdata.php]"]
  node_history_api["History API<br/>[gethistory.php]"]
  node_ingest_api["Reading ingestion"]
  node_setpoints_api["Setpoint updates"]
  node_relay_api["COM1 command<br/>[updateCOM1.php]"]
end

subgraph group_device["ESP32 firmware"]
  node_firmware["ESP32 firmware"]
end

subgraph group_storage["Persistence"]
  node_db_helper["PDO connection<br/>[database.php]"]
  node_mysql[("MySQL database")]
end

node_operator(("Operator"))

node_operator -->|"opens"| node_entry
node_entry -->|"redirects"| node_dashboard
node_dashboard -->|"posts command"| node_relay_api
node_firmware -.->|"reports readings"| node_ingest_api
node_live_api -->|"opens connection"| node_db_helper
node_legacy_api -->|"opens connection"| node_db_helper
node_history_api -->|"opens connection"| node_db_helper
node_ingest_api -->|"opens connection"| node_db_helper
node_setpoints_api -->|"opens connection"| node_db_helper
node_relay_api -->|"opens connection"| node_db_helper
node_audit -->|"opens connection"| node_db_helper
node_db_helper -->|"connects to"| node_mysql
node_ingest_api -->|"updates and records"| node_mysql
node_live_api -->|"reads live state"| node_mysql
node_legacy_api -->|"reads device state"| node_mysql
node_history_api -->|"reads history"| node_mysql
node_setpoints_api -->|"writes setpoints"| node_mysql
node_relay_api -->|"writes relay state"| node_mysql
node_audit -->|"reads audit records"| node_mysql

click node_entry "https://github.com/cb240002-create/esp32_mc_db/blob/main/index.php"
click node_dashboard "https://github.com/cb240002-create/esp32_mc_db/blob/main/home.php"
click node_audit "https://github.com/cb240002-create/esp32_mc_db/blob/main/recordtable.php"
click node_firmware "https://github.com/cb240002-create/esp32_mc_db/blob/main/ESP32_HVAC_SCD40/ESP32_HVAC_SCD40.ino"
click node_live_api "https://github.com/cb240002-create/esp32_mc_db/blob/main/get_scd40_data.php"
click node_legacy_api "https://github.com/cb240002-create/esp32_mc_db/blob/main/getdata.php"
click node_history_api "https://github.com/cb240002-create/esp32_mc_db/blob/main/gethistory.php"
click node_ingest_api "https://github.com/cb240002-create/esp32_mc_db/blob/main/updateSCD40data_and_recordtable.php"
click node_setpoints_api "https://github.com/cb240002-create/esp32_mc_db/blob/main/updateSetpoints.php"
click node_relay_api "https://github.com/cb240002-create/esp32_mc_db/blob/main/updateCOM1.php"
click node_db_helper "https://github.com/cb240002-create/esp32_mc_db/blob/main/database.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_entry,node_dashboard,node_audit toneBlue
class node_live_api,node_legacy_api,node_history_api,node_ingest_api,node_setpoints_api,node_relay_api toneAmber
class node_firmware toneMint
class node_db_helper,node_mysql toneRose
class node_operator toneIndigo
```

## Components

### Dashboard

- [Web entry redirect](https://github.com/cb240002-create/esp32_mc_db/blob/main/index.php): `index.php`
- [HVAC dashboard](https://github.com/cb240002-create/esp32_mc_db/blob/main/home.php): `home.php`
- [Audit log view](https://github.com/cb240002-create/esp32_mc_db/blob/main/recordtable.php): `recordtable.php`

### HTTP endpoints

- [Live readings API](https://github.com/cb240002-create/esp32_mc_db/blob/main/get_scd40_data.php): `get_scd40_data.php`
- [Legacy readings API](https://github.com/cb240002-create/esp32_mc_db/blob/main/getdata.php): `getdata.php`
- [History API](https://github.com/cb240002-create/esp32_mc_db/blob/main/gethistory.php): `gethistory.php`
- [Reading ingestion](https://github.com/cb240002-create/esp32_mc_db/blob/main/updateSCD40data_and_recordtable.php): `updateSCD40data_and_recordtable.php`
- [Setpoint updates](https://github.com/cb240002-create/esp32_mc_db/blob/main/updateSetpoints.php): `updateSetpoints.php`
- [COM1 command](https://github.com/cb240002-create/esp32_mc_db/blob/main/updateCOM1.php): `updateCOM1.php`

### ESP32 firmware

- [ESP32 firmware](https://github.com/cb240002-create/esp32_mc_db/blob/main/ESP32_HVAC_SCD40/ESP32_HVAC_SCD40.ino): `ESP32_HVAC_SCD40/ESP32_HVAC_SCD40.ino`

### Persistence

- [PDO connection](https://github.com/cb240002-create/esp32_mc_db/blob/main/database.php): `database.php`
- **MySQL database**

### Other components

- **Operator**

## Connections

- Operator → Web entry redirect: opens
- Web entry redirect → HVAC dashboard: redirects (evidence: `index.php`)
- HVAC dashboard → COM1 command: posts command (evidence: `home.php`)
- ESP32 firmware → Reading ingestion: reports readings
- Live readings API → PDO connection: opens connection (evidence: `get_scd40_data.php`)
- Legacy readings API → PDO connection: opens connection (evidence: `getdata.php`)
- History API → PDO connection: opens connection (evidence: `gethistory.php`)
- Reading ingestion → PDO connection: opens connection (evidence: `updateSCD40data_and_recordtable.php`)
- Setpoint updates → PDO connection: opens connection (evidence: `updateSetpoints.php`)
- COM1 command → PDO connection: opens connection (evidence: `updateCOM1.php`)
- Audit log view → PDO connection: opens connection (evidence: `recordtable.php`)
- PDO connection → MySQL database: connects to (evidence: `database.php`)
- Reading ingestion → MySQL database: updates and records (evidence: `updateSCD40data_and_recordtable.php`)
- Live readings API → MySQL database: reads live state (evidence: `get_scd40_data.php`)
- Legacy readings API → MySQL database: reads device state (evidence: `getdata.php`)
- History API → MySQL database: reads history (evidence: `gethistory.php`)
- Setpoint updates → MySQL database: writes setpoints (evidence: `updateSetpoints.php`)
- COM1 command → MySQL database: writes relay state (evidence: `updateCOM1.php`)
- Audit log view → MySQL database: reads audit records (evidence: `recordtable.php`)
