# nemo2547/iot--backend-system architecture

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

- Interactive diagram: https://gitdiagram.com/nemo2547/iot--backend-system
- Repository: https://github.com/nemo2547/iot--backend-system

## Overview

This is an IoT backend for device telemetry, status lookup, account access, and high-voltage alert dispatch. Its documented cache-aside workflow stores telemetry in PostgreSQL, updates Redis, and serves device status from cache or falls back to PostgreSQL. The sampled application mounts separate telemetry and device routes, while the cache-aside implementation is in an unmounted routes module; the graph preserves both without implying they form one live route. Worker internals were not excerpted, so no queue-consumer behavior is asserted.

Main entry points: [`src/app.js`](https://github.com/nemo2547/iot--backend-system/blob/main/src/app.js) (API App), [`src/routes/routes.js`](https://github.com/nemo2547/iot--backend-system/blob/main/src/routes/routes.js) (Cached Status), [`src/index.js`](https://github.com/nemo2547/iot--backend-system/blob/main/src/index.js) (Server Entry), [`src/routes/auth.js`](https://github.com/nemo2547/iot--backend-system/blob/main/src/routes/auth.js) (Auth Routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_entry["Server Entry<br/>[index.js]"]
  node_express["API App<br/>[app.js]"]
  node_deviceroutes["Device Routes<br/>[devices.js]"]
end

subgraph group_identity["Identity and Access"]
  node_authroutes["Auth Routes<br/>[auth.js]"]
  node_authguard["Token Guard<br/>[auth.js]"]
end

subgraph group_telemetry["Telemetry and Cache"]
  node_telemetryroutes["Alert Ingest<br/>[telemetry.js]"]
  node_cacheroutes["Cached Status<br/>[routes.js]"]
  node_dataclients["Data Clients<br/>[db.js]"]
  node_postgres[("PostgreSQL<br/>[schema.prisma]")]
  node_redis[("Redis Cache")]
end

subgraph group_async["Async Alerts"]
  node_rabbitconfig["Queue Publisher<br/>[rabbitmq.js]"]
  node_rabbitmq["RabbitMQ"]
  node_worker["Alert Worker<br/>[worker.js]"]
end

node_client(("API Client"))

node_client -->|"sends requests"| node_entry
node_entry -->|"starts app"| node_express
node_express -->|"mounts routes"| node_authroutes
node_express -->|"mounts routes"| node_deviceroutes
node_express -->|"mounts routes"| node_telemetryroutes
node_authroutes -->|"reads and writes"| node_postgres
node_deviceroutes -->|"checks token"| node_authguard
node_authroutes -->|"returns token"| node_client
node_telemetryroutes -->|"publishes alerts"| node_rabbitconfig
node_entry -->|"connects queue"| node_rabbitconfig
node_rabbitconfig -->|"sends messages"| node_rabbitmq
node_cacheroutes -->|"uses clients"| node_dataclients
node_dataclients -->|"queries telemetry"| node_postgres
node_dataclients -->|"connects cache"| node_redis
node_cacheroutes -->|"reads and writes"| node_redis
node_cacheroutes -->|"reads and writes"| node_postgres
node_rabbitmq -.->|"possible consumption"| node_worker

click node_entry "https://github.com/nemo2547/iot--backend-system/blob/main/src/index.js"
click node_express "https://github.com/nemo2547/iot--backend-system/blob/main/src/app.js"
click node_authroutes "https://github.com/nemo2547/iot--backend-system/blob/main/src/routes/auth.js"
click node_authguard "https://github.com/nemo2547/iot--backend-system/blob/main/src/middleware/auth.js"
click node_deviceroutes "https://github.com/nemo2547/iot--backend-system/blob/main/src/routes/devices.js"
click node_telemetryroutes "https://github.com/nemo2547/iot--backend-system/blob/main/src/routes/telemetry.js"
click node_cacheroutes "https://github.com/nemo2547/iot--backend-system/blob/main/src/routes/routes.js"
click node_dataclients "https://github.com/nemo2547/iot--backend-system/blob/main/src/db/db.js"
click node_postgres "https://github.com/nemo2547/iot--backend-system/blob/main/prisma/schema.prisma"
click node_rabbitconfig "https://github.com/nemo2547/iot--backend-system/blob/main/src/config/rabbitmq.js"
click node_worker "https://github.com/nemo2547/iot--backend-system/blob/main/src/worker.js"

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_entry,node_express,node_deviceroutes,node_client toneBlue
class node_authroutes,node_authguard toneAmber
class node_telemetryroutes,node_cacheroutes,node_dataclients,node_postgres,node_redis toneMint
class node_rabbitconfig,node_rabbitmq,node_worker toneRose
```

## Components

### HTTP API

- [Server Entry](https://github.com/nemo2547/iot--backend-system/blob/main/src/index.js): `src/index.js`
- [API App](https://github.com/nemo2547/iot--backend-system/blob/main/src/app.js): `src/app.js`
- [Device Routes](https://github.com/nemo2547/iot--backend-system/blob/main/src/routes/devices.js): `src/routes/devices.js`

### Identity and Access

- [Auth Routes](https://github.com/nemo2547/iot--backend-system/blob/main/src/routes/auth.js): `src/routes/auth.js`
- [Token Guard](https://github.com/nemo2547/iot--backend-system/blob/main/src/middleware/auth.js): `src/middleware/auth.js`

### Telemetry and Cache

- [Alert Ingest](https://github.com/nemo2547/iot--backend-system/blob/main/src/routes/telemetry.js): `src/routes/telemetry.js`
- [Cached Status](https://github.com/nemo2547/iot--backend-system/blob/main/src/routes/routes.js): `src/routes/routes.js`
- [Data Clients](https://github.com/nemo2547/iot--backend-system/blob/main/src/db/db.js): `src/db/db.js`
- [PostgreSQL](https://github.com/nemo2547/iot--backend-system/blob/main/prisma/schema.prisma): `prisma/schema.prisma`
- **Redis Cache**

### Async Alerts

- [Queue Publisher](https://github.com/nemo2547/iot--backend-system/blob/main/src/config/rabbitmq.js): `src/config/rabbitmq.js`
- **RabbitMQ**
- [Alert Worker](https://github.com/nemo2547/iot--backend-system/blob/main/src/worker.js): `src/worker.js`

### Other components

- **API Client**

## Connections

- API Client → Server Entry: sends requests (evidence: `readme.txt`)
- Server Entry → API App: starts app (evidence: `src/index.js`)
- API App → Auth Routes: mounts routes (evidence: `src/app.js`)
- API App → Device Routes: mounts routes (evidence: `src/app.js`)
- API App → Alert Ingest: mounts routes (evidence: `src/app.js`)
- Auth Routes → PostgreSQL: reads and writes (evidence: `src/routes/auth.js`)
- Device Routes → Token Guard: checks token (evidence: `src/routes/devices.js`)
- Auth Routes → API Client: returns token (evidence: `src/routes/auth.js`)
- Alert Ingest → Queue Publisher: publishes alerts (evidence: `src/routes/telemetry.js`)
- Server Entry → Queue Publisher: connects queue (evidence: `src/index.js`)
- Queue Publisher → RabbitMQ: sends messages (evidence: `src/config/rabbitmq.js`)
- Cached Status → Data Clients: uses clients (evidence: `src/routes/routes.js`)
- Data Clients → PostgreSQL: queries telemetry (evidence: `src/db/db.js`)
- Data Clients → Redis Cache: connects cache (evidence: `src/db/db.js`)
- Cached Status → Redis Cache: reads and writes (evidence: `src/routes/routes.js`)
- Cached Status → PostgreSQL: reads and writes (evidence: `src/routes/routes.js`)
- RabbitMQ → Alert Worker: possible consumption
