# pocketix/riot architecture

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

- Interactive diagram: https://gitdiagram.com/pocketix/riot
- Repository: https://github.com/pocketix/riot

## Overview

1. **Overall shape**
   - This repo is a containerized, multi-service IoT monitoring system written mostly in Go, with a separate React/TypeScript frontend.
   - The main architectural idea is a split between:
     - a **control plane** for CRUD, auth, and KPI configuration,
     - a **data plane** for ingesting device telemetry and evaluating KPIs in near real time.

2. **Frontend boundary**
   - The active UI is in `frontend/` and is a Vite + React app using GraphQL/Apollo and generated typed client code.
   - It is organized by feature areas such as dashboard, devices, groups, members, settings, and automations.
   - `frontend-old/` is a legacy/older UI implementation kept in the repo; it mirrors similar concepts but should be treated as separate from the current frontend.
   - The frontend talks primarily to the backend core through GraphQL queries, mutations, and subscriptions on port `9090`, and renders live monitoring views on port `8080`.

3. **Backend core as the API and domain hub**
   - `backend/backend-core` is the central backend service.
   - It exposes the GraphQL API, hosts auth middleware/handlers, and contains the domain logic for users, programs, procedures, KPI definitions, device types, groups, and instances.
   - GraphQL is generated with `gqlgen`, so the API layer is strongly tied to the schema and resolver files under `src/api/graphql`.

4. **Layered model separation**
   - The core backend explicitly separates three model layers:
     - `dbModel` for persistence shape,
     - `dllModel` for domain logic shape,
     - `graphQLModel` for API shape.
   - The `modelMapping` packages (`db2dll`, `dll2db`, `dll2gql`, `gql2dll`) are the main architecture boundary between these layers.
   - This is important for the diagram: most business operations flow through conversion layers rather than exposing database entities directly to the API.

5. **Persistence and relational data**
   - PostgreSQL is the relational store used by the backend system.
   - `backend/backend-core/src/db/dbClient` and related utilities are the DB access boundary.
   - This database likely stores configuration and identity data: users, KPI definitions, device/SD types, instances, groups, procedures, and program links.
   - The database is separate from the telemetry/time-series path.

6. **Realtime telemetry ingestion path**
   - The system uses **Mosquitto MQTT** as the external device ingress broker.
   - `backend/mqtt-preprocessor` is a dedicated Go service for reading raw MQTT data and pre-processing it into the system’s internal message flow.
   - The preprocessor feeds the internal messaging backbone, which is based on **RabbitMQ**.
   - This creates a clear boundary: MQTT handles device-facing ingestion; RabbitMQ carries internal processing events.

7. **Processing and KPI evaluation**
   - `backend/message-processing-unit` is the worker side of the system and appears designed for consuming internal messages and running KPI fulfillment checks.
   - `backend/interpret-unit` is a separate Go service, suggesting KPI/procedure interpretation is isolated into its own runtime component.
   - Shared message and KPI-related types live in `backend/commons/src/sharedModel`, indicating these services exchange common, versioned payloads rather than ad hoc structures.

8. **Time-series storage**
   - `backend/time-series-store` is a dedicated service with an InfluxDB 2 client implementation.
   - This is the system’s telemetry/time-series boundary, separate from PostgreSQL.
   - The likely flow is: device telemetry arrives via MQTT, is preprocessed and processed, and then relevant series/measurement data is persisted into the time-series store for dashboarding and historical analysis.

9. **Shared backend library**
   - `backend/commons` is a cross-service Go module used to avoid duplicating messaging contracts, constants, utilities, and helper types.
   - It contains RabbitMQ client code, shared constants, shared models, and utility functions.
   - Architecturally, this is the glue between the independently deployed Go services.

10. **Live updates and subscriptions**
   - The backend GraphQL layer exposes subscriptions such as KPI fulfillment checks and SD instance registration events.
   - This means the frontend is not purely request/response; it also receives pushed updates for monitoring dashboards and live state changes.
   - The architecture therefore combines API reads/writes with event-driven real-time updates.

11. **Security and session handling**
   - Authentication is implemented in the backend core with JWT, cookies, and middleware.
   - That suggests browser sessions are managed at the API boundary, with the frontend relying on authenticated GraphQL calls rather than direct backend trust.
   - This is a clear perimeter in the diagram: unauthenticated access is limited to login/bootstrap flows.

12. **Operational deployment**
   - The system is intended to run through `docker-compose.yml`, with individual service containers and optional scaling of the message-processing workers.
   - Monitoring/ops services are included: **Prometheus**, **Grafana**, and optional **pgAdmin**.
   - The repo also includes a RabbitMQ broker, Mosquitto config, and Grafana dashboard provisioning, so infrastructure is part of the architecture rather than external glue.

