# darho-academy/esp8266-underground-helmet architecture

> Architecture diagram of the GitHub repository darho-academy/esp8266-underground-helmet, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/darho-academy/esp8266-underground-helmet
- Repository: https://github.com/darho-academy/esp8266-underground-helmet

## Overview

#### Purpose and Runtime
Underground Helmet is ESP8266 firmware that monitors gas, temperature/humidity, and distance; drives LEDs and a buzzer; and exposes live device status on a local Wi-Fi web dashboard and JSON API. It runs on the ESP8266 RTOS SDK/FreeRTOS stack, producing a flashable image (`build/underground_helmet.bin`) with a SPIFFS web-assets image (`build/spiffs.bin`).

#### Entrypoint and Composition
Application startup is rooted at `main/main.c`, compiled as the `main` component (`main/component.mk`). It coordinates independently built application components rather than a monolithic program:
- `components/app_system/app_system.c`
- `components/app_wifi/app_wifi.c`
- `components/app_sensors/app_sensors.c`
- `components/app_outputs/app_outputs.c`
- `components/app_webserver/app_webserver.c`

Public headers under each component’s `include/` directory form the main inter-component boundary.

#### Sensing and Device-State Path
`components/app_sensors/app_sensors.c` is the hardware acquisition boundary for the MQ gas sensor, DHT temperature/humidity sensor, and ultrasonic distance sensor. Readings are consumed as device state by the rest of the firmware rather than directly coupled to HTTP handling.
- `components/app_sensors/include/app_sensors.h`
- `components/app_system/app_system.c`
- `components/app_logs/app_logs.c`

The ESP8266 driver/runtime layer supplies GPIO, ADC, timers, I2C, and FreeRTOS scheduling beneath this boundary.

#### Safety Actuation and System Coordination
`components/app_outputs/app_outputs.c` owns physical responses: five status LEDs and the buzzer alarm. `app_system` is the likely policy/orchestration layer that translates measurements and lifecycle events into status/alarm decisions and output updates.
- `components/app_outputs/include/app_outputs.h`
- `components/app_system/include/app_system.h`
- `components/app_logs/include/app_logs.h`

This separates safety-facing GPIO control from sensor acquisition and network-facing interfaces.

#### Network, Local API, and UI
`components/app_wifi/app_wifi.c` establishes connection to an existing router or hotspot, bridging firmware state to the TCP/IP stack. `components/app_webserver/app_webserver.c` serves the local dashboard and JSON status interface; its embedded minimal JSON support keeps HTTP/API serialization inside the web boundary.
- `components/app_wifi/include/app_wifi.h`
- `components/app_webserver/app_webserver.c`
- `components/app_webserver/json_min.c`

Browser assets are deployed separately through SPIFFS:
- `spiffs/index.html`
- `spiffs/app.js`
- `spiffs/style.css`

The external interaction surface is therefore local Wi-Fi HTTP, with browser clients reading status and potentially invoking protected operations.

#### Configuration, Authentication, Persistence, and Updates
Configuration interfaces are centralized in `components/app_config/include/app_config.h`; persistent backing is likely ESP-IDF NVS/SPI flash, as the build includes `nvs_flash`, SPIFFS, and partition artifacts. Authentication is an explicit boundary around administrative or API actions, with local SHA-256 implementation:
- `components/app_auth/app_auth.c`
- `components/app_auth/sha256_min.c`
- `components/app_ota/app_ota.c`

OTA is a distinct update path, built with ESP OTA and HTTPS OTA support. The flash layout is defined by `partitions.csv`; bootloader and OTA metadata artifacts (`build/bootloader/bootloader.bin`, `build/ota_data_initial.bin`) indicate firmware lifecycle management is part of the deployed system.

