# kolbacer/smart-sauna-iot-project architecture

> Architecture diagram of the GitHub repository kolbacer/smart-sauna-iot-project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kolbacer/smart-sauna-iot-project
- Repository: https://github.com/kolbacer/smart-sauna-iot-project

## Overview

##### Project type and purpose
- This is a full‑stack IoT demo (“Smart Sauna”) showcasing end‑to‑end data flow from hardware sensors to a mobile UI.
- Key parts: NodeMCU ESP8266 microcontroller with temperature/humidity sensors, an MQTT‐based Gateway (Mosquitto broker + Node.js server), and a Flutter mobile app for configuration and monitoring.

##### File structure
- Top level:
- NodeMCU/ – Arduino sketch for the ESP8266 device
- gateway/ – Docker Compose definition, Mosquitto config under gateway/mosquitto, Node.js server under gateway/server
- flutter_app/ – Flutter cross‑platform application with data providers, models, UI pages
- Recognize patterns:
- Pub/Sub messaging (MQTT) between device and broker
- REST + SSE API between server and mobile
- Docker Compose for microservice orchestration

##### README for additional insights
- Hardware list and wiring (NodeMCU sketch variables: ssid, password, mqtt_server)
- Gateway exposes HTTP endpoints for configuration (GET /getconfig, POST /setconfig) and monitoring via Server‑Sent Events (GET /monitoring)
- Flutter app pages for connection, configuration, and statistics

