# nhattannn222/customdevicehive architecture

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

- Interactive diagram: https://gitdiagram.com/nhattannn222/customdevicehive
- Repository: https://github.com/nhattannn222/customdevicehive

## Overview

##### Project Overview & Main Components
- This is a full-stack, containerized IoT management platform built on the open-source DeviceHive solution. It integrates additional functionality such as data storage and dashboarding (tracking temperature and humidity from an ESP8266 reading from a DHT11 sensor).
- The main components include:
- DeviceHive Containers: These include separate containers for DeviceHive’s backend, frontend, and authentication services (as referenced in the README log outputs – e.g. dh_backend, dh_frontend, dh_auth).
- Node.js Application: Found in the node_app directory; it likely handles custom business logic, REST API endpoints, or acts as a middleware component.
- ESP8266 Firmware: Located under the ESP8266_FIRMWARE folder, this is the Arduino sketch that runs on the IoT hardware, interfacing with the DHT11 sensor.
- Monitoring & Metrics: The lib/monitoring directory houses configuration files for Grafana dashboards, Prometheus, and possibly integrations with Kafka and a JMX Prometheus Java agent.
- Reverse Proxy / Messaging: The presence of nginx and MQTT broker configuration files implies components that manage routing and/or real-time messaging between devices and the platform.
- Auxiliary Docker & Environment Files: docker-compose.yml anchors the service orchestration.

##### Highlighting Architectural Patterns & Design Principles
- A containerized microservices architecture orchestrated via Docker Compose.
- Clearly separate concerns: device firmware at the edge (ESP8266), middleware (Node.js app), and backend services (DeviceHive-based containers).
- Integration points with external services (e.g., MQTT broker via Nginx configuration and the monitoring stack).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Containerized Services
    subgraph "Containerized Services"
        dh_backend["dh_backend"] 
        dh_frontend["dh_frontend"]
        dh_auth["dh_auth"]
        dh_plugins["dh_plugins"]
    end

    %% Application & Integration
    subgraph "Application & Integration"
        node_app["Node.js Application"]
        admin_console["Admin Console (http://localhost/admin)"]
        api_gateway["API Gateway (Swagger Endpoints)"]
        reverse_proxy["NGINX/MQTT Broker"]
    end

    %% Edge Devices
    subgraph "Edge Devices"
        firmware["IoT Device (ESP8266 + DHT11 Firmware)"]
    end

    %% Monitoring & Metrics
    subgraph "Monitoring & Metrics"
        grafana["Grafana Dashboard (http://localhost/grafana)"]
        prometheus["Prometheus"]
        kafka["Kafka"]
    end

    %% Data Storage
    subgraph "Data Storage"
        database["Database"]
    end

    %% Data flows:
    firmware -->|"sendsData(MQTT/HTTP)"| dh_backend
    node_app -->|"callsAPI"| dh_backend
    node_app -->|"callsAPI"| dh_frontend
    node_app -->|"callsAPI"| dh_auth

    dh_backend -->|"storesData"| database

    dh_backend -->|"reportsMetrics"| prometheus
    prometheus -->|"feedsData"| grafana
    prometheus -->|"streams"| kafka

    dh_frontend -->|"exposesUI"| admin_console
    dh_auth -->|"authenticates"| admin_console

    reverse_proxy -->|"routesTo"| dh_backend
    reverse_proxy -->|"routesTo"| dh_frontend
    reverse_proxy -->|"routesTo"| dh_auth

    admin_console -->|"adminOps"| dh_backend

    %% Click Events
    click dh_backend "https://github.com/nhattannn222/customdevicehive/blob/main/docker-compose.yml"
    click dh_frontend "https://github.com/nhattannn222/customdevicehive/blob/main/docker-compose.yml"
    click dh_auth "https://github.com/nhattannn222/customdevicehive/blob/main/docker-compose.yml"
    click dh_plugins "https://github.com/nhattannn222/customdevicehive/blob/main/docker-compose.yml"
    click node_app "https://github.com/nhattannn222/customdevicehive/tree/main/node_app/"
    click firmware "https://github.com/nhattannn222/customdevicehive/blob/main/ESP8266_FIRMWARE/ESP8266_FIRMWARE.ino"
    click grafana "https://github.com/nhattannn222/customdevicehive/tree/main/lib/monitoring/"
    click prometheus "https://github.com/nhattannn222/customdevicehive/tree/main/lib/monitoring/"
    click reverse_proxy "https://github.com/nhattannn222/customdevicehive/blob/main/nginx-mqtt-brokers.conf"

    %% Styles
    classDef container fill:#AED6F1,stroke:#2471A3,stroke-width:2px,color:#1B4F72;
    classDef app fill:#D5F5E3,stroke:#28B463,stroke-width:2px,color:#1D8348;
    classDef device fill:#FADBD8,stroke:#C0392B,stroke-width:2px,color:#641E16;
    classDef monitoring fill:#FCF3CF,stroke:#B7950B,stroke-width:2px,color:#7D6608;
    classDef storage fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px,color:#512E5F;

    %% Assign classes to nodes
    class dh_backend,dh_frontend,dh_auth,dh_plugins container;
    class node_app,admin_console,api_gateway,reverse_proxy app;
    class firmware device;
    class grafana,prometheus,kafka monitoring;
    class database storage;
```
