# diogox451/datanumbers-iot architecture

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

- Interactive diagram: https://gitdiagram.com/diogox451/datanumbers-iot
- Repository: https://github.com/diogox451/datanumbers-iot

## Overview

##### Project type and purpose
- This is an IoT-platform composed of multiple microservices and a web client.
- Purpose: gather sensor data (via MQTT), centralize processing (via Pulsar queues), persist/analyze it (TimescaleDB/Postgres), manage devices, and provide a web interface.

##### File structure
- Top level:
- arduino/… → firmware for a temperature sensor.
- auth/… → Go-based authentication microservice (REST + JWT + Redis + Postgres).
- data-management-service/… → Spring Boot service for persisting and retrieving IoT data (Postgres, TimescaleDB, Pulsar).
- device_manager/… → Spring Boot microservice for device & template management (Postgres, Pulsar client).
- datanumbers-iot-web/… → Next.js/TypeScript web frontend.
- gateway-emqx/… → Go service that hooks into EMQX via gRPC for inbound MQTT messages, writes to Postgres and publishes to Pulsar.
- docker-compose.yaml → composition of all services and infrastructure (EMQX broker, Pulsar broker, Postgres, TimescaleDB, Redis, the microservices, and web UI).

##### Key insights from the README
- Gateways: EMQX for MQTT.
- Queue broker: Pulsar.
- Microservices: modular, distributed, written in Go and Spring Boot.
- Web UI in Next.js.

##### Detail without overthinking
- Break each microservice into two conceptual layers if desired: API/ingestion and persistence/service.
- Queues/topics and datastores.
- Avoid lumping everything together—show each microservice, its ingress/egress, and its data stores as separate components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Infrastructure
    subgraph "Infrastructure" 
        direction TB
        EMQX["EMQX Broker"]:::infra
        Pulsar["Pulsar Broker"]:::infra
        PostgresDB["PostgreSQL"]:::infra
        TimescaleDB["TimescaleDB"]:::infra
        RedisDB["Redis"]:::infra
    end

    %% Edge Devices
    IoT["IoT Devices<br/>(Arduino)"]:::infra

    %% Microservices
    subgraph "Go Microservices" 
        direction TB
        GW["gateway-emqx<br/>(Go)"]:::micro-go
        AUTH["auth service<br/>(Go)"]:::micro-go
    end

    subgraph "Java Microservices"
        direction TB
        DATA["data-management-service<br/>(Spring Boot)"]:::micro-java
        DEV["device_manager<br/>(Spring Boot)"]:::micro-java
    end

    %% Frontend
    UI["datanumbers-iot-web<br/>(Next.js)"]:::ui

    %% Flows
    IoT -->|"MQTT"| EMQX
    EMQX -->|"gRPC"| GW
    GW -->|"write"| PostgresDB
    GW -.-|"publish raw-telemetry"| Pulsar

    Pulsar -.-|"subscribe raw-telemetry"| DATA
    DATA -->|"persist ts data"| TimescaleDB
    DATA -->|"persist meta data"| PostgresDB

    Pulsar -.-|"device-events"| DEV
    DEV -->|"persist device data"| PostgresDB

    UI -->|"REST+JWT"| AUTH
    AUTH -->|"validate"| RedisDB
    AUTH -->|"validate"| PostgresDB

    UI -->|"REST"| DEV
    UI -->|"REST"| DATA

    %% Click Events
    click IoT "https://github.com/diogox451/datanumbers-iot/blob/main/arduino/sensor_temperatura/sensor_temperatura.ino"
    click GW "https://github.com/diogox451/datanumbers-iot/blob/main/gateway-emqx/gateway/main.go"
    click DATA "https://github.com/diogox451/datanumbers-iot/blob/main/data-management-service/src/main/java/com/datanumbersiot/config/PulsarConfig.java"
    click DEV "https://github.com/diogox451/datanumbers-iot/blob/main/device_manager/src/main/java/com/data_numbers_iot/device_manager/DeviceManagerApplication.java"
    click AUTH "https://github.com/diogox451/datanumbers-iot/blob/main/auth/api/main.go"
    click UI "https://github.com/diogox451/datanumbers-iot/tree/main/datanumbers-iot-web/pages"
    click EMQX "https://github.com/diogox451/datanumbers-iot/blob/main/docker-compose.yaml"
    click Pulsar "https://github.com/diogox451/datanumbers-iot/blob/main/docker-compose.yaml"
    click PostgresDB "https://github.com/diogox451/datanumbers-iot/blob/main/docker-compose.yaml"
    click TimescaleDB "https://github.com/diogox451/datanumbers-iot/blob/main/docker-compose.yaml"
    click RedisDB "https://github.com/diogox451/datanumbers-iot/blob/main/auth/internal/config/redis.go"

    %% Styles
    classDef infra fill:#ccffcc,stroke:#006600,stroke-width:1px
    classDef micro-go fill:#cce5ff,stroke:#003366,stroke-width:1px
    classDef micro-java fill:#ffe5cc,stroke:#663300,stroke-width:1px
    classDef ui fill:#ffffcc,stroke:#666600,stroke-width:1px
```
