How pocketix/riot works
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: src React UI · api/graphql GraphQL API · rabbitmq RabbitMQ · src/graphql GraphQL Client
Components 22
Frontend
Active React/TypeScript UI and client-side state
- React UI · Current browser application with feature-based screens and live monitoring views
frontend/src - GraphQL Client · Typed queries, mutations, subscriptions, and generated API bindings
frontend/src/graphql - Dashboard · Monitoring dashboards, charts, cards, and layout editing
frontend/src/features/dashboard - Settings · KPI definitions, device types, personal info, and related admin flows
frontend/src/features/settings - Devices & Groups · Detail pages and feature screens for devices, groups, and members
frontend/src/features/devices - Login · 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 · Central Go service exposing API, auth, and domain orchestration
backend/backend-core/src - GraphQL API · Schema, resolvers, subscriptions, and API setup
backend/backend-core/src/api/graphql - Auth · Login handlers, cookies, JWT, and request protection
backend/backend-core/src/auth - Domain Logic · Users, programs, procedures, KPI definitions, device types, groups, and instances
backend/backend-core/src/domainLogicLayer - Model Layers · Persistence, domain, and GraphQL shapes plus conversion boundaries
backend/backend-core/src/model - Model Mapping · db2dll, dll2db, dll2gql, and gql2dll conversion packages
backend/backend-core/src/modelMapping - DB Client · 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 · Reads raw MQTT telemetry and normalizes it for internal processing
backend/mqtt-preprocessor/src - Message Worker · Consumes internal messages and runs KPI fulfillment checks
backend/message-processing-unit/src/processing - Interpret Unit · Isolated runtime for KPI or procedure interpretation
backend/interpret-unit/src
Storage & Ops
Relational, time-series, messaging, and observability infrastructure
- RabbitMQ · Internal event backbone between preprocessing and worker services
backend/commons/src/rabbitmq - Time-Series Store · Telemetry persistence boundary for dashboarding and history
backend/time-series-store/src/internal - PostgreSQL · Stores users, KPI definitions, device metadata, groups, procedures, and links
- Mosquitto MQTT · External ingress broker for device telemetry
docker/mosquitto-config/mosquitto.conf - Prometheus/Grafana · 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 · Previous frontend implementation kept alongside the active app
frontend-old/src
Connections 22
- 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