a. Main components
- IoT Device (NodeMCU + DHT11, TMP36 sensors + LEDs/relays)
- MQTT Broker (Mosquitto container)
- Node.js Gateway Server (broker.js, server.js container)
- Flutter Mobile App (UI, REST client, SSE client)
- (Optionally) External MQTT Broker if configured
b. Relationships & interactions
1. Sensors → NodeMCU gathers readings → publishes MQTT topics (e.g. “sauna/temp”, “pool/temp”)
2. Node.js server subscribes to those topics, stores or forwards readings
3. Flutter app calls REST endpoints on Node.js server to get/set configuration
4. Flutter app opens SSE stream to receive live sensor updates
5. NodeMCU also subscribes to configuration topics (for target temperature/hysteresis)
c. Architectural patterns & design principles
- Pub/Sub messaging decouples device and server
- RESTful API + SSE for client‑server communication
- Containerized deployment with Docker Compose (broker + server)
- Single‑page mobile client with clearly separated data providers, models, and UI layers
d. Key technologies
- NodeMCU ESP8266 C++ (Arduino)
- MQTT (Mosquitto)
- Node.js + Express (server.js, broker.js)
- Docker & Docker Compose
- Flutter (Dart) with HTTP, SSE, state management
- JSON for payloads

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Device Tier
    subgraph "Device Tier"
        direction TB
        NodeMCU["NodeMCU ESP8266"]:::device
    end

    %% Gateway Tier
    subgraph "Gateway Tier (Docker Compose)"
        direction TB
        Mosquitto["Mosquitto Broker\nPort 1883"]:::broker
        Compose["docker-compose.yml"]:::broker
        subgraph "Node.js API Server"
            direction TB
            ServerJS["server.js"]:::server
            BrokerJS["broker.js"]:::server
            PackageJSON["package.json"]:::server
            Dockerfile["Dockerfile"]:::server
            Env[".env"]:::server
        end
    end

    %% Client Tier
    subgraph "Client Tier (Flutter App)"
        direction TB
        MainDart["main.dart"]:::client
        subgraph "Data Providers"
            direction TB
            ConfigAPI["configuration_api.dart"]:::client
            MonitoringAPI["monitoring_api.dart"]:::client
        end
        subgraph "Models"
            direction TB
            ConfigModel["configuration.dart"]:::client
            ChartData["chart_data.dart"]:::client
            ExtremeValues["extreme_values.dart"]:::client
        end
        subgraph "Pages & Elements"
            direction TB
            ConfigPage["configuration_page.dart"]:::client
            StatsPage["statistics_page.dart"]:::client
            ChartElem["chart.dart"]:::client
            Slider["circular_slider.dart"]:::client
            AlertDialog["custom_alert_dialog.dart"]:::client
            ModalDialog["modal_dialog.dart"]:::client
        end
        Pubspec["pubspec.yaml"]:::client
    end

    %% Data Flows
    NodeMCU -->|"Publish telemetry\n(sauna/temp)\nMQTT 1883"| Mosquitto
    Mosquitto -->|"Subscribe telemetry"| ServerJS
    ServerJS -->|"SSE /monitoring"| MonitoringAPI
    MonitoringAPI -->|"Update UI"| StatsPage
    ConfigAPI -.->|"GET/POST\n/getconfig\n/setconfig"| ServerJS
    ServerJS -->|"Publish config\nMQTT topics"| Mosquitto
    Mosquitto -->|"Deliver config"| NodeMCU

    %% Click Events
    click NodeMCU "https://github.com/kolbacer/smart-sauna-iot-project/blob/main/NodeMCU/smart_sauna.ino"
    click Mosquitto "https://github.com/kolbacer/smart-sauna-iot-project/blob/main/gateway/mosquitto/config/mosquitto.conf"
    click Compose "https://github.com/kolbacer/smart-sauna-iot-project/blob/main/gateway/docker-compose.yml"
    click ServerJS "https://github.com/kolbacer/smart-sauna-iot-project/blob/main/gateway/server/server.js"
    click BrokerJS "https://github.com/kolbacer/smart-sauna-iot-project/blob/main/gateway/server/broker.js"
    click PackageJSON "https://github.com/kolbacer/smart-sauna-iot-project/blob/main/gateway/server/package.json"
    click Dockerfile "https://github.com/kolbacer/smart-sauna-iot-project/tree/main/gateway/server/Dockerfile"
    click Env "https://github.com/kolbacer/smart-sauna-iot-project/blob/main/gateway/server/.env"
    click MainDart "https://github.com/kolbacer/smart-sauna-iot-project/blob/main/flutter_app/lib/main.dart"
    click ConfigAPI "https://github.com/kolbacer/smart-sauna-iot-project/blob/main/flutter_app/lib/data/data_providers/configuration_api.dart"
    click MonitoringAPI "https://github.com/kolbacer/smart-sauna-iot-project/blob/main/flutter_app/lib/data/data_providers/monitoring_api.dart"
    click ConfigModel "https://github.com/kolbacer/smart-sauna-iot-project/blob/main/flutter_app/lib/data/models/configuration.dart"
    click ChartData "https://github.com/kolbacer/smart-sauna-iot-project/blob/main/flutter_app/lib/data/models/chart_data.dart"
    click ExtremeValues "https://github.com/kolbacer/smart-sauna-iot-project/blob/main/flutter_app/lib/data/models/extreme_values.dart"
    click ConfigPage "https://github.com/kolbacer/smart-sauna-iot-project/blob/main/flutter_app/lib/pages/configuration_page.dart"
    click StatsPage "https://github.com/kolbacer/smart-sauna-iot-project/blob/main/flutter_app/lib/pages/statistics_page.dart"
    click ChartElem "https://github.com/kolbacer/smart-sauna-iot-project/blob/main/flutter_app/lib/pages/elements/chart.dart"
    click Slider "https://github.com/kolbacer/smart-sauna-iot-project/blob/main/flutter_app/lib/pages/elements/circular_slider.dart"
    click AlertDialog "https://github.com/kolbacer/smart-sauna-iot-project/blob/main/flutter_app/lib/pages/elements/custom_alert_dialog.dart"
    click ModalDialog "https://github.com/kolbacer/smart-sauna-iot-project/blob/main/flutter_app/lib/pages/elements/modal_dialog.dart"
    click Pubspec "https://github.com/kolbacer/smart-sauna-iot-project/blob/main/flutter_app/pubspec.yaml"

    %% Styles
    classDef device fill:#e0ffe0,stroke:#008000,color:#004000;
    classDef broker fill:#e0f0ff,stroke:#0050a0,color:#003080;
    classDef server fill:#ffe0c0,stroke:#d07000,color:#a05000;
    classDef client fill:#f0e0ff,stroke:#8000a0,color:#500060;
```
