# duc-tien/backendfablab architecture

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

- Interactive diagram: https://gitdiagram.com/duc-tien/backendfablab
- Repository: https://github.com/duc-tien/backendfablab

## Overview

IOT.CleanArchitecture is an industrial monitoring and management API. Users query or mutate machines, workers, projects, and production details through controllers; MediatR dispatches feature handlers, which read or write repositories backed by SQL Server, then return DTO results. A parallel telemetry path connects SCADA hosting to MQTT communication and buffering, while SignalR exposes notification delivery. The tree confirms these subsystems, but ScadaHost and several handlers were not sampled, so their internal telemetry and notification arrows are intentionally limited.

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_machine_api["Machine Controller"]
  node_detail_api["Detail Controller"]
  node_worker_api["Worker Controller"]
  node_project_api["Project Controller"]
  node_runtime["API Runtime<br/>[Program.cs]"]
end

subgraph group_application["Application Workflows"]
  node_mediator["MediatR Dispatcher"]
  node_machine_workflows["Machine Workflows<br/>[Machine]"]
  node_detail_workflows["Detail Workflows<br/>[Detail]"]
  node_worker_workflows["Worker Workflows<br/>[Worker]"]
  node_project_workflows["Project Workflows<br/>[Project]"]
end

subgraph group_telemetry["Telemetry Runtime"]
  node_scada_host["SCADA Host<br/>[ScadaHost.cs]"]
  node_telemetry_buffer["Telemetry Buffer<br/>[Buffer.cs]"]
  node_mqtt_client["Managed MQTT"]
end

subgraph group_persistence["Persistence"]
  node_unit_of_work["Unit Of Work<br/>[UnitOfWork.cs]"]
  node_repositories["Entity Repositories<br/>[Repository.cs]"]
  node_sql_server[("IOT SQL Database<br/>[IOTDbContext.cs]")]
end

subgraph group_realtime["Realtime Delivery"]
  node_notification_hub["Notification Hub<br/>[NotificationHub.cs]"]
end

node_user(("API User"))
node_devices(("Industrial Devices"))
node_signalr_clients(("Realtime Clients"))
node_mqtt_broker(("MQTT Broker"))

node_user -->|"calls HTTP"| node_machine_api
node_user -->|"calls HTTP"| node_detail_api
node_user -->|"calls HTTP"| node_worker_api
node_user -->|"calls HTTP"| node_project_api
node_machine_api -->|"dispatches"| node_mediator
node_detail_api -->|"dispatches"| node_mediator
node_worker_api -->|"dispatches"| node_mediator
node_project_api -->|"dispatches"| node_mediator
node_mediator -->|"routes requests"| node_machine_workflows
node_mediator -->|"routes requests"| node_detail_workflows
node_mediator -->|"routes requests"| node_worker_workflows
node_mediator -->|"routes requests"| node_project_workflows
node_machine_workflows -->|"reads/writes"| node_unit_of_work
node_detail_workflows -->|"reads/writes"| node_unit_of_work
node_worker_workflows -->|"reads/writes"| node_unit_of_work
node_project_workflows -->|"reads/writes"| node_unit_of_work
node_unit_of_work -->|"uses repositories"| node_repositories
node_repositories -->|"queries/persists"| node_sql_server
node_machine_workflows -->|"returns DTOs"| node_machine_api
node_detail_workflows -->|"returns DTOs"| node_detail_api
node_worker_workflows -->|"returns DTOs"| node_worker_api
node_project_workflows -->|"returns DTOs"| node_project_api
node_machine_api -->|"returns results"| node_user
node_detail_api -->|"returns results"| node_user
node_worker_api -->|"returns results"| node_user
node_project_api -->|"returns results"| node_user
node_runtime -->|"registers service"| node_mqtt_client
node_runtime -->|"hosts worker"| node_scada_host
node_runtime -->|"maps hub"| node_notification_hub
node_devices -->|"publishes telemetry"| node_mqtt_broker
node_mqtt_broker -->|"delivers messages"| node_mqtt_client
node_signalr_clients -.->|"opens connection"| node_notification_hub

