# danilo20gonzalez/iot-lab-system architecture

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

- Interactive diagram: https://gitdiagram.com/danilo20gonzalez/iot-lab-system
- Repository: https://github.com/danilo20gonzalez/iot-lab-system

## Overview

LabControl Pro is a web application for managing laboratories, projects, work areas, users, sensors, and connected devices. Users sign in and navigate protected management and monitoring screens; the frontend calls an API and can receive Home Assistant state updates over WebSocket. The backend provides authentication and domain controllers backed by MySQL, with separate Home Assistant services. Several backend route/controller and integration files were not sampled, so those connections are shown only where the index or excerpts support them.

Main entry points: [`frontend/src/App.tsx`](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/App.tsx) (App routing), [`backend/src/index.ts`](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/index.ts) (Express API), [`frontend/src/api/api.ts`](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/api/api.ts) (HTTP client), [`frontend/src/pages/Sensors.tsx`](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/pages/Sensors.tsx) (Sensors)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_app["App routing<br/>[App.tsx]"]
  node_session["Session context<br/>[AppContext.tsx]"]
  node_login["Login<br/>[Login.tsx]"]
  node_dashboard["Dashboard<br/>[Dashboard.tsx]"]
  node_labmgmt["Lab management"]
  node_labview["Laboratory view<br/>[Laboratory.tsx]"]
  node_projects["Projects<br/>[Projects.tsx]"]
  node_sensors["Sensors<br/>[Sensors.tsx]"]
  node_deviceui["Device controls"]
  node_navbar["Navigation<br/>[Navbar.tsx]"]
  node_api["HTTP client<br/>[api.ts]"]
  node_ha_hook["HA state hook"]
end

subgraph group_backend["Backend API"]
  node_backend["Express API<br/>[index.ts]"]
  node_auth["Authentication<br/>[authService.ts]"]
  node_authmw["Token verification<br/>[authenticate.ts]"]
  node_labctrl["Laboratory domain"]
  node_projectctrl["Project domain"]
  node_devicectrl["Device domain"]
  node_ha_controller["HA endpoints"]
end

subgraph group_data["Persistence"]
  node_db[("MySQL pool<br/>[db.ts]")]
end

subgraph group_automation["Device integration"]
  node_ha_service["Home Assistant service"]
  node_ha_ws["HA WebSocket service"]
end

node_user(("User"))
node_ha["Home Assistant"]

node_user -->|"uses"| node_app
node_app -->|"provides context"| node_session
node_app -->|"routes to"| node_login
node_app -->|"routes to"| node_dashboard
node_app -->|"routes to"| node_labmgmt
node_app -->|"routes to"| node_labview
node_app -->|"routes to"| node_projects
node_app -->|"routes to"| node_sensors
node_dashboard -->|"renders"| node_navbar
node_labmgmt -->|"renders"| node_navbar
node_labview -->|"renders"| node_navbar
node_sensors -->|"renders"| node_navbar
node_sensors -->|"renders controls"| node_deviceui
node_dashboard -->|"requests data"| node_api
node_labmgmt -->|"requests data"| node_api
node_labview -->|"requests data"| node_api
node_projects -->|"requests data"| node_api
node_sensors -->|"requests HA data"| node_api
node_labview -->|"uses state hook"| node_ha_hook
node_projects -->|"uses state hook"| node_ha_hook
node_sensors -->|"uses state hook"| node_ha_hook
node_api -.->|"HTTP requests"| node_backend
node_backend -.->|"dispatches auth"| node_auth
node_backend -.->|"dispatches labs"| node_labctrl
node_backend -.->|"dispatches projects"| node_projectctrl
node_backend -.->|"dispatches devices"| node_devicectrl
node_auth -->|"queries users"| node_db
node_labctrl -->|"queries labs"| node_db
node_projectctrl -->|"queries projects"| node_db
node_devicectrl -->|"queries devices"| node_db
node_backend -.->|"applies middleware"| node_authmw
node_backend -.->|"dispatches HA"| node_ha_controller
node_ha_controller -.->|"delegates to"| node_ha_service
node_ha_controller -.->|"uses WebSocket"| node_ha_ws
node_ha_service -.->|"controls devices"| node_ha
node_ha_ws -.->|"exchanges state"| node_ha
node_ha_hook -.->|"receives live state"| node_ha

