# hika583/edgingthebuilding architecture

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

- Interactive diagram: https://gitdiagram.com/hika583/edgingthebuilding
- Repository: https://github.com/hika583/edgingthebuilding

## Overview

1. **Overall shape**
   - This repo is a multi-tier IoT/building telemetry system: ESP32 devices at the edge, a Jetson-based gateway/preprocessor in the middle, and a cloud backend plus dashboard on top.
   - The main boundary is between **device firmware** and **Python services**; data is normalized by shared schemas before reaching backend consumers.

2. **Device layer: ESP32-C6 sensor nodes**
   - `esp-firmware/esp32-c6-sensors` contains firmware and examples for sensor nodes and output nodes.
   - The examples (`jetson_sensor_node_demo`, `jetson_output_node_demo`, `jetson_gateway_dashboard_demo`, `jetson_register_test`) show the intended flows: register devices, emit sensor readings, and interact with a Jetson gateway.
   - `packet-format.md` documents the wire format these devices use, so this is a protocol boundary rather than just a firmware repo.

3. **Device layer: ESP32-S3 camera nodes**
   - `esp-firmware/esp32-s3-camera` is a separate firmware subtree for camera devices.
   - `firmware/camera_stream_portal` includes the actual camera streaming implementation (`app_httpd.cpp`, pin/preset configs, secrets), which indicates direct streaming from the device rather than sending camera frames through the same sensor pipeline.
   - `stream-format.md` documents the camera stream contract, which is distinct from the sensor packet format.

4. **Jetson gateway / edge hub**
   - `jetson-device-gateway` is the on-prem edge service, packaged for containerized deployment via `Dockerfile` and `docker-compose.yml`.
   - Its `app/` folder (`main.py`, `database.py`, `schemas.py`) suggests it receives device traffic, stores local state, and exposes an API for downstream use.
   - `scripts/setup_jetson_orin.sh` and `data/` indicate it is meant to run on a Jetson Orin as a persistent field gateway.

5. **Edge preprocessing**
   - `edge-preprocessing/app/esp32-c6-sensors/sensor_data_processor.py` is a dedicated processing step for sensor telemetry.
   - This is the clearest place where raw ESP32 sensor packets are transformed before being forwarded, aggregated, or analyzed.
   - Architecturally, it sits between low-level device packets and higher-level backend records.

6. **Cloud backend**
   - `cloud-backend` is the centralized server-side API and persistence layer.
   - The structure (`app/main.py`, `routes.py`, `models.py`, `schemas.py`, `database.py`) shows a classic separation of request handling, data models, validation contracts, and storage access.
   - `cloud-backend/data/` suggests local persisted state or a database file/bucket mounted into the service.

7. **Dashboard**
   - `cloud-dashboard/index.html` is a static frontend, not a large client application.
   - It likely consumes the cloud backend API directly to render device status, sensor readings, and camera-related events.
   - Because there is no build pipeline in the tree, the dashboard is a lightweight presentation layer rather than a separate frontend subsystem.

8. **Shared contract layer**
   - `shared/schemas/*.schema.json` defines the canonical JSON shapes for `camera-event`, `device-status`, and `sensor-reading`.
   - `shared/sample-payloads/*.example.json` provides example messages for those same event types.
   - This shared folder is important architecturally: it keeps the Jetson service, cloud backend, dashboard, and device-facing tooling aligned on payload structure.

9. **Documentation as an architecture boundary**
   - `docs/architecture.md`, `docs/api-contract.md`, `docs/device-packet-format.md`, and `docs/team-responsibilities.md` indicate the repo treats contracts and subsystem boundaries as first-class artifacts.
   - The top-level `CS131 Phase 2_ Design.pdf` likely captures the system design narrative, while `jetson-esp-wifi-topology.md` documents the network deployment pattern.

10. **Deployment model**
   - There are two operational environments: **edge/local** on the Jetson (`jetson-device-gateway`, device firmware, preprocessing) and **cloud** (`cloud-backend`, `cloud-dashboard`).
   - `docker-compose.jetson.yml` and the Jetson service’s compose file reinforce that the gateway is expected to run as a deployable field stack.
   - The ESP firmware repos are separate from the Python services, so device builds and server deployments are intentionally decoupled.

11. **Primary data flow**
   - ESP32 sensors and cameras generate packets/streams.
   - The Jetson gateway and preprocessing layer handle local ingestion and normalization, using the shared payload contracts.
   - The cloud backend persists and serves the normalized data.
   - The dashboard reads from the cloud backend to present the system state to users.