click node_machine_api "https://github.com/duc-tien/backendfablab/blob/main/IOT.Api/Controllers/MachineController.cs"
click node_detail_api "https://github.com/duc-tien/backendfablab/blob/main/IOT.Api/Controllers/DetailController.cs"
click node_worker_api "https://github.com/duc-tien/backendfablab/blob/main/IOT.Api/Controllers/WorkerController.cs"
click node_project_api "https://github.com/duc-tien/backendfablab/blob/main/IOT.Api/Controllers/ProjectController.cs"
click node_mediator "https://github.com/duc-tien/backendfablab/blob/main/IOT.Application/ApplicationServiceRegistration.cs"
click node_machine_workflows "https://github.com/duc-tien/backendfablab/tree/main/IOT.Application/Features/Machine"
click node_detail_workflows "https://github.com/duc-tien/backendfablab/tree/main/IOT.Application/Features/Detail"
click node_worker_workflows "https://github.com/duc-tien/backendfablab/tree/main/IOT.Application/Features/Worker"
click node_project_workflows "https://github.com/duc-tien/backendfablab/tree/main/IOT.Application/Features/Project"
click node_scada_host "https://github.com/duc-tien/backendfablab/blob/main/IOT.Api/Worker/ScadaHost.cs"
click node_telemetry_buffer "https://github.com/duc-tien/backendfablab/blob/main/IOT.Api/Worker/Buffer.cs"
click node_mqtt_client "https://github.com/duc-tien/backendfablab/blob/main/IOT.Infastructure/Communication/ManagedMqttClient.cs"
click node_notification_hub "https://github.com/duc-tien/backendfablab/blob/main/IOT.Api/Hubs/NotificationHub.cs"
click node_unit_of_work "https://github.com/duc-tien/backendfablab/blob/main/IOT.Persistence/Repository/Generic/UnitOfWork.cs"
click node_repositories "https://github.com/duc-tien/backendfablab/blob/main/IOT.Persistence/Repository/Generic/Repository.cs"
click node_sql_server "https://github.com/duc-tien/backendfablab/blob/main/IOT.Persistence/DatabaseContext/IOTDbContext.cs"
click node_runtime "https://github.com/duc-tien/backendfablab/blob/main/IOT.Api/Program.cs"

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_machine_api,node_detail_api,node_worker_api,node_project_api,node_runtime,node_user,node_signalr_clients toneBlue
class node_mediator,node_machine_workflows,node_detail_workflows,node_worker_workflows,node_project_workflows toneAmber
class node_scada_host,node_telemetry_buffer,node_mqtt_client toneMint
class node_unit_of_work,node_repositories,node_sql_server toneRose
class node_notification_hub,node_devices,node_mqtt_broker toneIndigo
```

## Components

### HTTP API

- [Machine Controller](https://github.com/duc-tien/backendfablab/blob/main/IOT.Api/Controllers/MachineController.cs): `IOT.Api/Controllers/MachineController.cs`
- [Detail Controller](https://github.com/duc-tien/backendfablab/blob/main/IOT.Api/Controllers/DetailController.cs): `IOT.Api/Controllers/DetailController.cs`
- [Worker Controller](https://github.com/duc-tien/backendfablab/blob/main/IOT.Api/Controllers/WorkerController.cs): `IOT.Api/Controllers/WorkerController.cs`
- [Project Controller](https://github.com/duc-tien/backendfablab/blob/main/IOT.Api/Controllers/ProjectController.cs): `IOT.Api/Controllers/ProjectController.cs`
- [API Runtime](https://github.com/duc-tien/backendfablab/blob/main/IOT.Api/Program.cs): `IOT.Api/Program.cs`

### Application Workflows

- [MediatR Dispatcher](https://github.com/duc-tien/backendfablab/blob/main/IOT.Application/ApplicationServiceRegistration.cs): `IOT.Application/ApplicationServiceRegistration.cs`
- [Machine Workflows](https://github.com/duc-tien/backendfablab/tree/main/IOT.Application/Features/Machine): `IOT.Application/Features/Machine`
- [Detail Workflows](https://github.com/duc-tien/backendfablab/tree/main/IOT.Application/Features/Detail): `IOT.Application/Features/Detail`
- [Worker Workflows](https://github.com/duc-tien/backendfablab/tree/main/IOT.Application/Features/Worker): `IOT.Application/Features/Worker`
- [Project Workflows](https://github.com/duc-tien/backendfablab/tree/main/IOT.Application/Features/Project): `IOT.Application/Features/Project`

### Telemetry Runtime

- [SCADA Host](https://github.com/duc-tien/backendfablab/blob/main/IOT.Api/Worker/ScadaHost.cs): `IOT.Api/Worker/ScadaHost.cs`
- [Telemetry Buffer](https://github.com/duc-tien/backendfablab/blob/main/IOT.Api/Worker/Buffer.cs): `IOT.Api/Worker/Buffer.cs`
- [Managed MQTT](https://github.com/duc-tien/backendfablab/blob/main/IOT.Infastructure/Communication/ManagedMqttClient.cs): `IOT.Infastructure/Communication/ManagedMqttClient.cs`

### Persistence

- [Unit Of Work](https://github.com/duc-tien/backendfablab/blob/main/IOT.Persistence/Repository/Generic/UnitOfWork.cs): `IOT.Persistence/Repository/Generic/UnitOfWork.cs`
- [Entity Repositories](https://github.com/duc-tien/backendfablab/blob/main/IOT.Persistence/Repository/Generic/Repository.cs): `IOT.Persistence/Repository/Generic/Repository.cs`
- [IOT SQL Database](https://github.com/duc-tien/backendfablab/blob/main/IOT.Persistence/DatabaseContext/IOTDbContext.cs): `IOT.Persistence/DatabaseContext/IOTDbContext.cs`

### Realtime Delivery

- [Notification Hub](https://github.com/duc-tien/backendfablab/blob/main/IOT.Api/Hubs/NotificationHub.cs): `IOT.Api/Hubs/NotificationHub.cs`

### Other components

- **API User**
- **Industrial Devices**
- **Realtime Clients**
- **MQTT Broker**

## Connections

- API User → Machine Controller: calls HTTP
- API User → Detail Controller: calls HTTP
- API User → Worker Controller: calls HTTP
- API User → Project Controller: calls HTTP
- Machine Controller → MediatR Dispatcher: dispatches
- Detail Controller → MediatR Dispatcher: dispatches
- Worker Controller → MediatR Dispatcher: dispatches
- Project Controller → MediatR Dispatcher: dispatches
- MediatR Dispatcher → Machine Workflows: routes requests
- MediatR Dispatcher → Detail Workflows: routes requests
- MediatR Dispatcher → Worker Workflows: routes requests
- MediatR Dispatcher → Project Workflows: routes requests
- Machine Workflows → Unit Of Work: reads/writes
- Detail Workflows → Unit Of Work: reads/writes
- Worker Workflows → Unit Of Work: reads/writes
- Project Workflows → Unit Of Work: reads/writes
- Unit Of Work → Entity Repositories: uses repositories
- Entity Repositories → IOT SQL Database: queries/persists
- Machine Workflows → Machine Controller: returns DTOs
- Detail Workflows → Detail Controller: returns DTOs
- Worker Workflows → Worker Controller: returns DTOs
- Project Workflows → Project Controller: returns DTOs
- Machine Controller → API User: returns results
- Detail Controller → API User: returns results
- Worker Controller → API User: returns results
- Project Controller → API User: returns results
- API Runtime → Managed MQTT: registers service
- API Runtime → SCADA Host: hosts worker
- API Runtime → Notification Hub: maps hub
- Industrial Devices → MQTT Broker: publishes telemetry
- MQTT Broker → Managed MQTT: delivers messages
- Realtime Clients → Notification Hub: opens connection