click node_app "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/App.tsx"
click node_session "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/context/AppContext.tsx"
click node_login "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/pages/Login.tsx"
click node_dashboard "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/pages/Dashboard.tsx"
click node_labmgmt "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/pages/LaboratoriesManagement.tsx"
click node_labview "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/pages/Laboratory.tsx"
click node_projects "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/pages/Projects.tsx"
click node_sensors "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/pages/Sensors.tsx"
click node_deviceui "https://github.com/danilo20gonzalez/iot-lab-system/tree/master/frontend/src/components/deviceControl"
click node_navbar "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/components/Navbar.tsx"
click node_api "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/api/api.ts"
click node_ha_hook "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/hooks/useHomeAssistant.ts"
click node_backend "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/index.ts"
click node_auth "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/services/authService.ts"
click node_authmw "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/middlewares/authenticate.ts"
click node_labctrl "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/controllers/laboratorioController.ts"
click node_projectctrl "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/controllers/proyectosController.ts"
click node_devicectrl "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/controllers/deviceController.ts"
click node_db "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/config/db.ts"
click node_ha_controller "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/controllers/homeAssistantController.ts"
click node_ha_service "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/services/homeAssistantService.ts"
click node_ha_ws "https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/services/haWebSocketService.ts"

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_app,node_session,node_login,node_dashboard,node_labmgmt,node_labview,node_projects,node_sensors,node_deviceui,node_navbar,node_api,node_ha_hook,node_user toneBlue
class node_backend,node_auth,node_authmw,node_labctrl,node_projectctrl,node_devicectrl,node_ha_controller toneAmber
class node_db toneMint
class node_ha_service,node_ha_ws toneRose
class node_ha toneIndigo
```

## Components

### Web application

- [App routing](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Session context](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/context/AppContext.tsx): `frontend/src/context/AppContext.tsx`
- [Login](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/pages/Login.tsx): `frontend/src/pages/Login.tsx`
- [Dashboard](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/pages/Dashboard.tsx): `frontend/src/pages/Dashboard.tsx`
- [Lab management](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/pages/LaboratoriesManagement.tsx): `frontend/src/pages/LaboratoriesManagement.tsx`
- [Laboratory view](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/pages/Laboratory.tsx): `frontend/src/pages/Laboratory.tsx`
- [Projects](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/pages/Projects.tsx): `frontend/src/pages/Projects.tsx`
- [Sensors](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/pages/Sensors.tsx): `frontend/src/pages/Sensors.tsx`
- [Device controls](https://github.com/danilo20gonzalez/iot-lab-system/tree/master/frontend/src/components/deviceControl): `frontend/src/components/deviceControl`
- [Navigation](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/components/Navbar.tsx): `frontend/src/components/Navbar.tsx`
- [HTTP client](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/api/api.ts): `frontend/src/api/api.ts`
- [HA state hook](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/frontend/src/hooks/useHomeAssistant.ts): `frontend/src/hooks/useHomeAssistant.ts`

### Backend API

- [Express API](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/index.ts): `backend/src/index.ts`
- [Authentication](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/services/authService.ts): `backend/src/services/authService.ts`
- [Token verification](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/middlewares/authenticate.ts): `backend/src/middlewares/authenticate.ts`
- [Laboratory domain](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/controllers/laboratorioController.ts): `backend/src/controllers/laboratorioController.ts`
- [Project domain](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/controllers/proyectosController.ts): `backend/src/controllers/proyectosController.ts`
- [Device domain](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/controllers/deviceController.ts): `backend/src/controllers/deviceController.ts`
- [HA endpoints](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/controllers/homeAssistantController.ts): `backend/src/controllers/homeAssistantController.ts`

### Persistence

- [MySQL pool](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/config/db.ts): `backend/src/config/db.ts`

### Device integration

- [Home Assistant service](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/services/homeAssistantService.ts): `backend/src/services/homeAssistantService.ts`
- [HA WebSocket service](https://github.com/danilo20gonzalez/iot-lab-system/blob/master/backend/src/services/haWebSocketService.ts): `backend/src/services/haWebSocketService.ts`

### Other components

- **User**
- **Home Assistant**

## Connections

- User → App routing: uses (evidence: `frontend/src/App.tsx`)
- App routing → Session context: provides context (evidence: `frontend/src/App.tsx`)
- App routing → Login: routes to (evidence: `frontend/src/App.tsx`)
- App routing → Dashboard: routes to (evidence: `frontend/src/App.tsx`)
- App routing → Lab management: routes to (evidence: `frontend/src/App.tsx`)
- App routing → Laboratory view: routes to (evidence: `frontend/src/App.tsx`)
- App routing → Projects: routes to (evidence: `frontend/src/App.tsx`)
- App routing → Sensors: routes to (evidence: `frontend/src/App.tsx`)
- Dashboard → Navigation: renders (evidence: `frontend/src/pages/Dashboard.tsx`)
- Lab management → Navigation: renders (evidence: `frontend/src/pages/LaboratoriesManagement.tsx`)
- Laboratory view → Navigation: renders (evidence: `frontend/src/pages/Laboratory.tsx`)
- Sensors → Navigation: renders (evidence: `frontend/src/pages/Sensors.tsx`)
- Sensors → Device controls: renders controls (evidence: `frontend/src/pages/Sensors.tsx`)
- Dashboard → HTTP client: requests data (evidence: `frontend/src/pages/Dashboard.tsx`)
- Lab management → HTTP client: requests data (evidence: `frontend/src/pages/LaboratoriesManagement.tsx`)
- Laboratory view → HTTP client: requests data (evidence: `frontend/src/pages/Laboratory.tsx`)
- Projects → HTTP client: requests data (evidence: `frontend/src/pages/Projects.tsx`)
- Sensors → HTTP client: requests HA data (evidence: `frontend/src/pages/Sensors.tsx`)
- Laboratory view → HA state hook: uses state hook (evidence: `frontend/src/pages/Laboratory.tsx`)
- Projects → HA state hook: uses state hook (evidence: `frontend/src/pages/Projects.tsx`)
- Sensors → HA state hook: uses state hook (evidence: `frontend/src/pages/Sensors.tsx`)
- HTTP client → Express API: HTTP requests
- Express API → Authentication: dispatches auth
- Express API → Laboratory domain: dispatches labs
- Express API → Project domain: dispatches projects
- Express API → Device domain: dispatches devices
- Authentication → MySQL pool: queries users (evidence: `backend/src/services/authService.ts`)
- Laboratory domain → MySQL pool: queries labs (evidence: `backend/src/controllers/laboratorioController.ts`)
- Project domain → MySQL pool: queries projects (evidence: `backend/src/controllers/proyectosController.ts`)
- Device domain → MySQL pool: queries devices (evidence: `backend/src/controllers/deviceController.ts`)
- Express API → Token verification: applies middleware
- Express API → HA endpoints: dispatches HA
- HA endpoints → Home Assistant service: delegates to
- HA endpoints → HA WebSocket service: uses WebSocket
- Home Assistant service → Home Assistant: controls devices
- HA WebSocket service → Home Assistant: exchanges state
- HA state hook → Home Assistant: receives live state