Main entry points: [`cloud-backend/app`](https://github.com/hika583/edgingthebuilding/tree/main/cloud-backend/app) (Cloud API), [`shared/schemas`](https://github.com/hika583/edgingthebuilding/tree/main/shared/schemas) (Schemas), [`jetson-device-gateway/app`](https://github.com/hika583/edgingthebuilding/tree/main/jetson-device-gateway/app) (Gateway app), [`esp-firmware/esp32-s3-camera/firmware/camera_stream_portal`](https://github.com/hika583/edgingthebuilding/tree/main/esp-firmware/esp32-s3-camera/firmware/camera_stream_portal) (Camera portal)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_firmware["Device firmware"]
  node_esp32_c6_fw["ESP32 C6<br/>ESP32 firmware"]
  node_esp32_c6_examples["C6 demos<br/>example flows"]
  node_esp32_c6_packet_format["Packet format<br/>protocol spec<br/>[packet-format.md]"]
  node_esp32_s3_fw["ESP32 S3<br/>camera firmware"]
  node_camera_portal["Camera portal<br/>streaming firmware"]
  node_camera_stream_format["Stream format<br/>stream contract<br/>[stream-format.md]"]
end

subgraph group_edge["Edge / Jetson"]
  node_jetson_gateway_app["Gateway app<br/>Jetson service"]
  node_jetson_gateway_db[("Gateway store<br/>local persistence<br/>[database.py]")]
  node_jetson_gateway_schemas["Gateway schemas<br/>API schemas<br/>[schemas.py]"]
  node_sensor_processor["Sensor processor<br/>telemetry transform"]
end

subgraph group_cloud["Cloud"]
  node_cloud_api["Cloud API<br/>backend service"]
  node_cloud_routes["API routes<br/>request layer<br/>[routes.py]"]
  node_cloud_models["Data models<br/>domain models<br/>[models.py]"]
  node_cloud_schemas["Backend schemas<br/>API schemas<br/>[schemas.py]"]
  node_cloud_db[("Cloud store<br/>persistence<br/>[database.py]")]
  node_dashboard["Dashboard<br/>static UI<br/>[index.html]"]
end

subgraph group_shared["Shared contracts"]
  node_shared_contracts["Schemas<br/>JSON schema set"]
  node_shared_examples["Payload examples<br/>sample data"]
end

subgraph group_docs["Docs"]
  node_architecture_docs["Architecture docs<br/>design docs<br/>[architecture.md]"]
end

node_esp32_c6_fw -->|"emits"| node_esp32_c6_packet_format
node_esp32_c6_examples -->|"demonstrates"| node_esp32_c6_fw
node_esp32_s3_fw -->|"contains"| node_camera_portal
node_camera_portal -->|"uses"| node_camera_stream_format
node_esp32_c6_packet_format -->|"feeds"| node_sensor_processor
node_sensor_processor -->|"normalizes to"| node_shared_contracts
node_jetson_gateway_app -->|"validates with"| node_jetson_gateway_schemas
node_jetson_gateway_app -->|"persists to"| node_jetson_gateway_db
node_jetson_gateway_app -->|"ingests from"| node_sensor_processor
node_shared_contracts -->|"aligns"| node_jetson_gateway_schemas
node_shared_contracts -->|"aligns"| node_cloud_schemas
node_cloud_api -->|"exposes"| node_cloud_routes
node_cloud_api -->|"defines"| node_cloud_models
node_cloud_api -->|"validates with"| node_cloud_schemas
node_cloud_api -->|"persists to"| node_cloud_db
node_jetson_gateway_app -->|"forwards"| node_cloud_api
node_shared_examples -->|"illustrates"| node_shared_contracts
node_cloud_api -->|"serves"| node_dashboard
node_camera_portal -.->|"publishes metadata"| node_cloud_api
node_architecture_docs -.->|"documents"| node_shared_contracts

click node_esp32_c6_fw "https://github.com/hika583/edgingthebuilding/tree/main/esp-firmware/esp32-c6-sensors"
click node_esp32_c6_examples "https://github.com/hika583/edgingthebuilding/tree/main/esp-firmware/esp32-c6-sensors/examples"
click node_esp32_c6_packet_format "https://github.com/hika583/edgingthebuilding/blob/main/esp-firmware/esp32-c6-sensors/packet-format.md"
click node_esp32_s3_fw "https://github.com/hika583/edgingthebuilding/tree/main/esp-firmware/esp32-s3-camera"
click node_camera_portal "https://github.com/hika583/edgingthebuilding/tree/main/esp-firmware/esp32-s3-camera/firmware/camera_stream_portal"
click node_camera_stream_format "https://github.com/hika583/edgingthebuilding/blob/main/esp-firmware/esp32-s3-camera/stream-format.md"
click node_jetson_gateway_app "https://github.com/hika583/edgingthebuilding/tree/main/jetson-device-gateway/app"
click node_jetson_gateway_db "https://github.com/hika583/edgingthebuilding/blob/main/jetson-device-gateway/app/database.py"
click node_jetson_gateway_schemas "https://github.com/hika583/edgingthebuilding/blob/main/jetson-device-gateway/app/schemas.py"
click node_sensor_processor "https://github.com/hika583/edgingthebuilding/blob/main/edge-preprocessing/app/esp32-c6-sensors/sensor_data_processor.py"
click node_cloud_api "https://github.com/hika583/edgingthebuilding/tree/main/cloud-backend/app"
click node_cloud_routes "https://github.com/hika583/edgingthebuilding/blob/main/cloud-backend/app/routes.py"
click node_cloud_models "https://github.com/hika583/edgingthebuilding/blob/main/cloud-backend/app/models.py"
click node_cloud_schemas "https://github.com/hika583/edgingthebuilding/blob/main/cloud-backend/app/schemas.py"
click node_cloud_db "https://github.com/hika583/edgingthebuilding/blob/main/cloud-backend/app/database.py"
click node_dashboard "https://github.com/hika583/edgingthebuilding/blob/main/cloud-dashboard/index.html"
click node_shared_contracts "https://github.com/hika583/edgingthebuilding/tree/main/shared/schemas"
click node_shared_examples "https://github.com/hika583/edgingthebuilding/tree/main/shared/sample-payloads"
click node_architecture_docs "https://github.com/hika583/edgingthebuilding/blob/main/docs/architecture.md"

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_esp32_c6_fw,node_esp32_c6_examples,node_esp32_c6_packet_format,node_esp32_s3_fw,node_camera_portal,node_camera_stream_format toneBlue
class node_jetson_gateway_app,node_jetson_gateway_db,node_jetson_gateway_schemas,node_sensor_processor toneAmber
class node_cloud_api,node_cloud_routes,node_cloud_models,node_cloud_schemas,node_cloud_db,node_dashboard toneMint
class node_shared_contracts,node_shared_examples toneRose
class node_architecture_docs toneIndigo
```

## Components

### Device firmware

ESP32 firmware for sensor and camera nodes

- [ESP32 C6](https://github.com/hika583/edgingthebuilding/tree/main/esp-firmware/esp32-c6-sensors): ESP32 firmware · Sensor and output node firmware for the ESP32-C6 device family · `esp-firmware/esp32-c6-sensors`
- [C6 demos](https://github.com/hika583/edgingthebuilding/tree/main/esp-firmware/esp32-c6-sensors/examples): example flows · Reference device flows for sensor, output, registration, and gateway interaction · `esp-firmware/esp32-c6-sensors/examples`
- [Packet format](https://github.com/hika583/edgingthebuilding/blob/main/esp-firmware/esp32-c6-sensors/packet-format.md): protocol spec · Wire format for ESP32-C6 sensor packets · `esp-firmware/esp32-c6-sensors/packet-format.md`
- [ESP32 S3](https://github.com/hika583/edgingthebuilding/tree/main/esp-firmware/esp32-s3-camera): camera firmware · ESP32-S3 camera device subtree · `esp-firmware/esp32-s3-camera`
- [Camera portal](https://github.com/hika583/edgingthebuilding/tree/main/esp-firmware/esp32-s3-camera/firmware/camera_stream_portal): streaming firmware · Camera streaming implementation and device-side portal · `esp-firmware/esp32-s3-camera/firmware/camera_stream_portal`
- [Stream format](https://github.com/hika583/edgingthebuilding/blob/main/esp-firmware/esp32-s3-camera/stream-format.md): stream contract · Contract for camera stream payloads and framing · `esp-firmware/esp32-s3-camera/stream-format.md`

### Edge / Jetson

On-prem gateway and preprocessing services

- [Gateway app](https://github.com/hika583/edgingthebuilding/tree/main/jetson-device-gateway/app): Jetson service · Edge gateway entrypoint for device ingestion and API handling · `jetson-device-gateway/app`
- [Gateway store](https://github.com/hika583/edgingthebuilding/blob/main/jetson-device-gateway/app/database.py): local persistence · Local state and persistence used by the Jetson gateway · `jetson-device-gateway/app/database.py`
- [Gateway schemas](https://github.com/hika583/edgingthebuilding/blob/main/jetson-device-gateway/app/schemas.py): API schemas · Gateway request and response validation models · `jetson-device-gateway/app/schemas.py`
- [Sensor processor](https://github.com/hika583/edgingthebuilding/blob/main/edge-preprocessing/app/esp32-c6-sensors/sensor_data_processor.py): telemetry transform · Edge preprocessing step that normalizes ESP32-C6 sensor telemetry · `edge-preprocessing/app/esp32-c6-sensors/sensor_data_processor.py`

### Cloud

Central backend and dashboard

- [Cloud API](https://github.com/hika583/edgingthebuilding/tree/main/cloud-backend/app): backend service · Central backend entrypoint for persistence and serving data · `cloud-backend/app`
- [API routes](https://github.com/hika583/edgingthebuilding/blob/main/cloud-backend/app/routes.py): request layer · HTTP route handling for backend endpoints · `cloud-backend/app/routes.py`
- [Data models](https://github.com/hika583/edgingthebuilding/blob/main/cloud-backend/app/models.py): domain models · Backend domain entities and persistence models · `cloud-backend/app/models.py`
- [Backend schemas](https://github.com/hika583/edgingthebuilding/blob/main/cloud-backend/app/schemas.py): API schemas · Backend validation and response contracts · `cloud-backend/app/schemas.py`
- [Cloud store](https://github.com/hika583/edgingthebuilding/blob/main/cloud-backend/app/database.py): persistence · Backend persistence layer and data storage access · `cloud-backend/app/database.py`
- [Dashboard](https://github.com/hika583/edgingthebuilding/blob/main/cloud-dashboard/index.html): static UI · Lightweight browser-based presentation layer · `cloud-dashboard/index.html`

### Shared contracts

Canonical payload schemas and examples

- [Schemas](https://github.com/hika583/edgingthebuilding/tree/main/shared/schemas): JSON schema set · Canonical event and reading schemas shared across the stack · `shared/schemas`
- [Payload examples](https://github.com/hika583/edgingthebuilding/tree/main/shared/sample-payloads): sample data · Example payloads for the shared event contracts · `shared/sample-payloads`

### Docs

Repository-level design and contract documentation

- [Architecture docs](https://github.com/hika583/edgingthebuilding/blob/main/docs/architecture.md): design docs · Repository documentation for system boundaries and deployment model · `docs/architecture.md`

## Connections

- ESP32 C6 → Packet format: emits · Device firmware follows the packet boundary when producing telemetry
- C6 demos → ESP32 C6: demonstrates · Examples show the intended sensor, output, and registration flows
- ESP32 S3 → Camera portal: contains · Camera subtree includes the streaming portal implementation
- Camera portal → Stream format: uses · Camera portal is governed by its own stream contract
- Packet format → Sensor processor: feeds · Raw sensor packets are the input to edge preprocessing
- Sensor processor → Schemas: normalizes to · Edge preprocessing converts telemetry into shared message shapes
- Gateway app → Gateway schemas: validates with · Gateway API relies on local request/response schemas
- Gateway app → Gateway store: persists to · Gateway stores local state and device records
- Gateway app → Sensor processor: ingests from · Gateway and preprocessing together form the edge normalization path
- Schemas → Gateway schemas: aligns · Shared payload shapes keep gateway contracts consistent
- Schemas → Backend schemas: aligns · Cloud backend uses the same canonical event shapes
- Cloud API → API routes: exposes · Backend routes handle external requests
- Cloud API → Data models: defines · Backend service is organized around domain models
- Cloud API → Backend schemas: validates with · Backend request and response contracts are schema-driven
- Cloud API → Cloud store: persists to · Backend reads and writes through its storage layer
- Gateway app → Cloud API: forwards · Edge-normalized data is forwarded to the cloud backend
- Payload examples → Schemas: illustrates · Examples document the canonical payload shapes
- Cloud API → Dashboard: serves · Dashboard consumes backend data directly
- Camera portal → Cloud API: publishes metadata · Camera subsystem is represented upstream through backend-facing events
- Architecture docs → Schemas: documents · Repository docs call out contracts as a first-class boundary
