# henferper/mundobee architecture

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

- Interactive diagram: https://gitdiagram.com/henferper/mundobee
- Repository: https://github.com/henferper/mundobee

## Overview

##### Project type and purpose
- This is a full-stack IoT monitoring application for beehives.
- It ingests sensor data (temperature, humidity, bee movement) from ESP32 devices over MQTT, stores it in MariaDB, provides a REST+WebSocket API via a NestJS backend, and presents interactive dashboards in a Next.js+Tailwind CSS frontend. It also integrates Grafana (with Prometheus) for advanced metric visualization and Node-RED for data simulation.

##### File structure
- Top-level directories:
- `/backend` – NestJS monolith providing REST endpoints, WebSocket gateway, authentication, device/preset/metrics/configuration modules.
- `/client` – Next.js 13 “app router” based React frontend with Tailwind CSS, contexts, components, pages under `(auth-routes)` and `(user-routes)`.
- `/docker-compose.yml`, `/docker/` – container definitions for backend, client, nginx, plus mosquitto, node-red, grafana, prometheus, portainer.
- `/mosquitto/`, `/node-red/`, `/grafana/`, `/prometheus/` – configuration and dashboards for external services.

##### README for additional insights
- Confirms all services: Frontend (Next.js), Backend (NestJS), Mosquitto (MQTT broker), MariaDB (relational DB), Grafana (visualization), Node-RED (simulation), Portainer.
- Mentions Prometheus for metrics, dashboards exposures at specific URLs.