13. **Practical diagram takeaway**
   - A good architecture diagram should show four main zones:
     - **Browser/UI**: React frontend,
     - **API/domain**: backend core with GraphQL/auth/db,
     - **stream processing**: MQTT preprocessor, RabbitMQ, message-processing/interpret units,
     - **storage/observability**: PostgreSQL, InfluxDB, Prometheus/Grafana.
   - The key data flow is:
     - user config and queries go through GraphQL to PostgreSQL-backed domain logic,
     - device telemetry enters via MQTT, is transformed into internal messages, processed by workers, and stored/used for KPI evaluation and live UI updates.

Main entry points: [`frontend/src`](https://github.com/pocketix/riot/tree/main/frontend/src) (React UI), [`backend/backend-core/src/api/graphql`](https://github.com/pocketix/riot/tree/main/backend/backend-core/src/api/graphql) (GraphQL API), [`backend/commons/src/rabbitmq`](https://github.com/pocketix/riot/tree/main/backend/commons/src/rabbitmq) (RabbitMQ), [`frontend/src/graphql`](https://github.com/pocketix/riot/tree/main/frontend/src/graphql) (GraphQL Client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["React UI<br/>vite-react app"]
  node_frontend_graphql["GraphQL Client<br/>apollo client"]
  node_frontend_dashboard["Dashboard<br/>live views"]
  node_frontend_settings["Settings<br/>admin screens"]
  node_frontend_entities["Devices & Groups<br/>domain screens"]
  node_frontend_auth["Login<br/>auth UI"]
end

subgraph group_backend_core["API Core"]
  node_backend_api["Backend Core<br/>graphql-api"]
  node_backend_graphql["GraphQL API<br/>gqlgen layer"]
  node_backend_auth["Auth<br/>jwt-cookie middleware"]
  node_backend_domain["Domain Logic<br/>business rules"]
  node_backend_models["Model Layers<br/>db-dll-gql models"]
  node_backend_mapping["Model Mapping<br/>transformers"]
  node_backend_db[("DB Client<br/>postgres access")]
end

subgraph group_streaming["Streaming"]
  node_mqtt_pre["MQTT Preprocessor<br/>go service"]
  node_msg_worker["Message Worker<br/>kpi processor"]
  node_interpret_unit["Interpret Unit<br/>procedure engine"]
end

subgraph group_storage_ops["Storage & Ops"]
  node_rabbitmq["RabbitMQ<br/>message broker"]
  node_timeseries[("Time-Series Store<br/>influxdb client")]
  node_postgres[("PostgreSQL<br/>relational store")]
  node_mosquitto["Mosquitto MQTT<br/>device broker<br/>[mosquitto.conf]"]
  node_monitoring["Prometheus/Grafana<br/>observability<br/>[prometheus.yml]"]
end

subgraph group_legacy_ui["Legacy UI"]
  node_legacy_frontend["Legacy UI<br/>older react app"]
end

node_frontend_app -->|"queries"| node_frontend_graphql
node_frontend_app -->|"renders"| node_frontend_dashboard
node_frontend_app -->|"renders"| node_frontend_settings
node_frontend_app -->|"renders"| node_frontend_entities
node_frontend_app -->|"auth flow"| node_frontend_auth
node_frontend_graphql -->|"API calls"| node_backend_graphql
node_backend_graphql -->|"protects"| node_backend_auth
node_backend_graphql -->|"resolves"| node_backend_domain
node_backend_domain -->|"maps via"| node_backend_mapping
node_backend_mapping -->|"converts"| node_backend_models
node_backend_models -->|"persists via"| node_backend_db
node_backend_db -->|"stores"| node_postgres
node_frontend_graphql -->|"subscriptions"| node_backend_graphql
node_mosquitto -->|"telemetry in"| node_mqtt_pre
node_mqtt_pre -->|"publishes"| node_rabbitmq
node_rabbitmq -->|"consumes"| node_msg_worker
node_rabbitmq -->|"consumes"| node_interpret_unit
node_msg_worker -->|"writes"| node_timeseries
node_timeseries -->|"feeds"| node_frontend_dashboard
node_monitoring -.->|"observes"| node_backend_api
node_monitoring -.->|"observes"| node_rabbitmq
node_legacy_frontend -.->|"legacy api"| node_backend_graphql

click node_frontend_app "https://github.com/pocketix/riot/tree/main/frontend/src"
click node_frontend_graphql "https://github.com/pocketix/riot/tree/main/frontend/src/graphql"
click node_frontend_dashboard "https://github.com/pocketix/riot/tree/main/frontend/src/features/dashboard"
click node_frontend_settings "https://github.com/pocketix/riot/tree/main/frontend/src/features/settings"
click node_frontend_entities "https://github.com/pocketix/riot/tree/main/frontend/src/features/devices"
click node_frontend_auth "https://github.com/pocketix/riot/tree/main/frontend/src/features/authentication"
click node_backend_api "https://github.com/pocketix/riot/tree/main/backend/backend-core/src"
click node_backend_graphql "https://github.com/pocketix/riot/tree/main/backend/backend-core/src/api/graphql"
click node_backend_auth "https://github.com/pocketix/riot/tree/main/backend/backend-core/src/auth"
click node_backend_domain "https://github.com/pocketix/riot/tree/main/backend/backend-core/src/domainLogicLayer"
click node_backend_models "https://github.com/pocketix/riot/tree/main/backend/backend-core/src/model"
click node_backend_mapping "https://github.com/pocketix/riot/tree/main/backend/backend-core/src/modelMapping"
click node_backend_db "https://github.com/pocketix/riot/tree/main/backend/backend-core/src/db/dbClient"
click node_mqtt_pre "https://github.com/pocketix/riot/tree/main/backend/mqtt-preprocessor/src"
click node_rabbitmq "https://github.com/pocketix/riot/tree/main/backend/commons/src/rabbitmq"
click node_msg_worker "https://github.com/pocketix/riot/tree/main/backend/message-processing-unit/src/processing"
click node_interpret_unit "https://github.com/pocketix/riot/tree/main/backend/interpret-unit/src"
click node_timeseries "https://github.com/pocketix/riot/tree/main/backend/time-series-store/src/internal"
click node_mosquitto "https://github.com/pocketix/riot/blob/main/docker/mosquitto-config/mosquitto.conf"
click node_monitoring "https://github.com/pocketix/riot/blob/main/docker/prometheus.yml"
click node_legacy_frontend "https://github.com/pocketix/riot/tree/main/frontend-old/src"

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_frontend_app,node_frontend_graphql,node_frontend_dashboard,node_frontend_settings,node_frontend_entities,node_frontend_auth toneBlue
class node_backend_api,node_backend_graphql,node_backend_auth,node_backend_domain,node_backend_models,node_backend_mapping,node_backend_db toneAmber
class node_mqtt_pre,node_msg_worker,node_interpret_unit toneMint
class node_rabbitmq,node_timeseries,node_postgres,node_mosquitto,node_monitoring toneRose
class node_legacy_frontend toneIndigo
```

## Components

### Frontend

Active React/TypeScript UI and client-side state

- [React UI](https://github.com/pocketix/riot/tree/main/frontend/src): vite-react app · Current browser application with feature-based screens and live monitoring views · `frontend/src`
- [GraphQL Client](https://github.com/pocketix/riot/tree/main/frontend/src/graphql): apollo client · Typed queries, mutations, subscriptions, and generated API bindings · `frontend/src/graphql`
- [Dashboard](https://github.com/pocketix/riot/tree/main/frontend/src/features/dashboard): live views · Monitoring dashboards, charts, cards, and layout editing · `frontend/src/features/dashboard`
- [Settings](https://github.com/pocketix/riot/tree/main/frontend/src/features/settings): admin screens · KPI definitions, device types, personal info, and related admin flows · `frontend/src/features/settings`
- [Devices & Groups](https://github.com/pocketix/riot/tree/main/frontend/src/features/devices): domain screens · Detail pages and feature screens for devices, groups, and members · `frontend/src/features/devices`
- [Login](https://github.com/pocketix/riot/tree/main/frontend/src/features/authentication): auth UI · User sign-in entry point and protected route boundary · `frontend/src/features/authentication`

### API Core

GraphQL API, auth, domain logic, and relational persistence

- [Backend Core](https://github.com/pocketix/riot/tree/main/backend/backend-core/src): graphql-api · Central Go service exposing API, auth, and domain orchestration · `backend/backend-core/src`
- [GraphQL API](https://github.com/pocketix/riot/tree/main/backend/backend-core/src/api/graphql): gqlgen layer · Schema, resolvers, subscriptions, and API setup · `backend/backend-core/src/api/graphql`
- [Auth](https://github.com/pocketix/riot/tree/main/backend/backend-core/src/auth): jwt-cookie middleware · Login handlers, cookies, JWT, and request protection · `backend/backend-core/src/auth`
- [Domain Logic](https://github.com/pocketix/riot/tree/main/backend/backend-core/src/domainLogicLayer): business rules · Users, programs, procedures, KPI definitions, device types, groups, and instances · `backend/backend-core/src/domainLogicLayer`
- [Model Layers](https://github.com/pocketix/riot/tree/main/backend/backend-core/src/model): db-dll-gql models · Persistence, domain, and GraphQL shapes plus conversion boundaries · `backend/backend-core/src/model`
- [Model Mapping](https://github.com/pocketix/riot/tree/main/backend/backend-core/src/modelMapping): transformers · db2dll, dll2db, dll2gql, and gql2dll conversion packages · `backend/backend-core/src/modelMapping`
- [DB Client](https://github.com/pocketix/riot/tree/main/backend/backend-core/src/db/dbClient): postgres access · Database access boundary for configuration and identity data · `backend/backend-core/src/db/dbClient`

### Streaming

Telemetry ingestion, internal messaging, and KPI processing services

- [MQTT Preprocessor](https://github.com/pocketix/riot/tree/main/backend/mqtt-preprocessor/src): go service · Reads raw MQTT telemetry and normalizes it for internal processing · `backend/mqtt-preprocessor/src`
- [Message Worker](https://github.com/pocketix/riot/tree/main/backend/message-processing-unit/src/processing): kpi processor · Consumes internal messages and runs KPI fulfillment checks · `backend/message-processing-unit/src/processing`
- [Interpret Unit](https://github.com/pocketix/riot/tree/main/backend/interpret-unit/src): procedure engine · Isolated runtime for KPI or procedure interpretation · `backend/interpret-unit/src`

### Storage & Ops

Relational, time-series, messaging, and observability infrastructure

- [RabbitMQ](https://github.com/pocketix/riot/tree/main/backend/commons/src/rabbitmq): message broker · Internal event backbone between preprocessing and worker services · `backend/commons/src/rabbitmq`
- [Time-Series Store](https://github.com/pocketix/riot/tree/main/backend/time-series-store/src/internal): influxdb client · Telemetry persistence boundary for dashboarding and history · `backend/time-series-store/src/internal`
- **PostgreSQL**: relational store · Stores users, KPI definitions, device metadata, groups, procedures, and links
- [Mosquitto MQTT](https://github.com/pocketix/riot/blob/main/docker/mosquitto-config/mosquitto.conf): device broker · External ingress broker for device telemetry · `docker/mosquitto-config/mosquitto.conf`
- [Prometheus/Grafana](https://github.com/pocketix/riot/blob/main/docker/prometheus.yml): observability · Metrics scraping and dashboard provisioning for operations · `docker/prometheus.yml`

### Legacy UI

Older frontend kept in the repo separately from the active app

- [Legacy UI](https://github.com/pocketix/riot/tree/main/frontend-old/src): older react app · Previous frontend implementation kept alongside the active app · `frontend-old/src`

## Connections

- React UI → GraphQL Client: queries · UI reads and mutates system state through typed GraphQL operations
- React UI → Dashboard: renders · Dashboard pages compose cards, charts, and live layouts
- React UI → Settings: renders · Admin and configuration screens are built from feature modules
- React UI → Devices & Groups: renders · Device, group, and member views are exposed as app features
- React UI → Login: auth flow · Login and protected-route handling gate access to the UI
- GraphQL Client → GraphQL API: API calls · Apollo client targets the backend GraphQL boundary
- GraphQL API → Auth: protects · Request handling uses middleware, JWT, and cookie session logic
- GraphQL API → Domain Logic: resolves · Resolvers delegate business operations to domain logic
- Domain Logic → Model Mapping: maps via · Domain operations cross persistence and API shapes through converters
- Model Mapping → Model Layers: converts · Model mapping mediates between db, domain, and GraphQL layers
- Model Layers → DB Client: persists via · Persistence-facing models are stored and loaded through the DB client
- DB Client → PostgreSQL: stores · Relational configuration and identity data live in PostgreSQL
- GraphQL Client → GraphQL API: subscriptions · Live UI receives pushed KPI and registration events
- Mosquitto MQTT → MQTT Preprocessor: telemetry in · Device-facing MQTT messages enter the preprocessor
- MQTT Preprocessor → RabbitMQ: publishes · Preprocessed events are forwarded into the internal broker
- RabbitMQ → Message Worker: consumes · Workers read internal events for KPI checks and processing
- RabbitMQ → Interpret Unit: consumes · Interpretation runtime can be fed from the same event backbone
- Message Worker → Time-Series Store: writes · Processed telemetry and KPI-related data reach time-series storage
- Time-Series Store → Dashboard: feeds · Historical and live metric data support dashboard visuals
- Prometheus/Grafana → Backend Core: observes · Operational tooling monitors the deployed service set
- Prometheus/Grafana → RabbitMQ: observes · Broker health and load are part of operations visibility
- Legacy UI → GraphQL API: legacy api · Older UI implementation used the same backend API surface