Main entry points: [`components/app_webserver/app_webserver.c`](https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_webserver/app_webserver.c) (Dashboard & JSON API), [`main/main.c`](https://github.com/darho-academy/esp8266-underground-helmet/blob/main/main/main.c) (Application startup), [`components/app_system/app_system.c`](https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_system/app_system.c) (System coordinator), [`components/app_sensors/app_sensors.c`](https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_sensors/app_sensors.c) (Sensor acquisition)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_firmware["Firmware Components"]
  node_entry["Application startup<br/>ESP8266 entrypoint<br/>[main.c]"]
  node_system["System coordinator<br/>policy orchestration<br/>[app_system.c]"]
  node_sensors["Sensor acquisition<br/>hardware boundary<br/>[app_sensors.c]"]
  node_outputs["Safety outputs<br/>GPIO actuator<br/>[app_outputs.c]"]
  node_logs["Application logging<br/>observability<br/>[app_logs.c]"]
  node_config["Configuration interface<br/>component API<br/>[app_config.h]"]
  node_auth["Authentication<br/>access control<br/>[app_auth.c]"]
  node_ota["OTA updater<br/>firmware lifecycle<br/>[app_ota.c]"]
end

subgraph group_network["Local Network Surface"]
  node_wifi["Wi-Fi connection<br/>network adapter<br/>[app_wifi.c]"]
  node_webserver["Dashboard &amp; JSON API<br/>HTTP server<br/>[app_webserver.c]"]
  node_json["JSON serialization<br/>embedded JSON<br/>[json_min.c]"]
  node_browser(("Browser clients<br/>local user interface"))
end

subgraph group_deployment["Storage &amp; Deployment"]
  node_web_assets["SPIFFS web assets<br/>static dashboard<br/>[index.html]"]
  node_persistent_storage[("Flash persistence<br/>NVS / SPI flash")]
  node_partitions["Flash layout<br/>partition definition<br/>[partitions.csv]"]
  node_firmware_image["Flashable firmware<br/>build artifact"]
  node_spiffs_image["SPIFFS image<br/>build artifact<br/>[spiffs.bin]"]
end

node_runtime{{"ESP8266 RTOS &amp; drivers<br/>platform runtime"}}

node_entry -->|"starts"| node_system
node_entry -->|"starts"| node_sensors
node_entry -->|"starts"| node_outputs
node_entry -->|"starts"| node_wifi
node_entry -->|"starts"| node_webserver
node_sensors -->|"measurements"| node_system
node_system -->|"status and alarm decisions"| node_outputs
node_sensors -.->|"readings"| node_logs
node_system -.->|"lifecycle events"| node_logs
node_runtime -->|"drivers and scheduling"| node_sensors
node_runtime -->|"GPIO"| node_outputs
node_runtime -->|"TCP/IP stack"| node_wifi
node_wifi -->|"local TCP/IP"| node_webserver
node_webserver -->|"reads device state"| node_system
node_webserver -->|"serializes status"| node_json
node_browser -->|"local Wi-Fi HTTP"| node_webserver
node_webserver -->|"serves"| node_web_assets
node_webserver -->|"protects operations"| node_auth
node_config -->|"persists"| node_persistent_storage
node_ota -->|"writes update state"| node_persistent_storage
node_partitions -.->|"places"| node_firmware_image
node_partitions -.->|"places"| node_spiffs_image
node_web_assets -->|"packaged into"| node_spiffs_image
node_firmware_image -.->|"update payload"| node_ota

click node_entry "https://github.com/darho-academy/esp8266-underground-helmet/blob/main/main/main.c"
click node_system "https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_system/app_system.c"
click node_sensors "https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_sensors/app_sensors.c"
click node_outputs "https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_outputs/app_outputs.c"
click node_logs "https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_logs/app_logs.c"
click node_config "https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_config/include/app_config.h"
click node_auth "https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_auth/app_auth.c"
click node_ota "https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_ota/app_ota.c"
click node_wifi "https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_wifi/app_wifi.c"
click node_webserver "https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_webserver/app_webserver.c"
click node_json "https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_webserver/json_min.c"
click node_web_assets "https://github.com/darho-academy/esp8266-underground-helmet/blob/main/spiffs/index.html"
click node_partitions "https://github.com/darho-academy/esp8266-underground-helmet/blob/main/partitions.csv"
click node_firmware_image "https://github.com/darho-academy/esp8266-underground-helmet/blob/main/build/underground_helmet.bin"
click node_spiffs_image "https://github.com/darho-academy/esp8266-underground-helmet/blob/main/build/spiffs.bin"

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_system,node_sensors,node_outputs,node_logs,node_config,node_auth,node_ota toneBlue
class node_wifi,node_webserver,node_json,node_browser toneAmber
class node_web_assets,node_persistent_storage,node_partitions,node_firmware_image,node_spiffs_image toneMint
class node_runtime toneNeutral
```

## Components

### Firmware Components

- [Application startup](https://github.com/darho-academy/esp8266-underground-helmet/blob/main/main/main.c): ESP8266 entrypoint · Composes and starts application components. · `main/main.c`
- [System coordinator](https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_system/app_system.c): policy orchestration · Turns lifecycle and measurements into device decisions. · `components/app_system/app_system.c`
- [Sensor acquisition](https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_sensors/app_sensors.c): hardware boundary · Reads MQ gas, DHT, and ultrasonic sensors. · `components/app_sensors/app_sensors.c`
- [Safety outputs](https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_outputs/app_outputs.c): GPIO actuator · Controls five LEDs and buzzer alarm. · `components/app_outputs/app_outputs.c`
- [Application logging](https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_logs/app_logs.c): observability · `components/app_logs/app_logs.c`
- [Configuration interface](https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_config/include/app_config.h): component API · Central configuration boundary. · `components/app_config/include/app_config.h`
- [Authentication](https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_auth/app_auth.c): access control · Protects administrative or API actions. · `components/app_auth/app_auth.c`
- [OTA updater](https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_ota/app_ota.c): firmware lifecycle · Installs updates through OTA support. · `components/app_ota/app_ota.c`

### Local Network Surface

- [Wi-Fi connection](https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_wifi/app_wifi.c): network adapter · Connects to an existing router or hotspot. · `components/app_wifi/app_wifi.c`
- [Dashboard & JSON API](https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_webserver/app_webserver.c): HTTP server · Serves local status and protected operations. · `components/app_webserver/app_webserver.c`
- [JSON serialization](https://github.com/darho-academy/esp8266-underground-helmet/blob/main/components/app_webserver/json_min.c): embedded JSON · `components/app_webserver/json_min.c`
- **Browser clients**: local user interface

### Storage & Deployment

- [SPIFFS web assets](https://github.com/darho-academy/esp8266-underground-helmet/blob/main/spiffs/index.html): static dashboard · Dashboard HTML, JavaScript, and CSS. · `spiffs/index.html`
- **Flash persistence**: NVS / SPI flash · Stores configuration and device state.
- [Flash layout](https://github.com/darho-academy/esp8266-underground-helmet/blob/main/partitions.csv): partition definition · Defines firmware, OTA, and SPIFFS storage layout. · `partitions.csv`
- [Flashable firmware](https://github.com/darho-academy/esp8266-underground-helmet/blob/main/build/underground_helmet.bin): build artifact · `build/underground_helmet.bin`
- [SPIFFS image](https://github.com/darho-academy/esp8266-underground-helmet/blob/main/build/spiffs.bin): build artifact · `build/spiffs.bin`

### Other components

- **ESP8266 RTOS & drivers**: platform runtime · Provides FreeRTOS, GPIO, ADC, timers, I2C, and TCP/IP.

## Connections

- Application startup → System coordinator: starts
- Application startup → Sensor acquisition: starts
- Application startup → Safety outputs: starts
- Application startup → Wi-Fi connection: starts
- Application startup → Dashboard & JSON API: starts
- Sensor acquisition → System coordinator: measurements
- System coordinator → Safety outputs: status and alarm decisions
- Sensor acquisition → Application logging: readings
- System coordinator → Application logging: lifecycle events
- ESP8266 RTOS & drivers → Sensor acquisition: drivers and scheduling
- ESP8266 RTOS & drivers → Safety outputs: GPIO
- ESP8266 RTOS & drivers → Wi-Fi connection: TCP/IP stack
- Wi-Fi connection → Dashboard & JSON API: local TCP/IP
- Dashboard & JSON API → System coordinator: reads device state
- Dashboard & JSON API → JSON serialization: serializes status
- Browser clients → Dashboard & JSON API: local Wi-Fi HTTP
- Dashboard & JSON API → SPIFFS web assets: serves
- Dashboard & JSON API → Authentication: protects operations
- Configuration interface → Flash persistence: persists
- OTA updater → Flash persistence: writes update state
- Flash layout → Flashable firmware: places
- Flash layout → SPIFFS image: places
- SPIFFS web assets → SPIFFS image: packaged into
- Flashable firmware → OTA updater: update payload