a. Main components:
- ESP32 devices (sensors)
- Mosquitto MQTT Broker
- NestJS Backend (REST + WebSocket + MQTT subscriber + Prometheus metrics exporter)
- MariaDB Database
- Prometheus (scrapes /metrics from backend)
- Grafana (reads from Prometheus and optionally MariaDB)
- Next.js Frontend
- Node-RED (data simulator & test flows)
-

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% IoT Layer
    subgraph "IoT Devices"
        ESP32["ESP32 Sensors"]:::iot
    end

    %% Broker Layer
    subgraph "MQTT Broker"
        MQTT["Mosquitto MQTT Broker"]:::broker
    end

    %% Simulation Layer
    subgraph "Data Simulator"
        NodeRED["Node-RED (Simulator)"]:::simulation
    end

    %% Backend Layer
    subgraph "NestJS Backend" 
        direction TB
        BackendRoot["Backend (NestJS Monolith)"]:::backend
        subgraph "Controllers"
            AuthCtrl["AuthController"]:::api
            DeviceCtrl["DeviceController"]:::api
            MetricsCtrl["MetricsController"]:::api
            PresetCtrl["PresetController"]:::api
            ConfigCtrl["ConfigurationController"]:::api
            UserCtrl["UserController"]:::api
        end
        Gateway["WebSocket Gateway"]:::api
        MQTTModule["MQTT Module"]:::backend
        MQTTService["MQTT Service"]:::backend
        PromModule["Prometheus Metrics Module"]:::monitoring
        Scheduler["Scheduler"]:::backend
        LoggerSvc["Logger Service"]:::backend
        LogInterceptor["Logging Interceptor"]:::backend
        EntryPoint["main.ts"]:::backend
    end

    %% Database Layer
    subgraph "Database"
        MariaDB[(MariaDB)]:::db
    end

    %% Monitoring Layer
    subgraph "Monitoring"
        Prometheus[(Prometheus)]:::monitoring
        Grafana[(Grafana)]:::monitoring
    end

    %% Frontend Layer
    subgraph "Next.js Frontend"
        direction TB
        FrontendRoot["Frontend (Next.js)"]:::frontend
        AuthRoute["Auth Routes"]:::frontend
        UserHives["User Hives Page"]:::frontend
        UserPresets["User Presets Page"]:::frontend
        Layout["Global Layout"]:::frontend
        Providers["Providers & Auth Wrapper"]:::frontend
        Components["UI Components"]:::frontend
        Context["Auth Context"]:::frontend
        Helpers["Helpers & Hooks"]:::frontend
        Types["Types"]:::frontend
    end

    %% Connections
    ESP32 --> MQTT
    NodeRED --> MQTT
    MQTT --> BackendRoot
    BackendRoot --> MariaDB
    BackendRoot -->|"/metrics"| Prometheus
    Prometheus --> Grafana
    FrontendRoot -->|REST / WebSocket| BackendRoot

    %% Backend internals connections
    BackendRoot --> AuthCtrl
    BackendRoot --> DeviceCtrl
    BackendRoot --> MetricsCtrl
    BackendRoot --> PresetCtrl
    BackendRoot --> ConfigCtrl
    BackendRoot --> UserCtrl
    BackendRoot --> Gateway
    BackendRoot --> MQTTModule
    MQTTModule --> MQTTService
    BackendRoot --> PromModule
    BackendRoot --> Scheduler
    BackendRoot --> LoggerSvc
    BackendRoot --> LogInterceptor
    BackendRoot --> EntryPoint

    %% Frontend internals connections
    FrontendRoot --> AuthRoute
    FrontendRoot --> UserHives
    FrontendRoot --> UserPresets
    FrontendRoot --> Layout
    FrontendRoot --> Providers
    FrontendRoot --> Components
    FrontendRoot --> Context
    FrontendRoot --> Helpers
    FrontendRoot --> Types

    %% Click Events
    click MQTT "https://github.com/henferper/mundobee/blob/main/mosquitto/mosquitto.conf"
    click BackendRoot "https://github.com/henferper/mundobee/tree/main/backend/"
    click AuthCtrl "https://github.com/henferper/mundobee/blob/main/backend/src/auth/auth.controller.ts"
    click DeviceCtrl "https://github.com/henferper/mundobee/blob/main/backend/src/device/device.controller.ts"
    click MetricsCtrl "https://github.com/henferper/mundobee/blob/main/backend/src/metrics/metrics.controller.ts"
    click PresetCtrl "https://github.com/henferper/mundobee/blob/main/backend/src/presets/preset.controller.ts"
    click ConfigCtrl "https://github.com/henferper/mundobee/blob/main/backend/src/configuration/configuration.controller.ts"
    click UserCtrl "https://github.com/henferper/mundobee/blob/main/backend/src/user/user.controller.ts"
    click Gateway "https://github.com/henferper/mundobee/blob/main/backend/src/app.gateway.ts"
    click MQTTModule "https://github.com/henferper/mundobee/blob/main/backend/src/mqtt/mqtt.module.ts"
    click MQTTService "https://github.com/henferper/mundobee/blob/main/backend/src/mqtt/mqtt.service.ts"
    click PromModule "https://github.com/henferper/mundobee/blob/main/backend/src/metrics/metrics.module.ts"
    click Scheduler "https://github.com/henferper/mundobee/blob/main/backend/src/schedules/scheduler.ts"
    click LoggerSvc "https://github.com/henferper/mundobee/blob/main/backend/src/logger/log.service.ts"
    click LogInterceptor "https://github.com/henferper/mundobee/blob/main/backend/src/logging.interceptor.ts"
    click EntryPoint "https://github.com/henferper/mundobee/blob/main/backend/src/main.ts"
    click MariaDB "https://github.com/henferper/mundobee/blob/main/docker-compose.yml"
    click Prometheus "https://github.com/henferper/mundobee/blob/main/prometheus/prometheus.yml"
    click Grafana "https://github.com/henferper/mundobee/blob/main/grafana/prom-client-dashboard.json"
    click FrontendRoot "https://github.com/henferper/mundobee/tree/main/client/"
    click AuthRoute "https://github.com/henferper/mundobee/blob/main/client/src/app/(auth-routes)/signin/page.tsx"
    click UserHives "https://github.com/henferper/mundobee/blob/main/client/src/app/(user-routes)/hives/page.tsx"
    click UserPresets "https://github.com/henferper/mundobee/blob/main/client/src/app/(user-routes)/presets/page.tsx"
    click Layout "https://github.com/henferper/mundobee/blob/main/client/src/app/layout.tsx"
    click Providers "https://github.com/henferper/mundobee/blob/main/client/src/app/providers.tsx"
    click Helpers "https://github.com/henferper/mundobee/blob/main/client/src/helper/hooks/useAxios.tsx"
    click Context "https://github.com/henferper/mundobee/blob/main/client/src/context/authContext.tsx"
    click Types "https://github.com/henferper/mundobee/tree/main/client/src/types/"
    click Components "https://github.com/henferper/mundobee/tree/main/client/src/components/"
    click NodeRED "https://github.com/henferper/mundobee/blob/main/node-red/flows.json"

    %% Styles
    classDef iot fill:#FFEDA7,stroke:#333,stroke-width:1px;
    classDef broker fill:#AEDFF7,stroke:#333,stroke-width:1px;
    classDef simulation fill:#E3F7D3,stroke:#333,stroke-width:1px;
    classDef backend fill:#F7D1E3,stroke:#333,stroke-width:1px;
    classDef api fill:#E8B4A0,stroke:#333,stroke-width:1px;
    classDef db fill:#F0E68C,stroke:#333,stroke-width:1px;
    classDef monitoring fill:#D4E157,stroke:#333,stroke-width:1px;
    classDef frontend fill:#B3E5FC,stroke:#333,stroke-width:1px;
```
