# commerry/web-factorybox architecture

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

- Interactive diagram: https://gitdiagram.com/commerry/web-factorybox
- Repository: https://github.com/commerry/web-factorybox

## Overview

FactoryBox is an IoT monitoring platform: users register and manage devices, devices publish sensor readings over MQTT, and the platform stores readings, evaluates alerts, and serves dashboard/history views with real-time updates. The graph includes documented areas whose source wiring was not sampled; those relationships are marked dashed and unevidenced rather than asserted as inspected calls.

Main entry points: [`backend/src/services/mqtt.service.ts`](https://github.com/commerry/web-factorybox/blob/main/backend/src/services/mqtt.service.ts) (MQTT ingestion), [`backend/src/controllers/auth.controller.ts`](https://github.com/commerry/web-factorybox/blob/main/backend/src/controllers/auth.controller.ts) (Authentication), [`backend/src/config/database.ts`](https://github.com/commerry/web-factorybox/blob/main/backend/src/config/database.ts) (Prisma database), [`backend/src/routes/index.ts`](https://github.com/commerry/web-factorybox/blob/main/backend/src/routes/index.ts) (API route registry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_dashboard["Dashboard and history"]
  node_deviceui["Device views"]
  node_adminui["Admin and settings"]
  node_liveui["Live updates<br/>[useWebSocket.ts]"]
  node_frontendapi["API clients"]
end

subgraph group_api["Backend API"]
  node_app["Express application<br/>[app.ts]"]
  node_routes["API route registry<br/>[index.ts]"]
  node_authroutes["Authentication routes<br/>[auth.routes.ts]"]
  node_alertroutes["Alert routes<br/>[alert.routes.ts]"]
  node_notifyroutes["Notification routes"]
  node_alerts["Alert management"]
  node_notifications["Notifications"]
end

subgraph group_ingest["Device data and realtime"]
  node_mqtt["MQTT ingestion<br/>[mqtt.service.ts]"]
  node_alertengine["Alert evaluation<br/>[alert.service.ts]"]
  node_websocket["WebSocket service"]
end

subgraph group_platform["Identity and persistence"]
  node_auth["Authentication<br/>[auth.controller.ts]"]
  node_database[("Prisma database<br/>[database.ts]")]
  node_email["Email delivery<br/>[email.service.ts]"]
end

node_user(("Dashboard user"))
node_device(("ESP device"))
node_simulator["Device simulator<br/>[simulator.js]"]

node_user -.->|"views"| node_dashboard
node_user -.->|"manages devices"| node_deviceui
node_user -.->|"administers plans"| node_adminui
node_dashboard -.->|"requests data"| node_frontendapi
node_deviceui -.->|"requests device data"| node_frontendapi
node_adminui -.->|"requests administration"| node_frontendapi
node_websocket -.->|"pushes updates"| node_liveui
node_frontendapi -.->|"calls API"| node_app
node_device -.->|"publishes readings"| node_mqtt
node_simulator -.->|"simulates publishing"| node_mqtt
node_app -->|"mounts"| node_routes
node_routes -->|"registers"| node_authroutes
node_routes -->|"registers"| node_alertroutes
node_routes -->|"registers"| node_notifyroutes
node_authroutes -->|"dispatches"| node_auth
node_alertroutes -->|"dispatches"| node_alerts
node_alertroutes -->|"authenticates"| node_auth
node_notifyroutes -->|"dispatches"| node_notifications
node_notifyroutes -->|"authenticates"| node_auth
node_auth -->|"reads and writes"| node_database
node_auth -->|"sends verification"| node_email
node_mqtt -->|"stores readings"| node_database
node_mqtt -->|"checks alerts"| node_alertengine
node_mqtt -.->|"emits device events"| node_websocket
node_mqtt -.->|"emits alert notifications"| node_notifications
node_alertengine -->|"reads alert rules"| node_database
node_alerts -->|"reads and writes"| node_database
node_notifications -->|"reads and writes"| node_database

click node_dashboard "https://github.com/commerry/web-factorybox/tree/main/frontend/src/pages/dashboard"
click node_deviceui "https://github.com/commerry/web-factorybox/tree/main/frontend/src/pages/devices"
click node_adminui "https://github.com/commerry/web-factorybox/tree/main/frontend/src/pages/admin"
click node_liveui "https://github.com/commerry/web-factorybox/blob/main/frontend/src/composables/useWebSocket.ts"
click node_frontendapi "https://github.com/commerry/web-factorybox/tree/main/frontend/src/api"
click node_app "https://github.com/commerry/web-factorybox/blob/main/backend/src/app.ts"
click node_routes "https://github.com/commerry/web-factorybox/blob/main/backend/src/routes/index.ts"
click node_authroutes "https://github.com/commerry/web-factorybox/blob/main/backend/src/routes/auth.routes.ts"
click node_alertroutes "https://github.com/commerry/web-factorybox/blob/main/backend/src/routes/alert.routes.ts"
click node_notifyroutes "https://github.com/commerry/web-factorybox/blob/main/backend/src/routes/notification.routes.ts"
click node_auth "https://github.com/commerry/web-factorybox/blob/main/backend/src/controllers/auth.controller.ts"
click node_alerts "https://github.com/commerry/web-factorybox/blob/main/backend/src/controllers/alert.controller.ts"
click node_notifications "https://github.com/commerry/web-factorybox/blob/main/backend/src/controllers/notification.controller.ts"
click node_mqtt "https://github.com/commerry/web-factorybox/blob/main/backend/src/services/mqtt.service.ts"
click node_alertengine "https://github.com/commerry/web-factorybox/blob/main/backend/src/services/alert.service.ts"
click node_websocket "https://github.com/commerry/web-factorybox/blob/main/backend/src/services/websocket.service.ts"
click node_database "https://github.com/commerry/web-factorybox/blob/main/backend/src/config/database.ts"
click node_email "https://github.com/commerry/web-factorybox/blob/main/backend/src/services/email.service.ts"
click node_simulator "https://github.com/commerry/web-factorybox/blob/main/simulator/simulator.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_dashboard,node_deviceui,node_adminui,node_liveui,node_frontendapi,node_user toneBlue
class node_app,node_routes,node_authroutes,node_alertroutes,node_notifyroutes,node_alerts,node_notifications toneAmber
class node_mqtt,node_alertengine,node_websocket toneMint
class node_auth,node_database,node_email toneRose
class node_device toneIndigo
class node_simulator toneTeal
```

## Components

### Web application

- [Dashboard and history](https://github.com/commerry/web-factorybox/tree/main/frontend/src/pages/dashboard): `frontend/src/pages/dashboard`
- [Device views](https://github.com/commerry/web-factorybox/tree/main/frontend/src/pages/devices): `frontend/src/pages/devices`
- [Admin and settings](https://github.com/commerry/web-factorybox/tree/main/frontend/src/pages/admin): `frontend/src/pages/admin`
- [Live updates](https://github.com/commerry/web-factorybox/blob/main/frontend/src/composables/useWebSocket.ts): `frontend/src/composables/useWebSocket.ts`
- [API clients](https://github.com/commerry/web-factorybox/tree/main/frontend/src/api): `frontend/src/api`

### Backend API

- [Express application](https://github.com/commerry/web-factorybox/blob/main/backend/src/app.ts): `backend/src/app.ts`
- [API route registry](https://github.com/commerry/web-factorybox/blob/main/backend/src/routes/index.ts): `backend/src/routes/index.ts`
- [Authentication routes](https://github.com/commerry/web-factorybox/blob/main/backend/src/routes/auth.routes.ts): `backend/src/routes/auth.routes.ts`
- [Alert routes](https://github.com/commerry/web-factorybox/blob/main/backend/src/routes/alert.routes.ts): `backend/src/routes/alert.routes.ts`
- [Notification routes](https://github.com/commerry/web-factorybox/blob/main/backend/src/routes/notification.routes.ts): `backend/src/routes/notification.routes.ts`
- [Alert management](https://github.com/commerry/web-factorybox/blob/main/backend/src/controllers/alert.controller.ts): `backend/src/controllers/alert.controller.ts`
- [Notifications](https://github.com/commerry/web-factorybox/blob/main/backend/src/controllers/notification.controller.ts): `backend/src/controllers/notification.controller.ts`

### Device data and realtime

- [MQTT ingestion](https://github.com/commerry/web-factorybox/blob/main/backend/src/services/mqtt.service.ts): `backend/src/services/mqtt.service.ts`
- [Alert evaluation](https://github.com/commerry/web-factorybox/blob/main/backend/src/services/alert.service.ts): `backend/src/services/alert.service.ts`
- [WebSocket service](https://github.com/commerry/web-factorybox/blob/main/backend/src/services/websocket.service.ts): `backend/src/services/websocket.service.ts`

### Identity and persistence

- [Authentication](https://github.com/commerry/web-factorybox/blob/main/backend/src/controllers/auth.controller.ts): `backend/src/controllers/auth.controller.ts`
- [Prisma database](https://github.com/commerry/web-factorybox/blob/main/backend/src/config/database.ts): `backend/src/config/database.ts`
- [Email delivery](https://github.com/commerry/web-factorybox/blob/main/backend/src/services/email.service.ts): `backend/src/services/email.service.ts`

### Other components

- **Dashboard user**
- **ESP device**
- [Device simulator](https://github.com/commerry/web-factorybox/blob/main/simulator/simulator.js): `simulator/simulator.js`

## Connections

- Dashboard user → Dashboard and history: views
- Dashboard user → Device views: manages devices
- Dashboard user → Admin and settings: administers plans
- Dashboard and history → API clients: requests data
- Device views → API clients: requests device data
- Admin and settings → API clients: requests administration
- WebSocket service → Live updates: pushes updates
- API clients → Express application: calls API
- ESP device → MQTT ingestion: publishes readings
- Device simulator → MQTT ingestion: simulates publishing
- Express application → API route registry: mounts (evidence: `backend/src/app.ts`)
- API route registry → Authentication routes: registers (evidence: `backend/src/routes/index.ts`)
- API route registry → Alert routes: registers (evidence: `backend/src/routes/index.ts`)
- API route registry → Notification routes: registers (evidence: `backend/src/routes/index.ts`)
- Authentication routes → Authentication: dispatches (evidence: `backend/src/routes/auth.routes.ts`)
- Alert routes → Alert management: dispatches (evidence: `backend/src/routes/alert.routes.ts`)
- Alert routes → Authentication: authenticates (evidence: `backend/src/routes/alert.routes.ts`)
- Notification routes → Notifications: dispatches (evidence: `backend/src/routes/notification.routes.ts`)
- Notification routes → Authentication: authenticates (evidence: `backend/src/routes/notification.routes.ts`)
- Authentication → Prisma database: reads and writes (evidence: `backend/src/controllers/auth.controller.ts`)
- Authentication → Email delivery: sends verification (evidence: `backend/src/controllers/auth.controller.ts`)
- MQTT ingestion → Prisma database: stores readings (evidence: `backend/src/services/mqtt.service.ts`)
- MQTT ingestion → Alert evaluation: checks alerts (evidence: `backend/src/services/mqtt.service.ts`)
- MQTT ingestion → WebSocket service: emits device events
- MQTT ingestion → Notifications: emits alert notifications
- Alert evaluation → Prisma database: reads alert rules (evidence: `backend/src/services/alert.service.ts`)
- Alert management → Prisma database: reads and writes (evidence: `backend/src/controllers/alert.controller.ts`)
- Notifications → Prisma database: reads and writes (evidence: `backend/src/controllers/notification.controller.ts`)
