# iamvolvic/iot-greenhouse architecture

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

- Interactive diagram: https://gitdiagram.com/iamvolvic/iot-greenhouse
- Repository: https://github.com/iamvolvic/iot-greenhouse

## Overview

Greenhouse Observer is an IoT monitoring product: ESP32 sensor readings travel through the Flespi MQTT broker to a .NET backend, are persisted, and reach a live dashboard over WebSockets. Users also authenticate and manage devices through HTTPS APIs. The graph preserves the documented ingestion, persistence, and live-update stages, plus authentication, device management, and the backend’s service and storage layers. Internal MQTT, persistence, and WebSocket wiring is only partially evidenced by the excerpts and README; uncertain links are omitted rather than inferred.

Main entry points: [`Backend/Greenhouse.Infrastructure/MqttServices`](https://github.com/iamvolvic/iot-greenhouse/tree/main/Backend/Greenhouse.Infrastructure/MqttServices) (MQTT listener), [`Backend/Greenhouse.API/WebSocketHandler.cs`](https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.API/WebSocketHandler.cs) (WebSocket handling), [`Backend/Greenhouse.Infrastructure/AppDbContext.cs`](https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.Infrastructure/AppDbContext.cs) (Database context), [`Backend/Greenhouse.API/Program.cs`](https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.API/Program.cs) (API startup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Devices and dashboard"]
  node_esp32(("ESP32 sensors"))
  node_broker["Flespi broker"]
  node_dashboard["Live dashboard<br/>[index.tsx]"]
end

subgraph group_api["Backend API"]
  node_auth["Authentication API<br/>[AuthController.cs]"]
  node_devices["Device API"]
  node_subscriptions["Subscription API"]
  node_bootstrap["API startup<br/>[Program.cs]"]
end

subgraph group_realtime["Realtime ingestion"]
  node_mqtt["MQTT listener<br/>[MqttServices]"]
  node_ws["WebSocket handling"]
  node_wsconnections["Connection manager"]
end

subgraph group_core["Application services"]
  node_device_service["Device services<br/>[DeviceService.cs]"]
  node_auth_service["Auth services<br/>[AuthService.cs]"]
  node_jwt["JWT manager<br/>[JwtManager.cs]"]
end

subgraph group_data["Persistence"]
  node_dbcontext[("Database context<br/>[AppDbContext.cs]")]
  node_device_repo["Device repository"]
  node_domain["Domain records<br/>[Device.cs]"]
end

node_esp32 -->|"sends MQTT"| node_broker
node_broker -->|"forwards MQTT"| node_mqtt
node_mqtt -.->|"persists readings"| node_dbcontext
node_mqtt -.->|"feeds updates"| node_ws
node_ws -.->|"dispatches sockets"| node_wsconnections
node_ws -->|"pushes updates"| node_dashboard
node_dashboard -.->|"manages devices"| node_devices
node_devices -->|"invokes"| node_device_service
node_device_service -->|"uses"| node_device_repo
node_device_repo -->|"queries"| node_dbcontext
node_dbcontext -.->|"stores records"| node_domain
node_auth -->|"invokes"| node_auth_service
node_auth_service -->|"validates tokens"| node_jwt
node_auth_service -->|"loads user"| node_domain
node_bootstrap -->|"configures"| node_dbcontext
node_bootstrap -->|"configures"| node_mqtt
node_bootstrap -->|"configures"| node_ws
node_subscriptions -->|"invokes"| node_device_service

click node_dashboard "https://github.com/iamvolvic/iot-greenhouse/blob/main/Frontend/src/modules/editor/components/index.tsx"
click node_auth "https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.API/Controllers/AuthController.cs"
click node_devices "https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.API/Controllers/DeviceController.cs"
click node_subscriptions "https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.API/Controllers/SubscriptionController.cs"
click node_bootstrap "https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.API/Program.cs"
click node_mqtt "https://github.com/iamvolvic/iot-greenhouse/tree/main/Backend/Greenhouse.Infrastructure/MqttServices"
click node_ws "https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.API/WebSocketHandler.cs"
click node_wsconnections "https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.Infrastructure/WebsocketServices/ConnectionManager.cs"
click node_device_service "https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.Infrastructure/Services/DeviceService.cs"
click node_auth_service "https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.Infrastructure/AuthService/AuthService.cs"
click node_jwt "https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.Infrastructure/Security/JwtManager.cs"
click node_dbcontext "https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.Infrastructure/AppDbContext.cs"
click node_device_repo "https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.Infrastructure/Infrastructure.DataAccess/Repositories/DeviceRepository.cs"
click node_domain "https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.Domain/DatabaseDtos/Device.cs"

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,node_broker,node_dashboard toneBlue
class node_auth,node_devices,node_subscriptions,node_bootstrap toneAmber
class node_mqtt,node_ws,node_wsconnections toneMint
class node_device_service,node_auth_service,node_jwt toneRose
class node_dbcontext,node_device_repo,node_domain toneIndigo
```

## Components

### Devices and dashboard

- **ESP32 sensors**
- **Flespi broker**
- [Live dashboard](https://github.com/iamvolvic/iot-greenhouse/blob/main/Frontend/src/modules/editor/components/index.tsx): `Frontend/src/modules/editor/components/index.tsx`

### Backend API

- [Authentication API](https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.API/Controllers/AuthController.cs): `Backend/Greenhouse.API/Controllers/AuthController.cs`
- [Device API](https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.API/Controllers/DeviceController.cs): `Backend/Greenhouse.API/Controllers/DeviceController.cs`
- [Subscription API](https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.API/Controllers/SubscriptionController.cs): `Backend/Greenhouse.API/Controllers/SubscriptionController.cs`
- [API startup](https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.API/Program.cs): `Backend/Greenhouse.API/Program.cs`

### Realtime ingestion

- [MQTT listener](https://github.com/iamvolvic/iot-greenhouse/tree/main/Backend/Greenhouse.Infrastructure/MqttServices): `Backend/Greenhouse.Infrastructure/MqttServices`
- [WebSocket handling](https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.API/WebSocketHandler.cs): `Backend/Greenhouse.API/WebSocketHandler.cs`
- [Connection manager](https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.Infrastructure/WebsocketServices/ConnectionManager.cs): `Backend/Greenhouse.Infrastructure/WebsocketServices/ConnectionManager.cs`

### Application services

- [Device services](https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.Infrastructure/Services/DeviceService.cs): `Backend/Greenhouse.Infrastructure/Services/DeviceService.cs`
- [Auth services](https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.Infrastructure/AuthService/AuthService.cs): `Backend/Greenhouse.Infrastructure/AuthService/AuthService.cs`
- [JWT manager](https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.Infrastructure/Security/JwtManager.cs): `Backend/Greenhouse.Infrastructure/Security/JwtManager.cs`

### Persistence

- [Database context](https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.Infrastructure/AppDbContext.cs): `Backend/Greenhouse.Infrastructure/AppDbContext.cs`
- [Device repository](https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.Infrastructure/Infrastructure.DataAccess/Repositories/DeviceRepository.cs): `Backend/Greenhouse.Infrastructure/Infrastructure.DataAccess/Repositories/DeviceRepository.cs`
- [Domain records](https://github.com/iamvolvic/iot-greenhouse/blob/main/Backend/Greenhouse.Domain/DatabaseDtos/Device.cs): `Backend/Greenhouse.Domain/DatabaseDtos/Device.cs`

## Connections

- ESP32 sensors → Flespi broker: sends MQTT
- Flespi broker → MQTT listener: forwards MQTT
- MQTT listener → Database context: persists readings
- MQTT listener → WebSocket handling: feeds updates
- WebSocket handling → Connection manager: dispatches sockets
- WebSocket handling → Live dashboard: pushes updates
- Live dashboard → Device API: manages devices
- Device API → Device services: invokes (evidence: `Backend/Greenhouse.API/Controllers/DeviceController.cs`)
- Device services → Device repository: uses (evidence: `Backend/Greenhouse.Infrastructure/Services/DeviceService.cs`)
- Device repository → Database context: queries (evidence: `Backend/Greenhouse.Infrastructure/Infrastructure.DataAccess/Repositories/DeviceRepository.cs`)
- Database context → Domain records: stores records (evidence: `Backend/Greenhouse.Infrastructure/AppDbContext.cs`)
- Authentication API → Auth services: invokes (evidence: `Backend/Greenhouse.API/Controllers/AuthController.cs`)
- Auth services → JWT manager: validates tokens (evidence: `Backend/Greenhouse.Infrastructure/AuthService/AuthService.cs`)
- Auth services → Domain records: loads user (evidence: `Backend/Greenhouse.Infrastructure/AuthService/AuthService.cs`)
- API startup → Database context: configures (evidence: `Backend/Greenhouse.API/Program.cs`)
- API startup → MQTT listener: configures (evidence: `Backend/Greenhouse.API/Program.cs`)
- API startup → WebSocket handling: configures (evidence: `Backend/Greenhouse.API/Program.cs`)
- Subscription API → Device services: invokes (evidence: `Backend/Greenhouse.API/Controllers/SubscriptionController.cs`)
