# fabriziobc2005/smart-classroom architecture

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

- Interactive diagram: https://gitdiagram.com/fabriziobc2005/smart-classroom
- Repository: https://github.com/fabriziobc2005/smart-classroom

## Overview

Smart Classroom monitors classroom air and occupancy, computes health and risk, automates ventilation and lighting, and surfaces live status and human follow-up in a dashboard. The main flow is sensor or simulator telemetry over MQTT into the worker, which applies rules, stores readings and actions, and publishes live updates for the API and dashboard. Separate branches provide forecasts, compliance and ventilation reports, pending tasks, and a read-only AI assistant. The worker excerpts and README support the ingestion and live-update flow; unsampled frontend and service internals limit further call-level links.

Main entry points: [`backend/app/main.py`](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/main.py) (REST and WebSocket API), [`backend/worker/main.py`](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/worker/main.py) (Ingestion worker), [`web/src/app/page.tsx`](https://github.com/fabriziobc2005/smart-classroom/blob/main/web/src/app/page.tsx) (Web dashboard), [`backend/app/db.py`](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/db.py) (PostgreSQL)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Telemetry ingestion"]
  node_simulator["Telemetry simulator<br/>[main.py]"]
  node_mqtt["MQTT broker"]
  node_worker["Ingestion worker<br/>[main.py]"]
  node_db[("PostgreSQL<br/>[db.py]")]
  node_redis[("Redis cache and pub/sub")]
end

subgraph group_analysis["Analysis and control"]
  node_rules["Automation rules<br/>[reglas.py]"]
  node_comfort["Comfort index<br/>[indice.py]"]
  node_occupancy["Occupancy estimate<br/>[aforo.py]"]
  node_prediction["CO₂ prediction<br/>[prediccion.py]"]
end

subgraph group_api["API and reporting"]
  node_api_main["REST and WebSocket API<br/>[main.py]"]
  node_models["Classroom data models<br/>[models.py]"]
  node_classroom_routes["Classroom status and history<br/>[aulas.py]"]
  node_control_routes["Manual control<br/>[control.py]"]
  node_event_routes["Events<br/>[eventos.py]"]
  node_report_routes["Compliance and ACH reports<br/>[reportes.py]"]
  node_pending_service["Human follow-up tasks<br/>[pendientes.py]"]
  node_assistant_service["Read-only AI assistant<br/>[asistente.py]"]
  node_forecast_routes["Forecast review<br/>[pronostico.py]"]
  node_realtime["Redis WebSocket bridge<br/>[realtime.py]"]
end

subgraph group_dashboard["Dashboard"]
  node_dashboard["Web dashboard<br/>[page.tsx]"]
  node_detail_view["Classroom detail<br/>[page.tsx]"]
  node_pending_view["Pending tasks view<br/>[page.tsx]"]
  node_report_view["Compliance report view<br/>[page.tsx]"]
  node_assistant_ui["Assistant bubble<br/>[Asistente.tsx]"]
  node_web_types["Dashboard data types<br/>[tipos.ts]"]
end

subgraph group_learning["Forecast learning"]
  node_training_data["Historical training examples<br/>[ejemplos.py]"]
  node_features["Forecast features<br/>[que_mira.py]"]
  node_forecaster["Forecast model<br/>[pronosticador.py]"]
end

node_sensors(("Classroom sensors"))
node_actuators(("Ventilation and lights"))
node_actuator_user(("Classroom staff"))

node_sensors -->|"send telemetry"| node_mqtt
node_simulator -->|"publish telemetry"| node_mqtt
node_mqtt -->|"deliver telemetry"| node_worker
node_worker -->|"evaluate readings"| node_rules
node_rules -->|"calculate index"| node_comfort
node_rules -.->|"estimate occupancy"| node_occupancy
node_rules -->|"project CO₂"| node_prediction
node_worker -->|"persist readings"| node_db
node_worker -->|"save events and actions"| node_db
node_worker -->|"publish live state"| node_redis
node_worker -->|"send commands"| node_mqtt
node_mqtt -->|"deliver commands"| node_actuators
node_api_main -->|"register routes"| node_classroom_routes
node_api_main -->|"register routes"| node_control_routes
node_api_main -->|"register routes"| node_event_routes
node_api_main -->|"register routes"| node_report_routes
node_api_main -->|"register routes"| node_forecast_routes
node_api_main -->|"start Redis listener"| node_realtime
node_realtime -->|"receive updates"| node_redis
node_api_main -->|"serve API and live updates"| node_dashboard
node_classroom_routes -->|"read classroom history"| node_db
node_classroom_routes -->|"read cached state"| node_redis
node_report_routes -->|"query report data"| node_db
node_pending_service -->|"inspect incidents"| node_db
node_pending_service -->|"read live state"| node_redis
node_assistant_service -.->|"answer questions"| node_actuator_user
node_dashboard -.->|"open classroom"| node_detail_view
node_dashboard -.->|"open tasks"| node_pending_view
node_dashboard -.->|"open reports"| node_report_view
node_dashboard -->|"offer assistant"| node_assistant_ui
node_detail_view -->|"offer manual controls"| node_actuator_user
node_actuator_user -->|"request manual action"| node_control_routes
node_assistant_ui -->|"ask questions"| node_assistant_service
node_training_data -->|"read historical samples"| node_db
node_training_data -->|"build feature rows"| node_features
node_features -->|"provide forecast inputs"| node_forecaster
node_worker -->|"forecast live CO₂"| node_forecaster
node_dashboard -.->|"use typed API data"| node_web_types

click node_simulator "https://github.com/fabriziobc2005/smart-classroom/blob/main/simulator/main.py"
click node_worker "https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/worker/main.py"
click node_db "https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/db.py"
click node_rules "https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/services/reglas.py"
click node_comfort "https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/services/indice.py"
click node_occupancy "https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/services/aforo.py"
click node_prediction "https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/services/prediccion.py"
click node_api_main "https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/main.py"
click node_models "https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/models.py"
click node_classroom_routes "https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/routers/aulas.py"
click node_control_routes "https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/routers/control.py"
click node_event_routes "https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/routers/eventos.py"
click node_report_routes "https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/routers/reportes.py"
click node_pending_service "https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/services/pendientes.py"
click node_assistant_service "https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/services/asistente.py"
click node_forecast_routes "https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/routers/pronostico.py"
click node_realtime "https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/realtime.py"
click node_dashboard "https://github.com/fabriziobc2005/smart-classroom/blob/main/web/src/app/page.tsx"
click node_detail_view "https://github.com/fabriziobc2005/smart-classroom/blob/main/web/src/app/aula/%5Bid%5D/page.tsx"
click node_pending_view "https://github.com/fabriziobc2005/smart-classroom/blob/main/web/src/app/pendientes/page.tsx"
click node_report_view "https://github.com/fabriziobc2005/smart-classroom/blob/main/web/src/app/reporte/page.tsx"
click node_assistant_ui "https://github.com/fabriziobc2005/smart-classroom/blob/main/web/src/components/Asistente.tsx"
click node_web_types "https://github.com/fabriziobc2005/smart-classroom/blob/main/web/src/lib/tipos.ts"
click node_training_data "https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/aprendizaje/ejemplos.py"
click node_features "https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/aprendizaje/que_mira.py"
click node_forecaster "https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/aprendizaje/pronosticador.py"

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_simulator,node_mqtt,node_worker,node_db,node_redis toneBlue
class node_rules,node_comfort,node_occupancy,node_prediction toneAmber
class node_api_main,node_models,node_classroom_routes,node_control_routes,node_event_routes,node_report_routes,node_pending_service,node_assistant_service,node_forecast_routes,node_realtime toneMint
class node_dashboard,node_detail_view,node_pending_view,node_report_view,node_assistant_ui,node_web_types toneRose
class node_training_data,node_features,node_forecaster,node_sensors,node_actuators,node_actuator_user toneIndigo
```

## Components

### Telemetry ingestion

- [Telemetry simulator](https://github.com/fabriziobc2005/smart-classroom/blob/main/simulator/main.py): `simulator/main.py`
- **MQTT broker**
- [Ingestion worker](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/worker/main.py): `backend/worker/main.py`
- [PostgreSQL](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/db.py): `backend/app/db.py`
- **Redis cache and pub/sub**

### Analysis and control

- [Automation rules](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/services/reglas.py): `backend/app/services/reglas.py`
- [Comfort index](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/services/indice.py): `backend/app/services/indice.py`
- [Occupancy estimate](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/services/aforo.py): `backend/app/services/aforo.py`
- [CO₂ prediction](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/services/prediccion.py): `backend/app/services/prediccion.py`

### API and reporting

- [REST and WebSocket API](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/main.py): `backend/app/main.py`
- [Classroom data models](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/models.py): `backend/app/models.py`
- [Classroom status and history](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/routers/aulas.py): `backend/app/routers/aulas.py`
- [Manual control](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/routers/control.py): `backend/app/routers/control.py`
- [Events](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/routers/eventos.py): `backend/app/routers/eventos.py`
- [Compliance and ACH reports](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/routers/reportes.py): `backend/app/routers/reportes.py`
- [Human follow-up tasks](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/services/pendientes.py): `backend/app/services/pendientes.py`
- [Read-only AI assistant](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/services/asistente.py): `backend/app/services/asistente.py`
- [Forecast review](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/routers/pronostico.py): `backend/app/routers/pronostico.py`
- [Redis WebSocket bridge](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/app/realtime.py): `backend/app/realtime.py`

### Dashboard

- [Web dashboard](https://github.com/fabriziobc2005/smart-classroom/blob/main/web/src/app/page.tsx): `web/src/app/page.tsx`
- [Classroom detail](https://github.com/fabriziobc2005/smart-classroom/blob/main/web/src/app/aula/%5Bid%5D/page.tsx): `web/src/app/aula/[id]/page.tsx`
- [Pending tasks view](https://github.com/fabriziobc2005/smart-classroom/blob/main/web/src/app/pendientes/page.tsx): `web/src/app/pendientes/page.tsx`
- [Compliance report view](https://github.com/fabriziobc2005/smart-classroom/blob/main/web/src/app/reporte/page.tsx): `web/src/app/reporte/page.tsx`
- [Assistant bubble](https://github.com/fabriziobc2005/smart-classroom/blob/main/web/src/components/Asistente.tsx): `web/src/components/Asistente.tsx`
- [Dashboard data types](https://github.com/fabriziobc2005/smart-classroom/blob/main/web/src/lib/tipos.ts): `web/src/lib/tipos.ts`

### Forecast learning

- [Historical training examples](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/aprendizaje/ejemplos.py): `backend/aprendizaje/ejemplos.py`
- [Forecast features](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/aprendizaje/que_mira.py): `backend/aprendizaje/que_mira.py`
- [Forecast model](https://github.com/fabriziobc2005/smart-classroom/blob/main/backend/aprendizaje/pronosticador.py): `backend/aprendizaje/pronosticador.py`

### Other components

- **Classroom sensors**
- **Ventilation and lights**
- **Classroom staff**

## Connections

- Classroom sensors → MQTT broker: send telemetry (evidence: `README.md`)
- Telemetry simulator → MQTT broker: publish telemetry (evidence: `README.md`)
- MQTT broker → Ingestion worker: deliver telemetry (evidence: `README.md`)
- Ingestion worker → Automation rules: evaluate readings (evidence: `backend/worker/main.py`)
- Automation rules → Comfort index: calculate index (evidence: `backend/app/services/reglas.py`)
- Automation rules → Occupancy estimate: estimate occupancy (evidence: `backend/app/services/reglas.py`)
- Automation rules → CO₂ prediction: project CO₂ (evidence: `backend/app/services/reglas.py`)
- Ingestion worker → PostgreSQL: persist readings (evidence: `backend/worker/main.py`)
- Ingestion worker → PostgreSQL: save events and actions (evidence: `backend/worker/main.py`)
- Ingestion worker → Redis cache and pub/sub: publish live state (evidence: `backend/worker/main.py`)
- Ingestion worker → MQTT broker: send commands (evidence: `README.md`)
- MQTT broker → Ventilation and lights: deliver commands (evidence: `README.md`)
- REST and WebSocket API → Classroom status and history: register routes (evidence: `backend/app/main.py`)
- REST and WebSocket API → Manual control: register routes (evidence: `backend/app/main.py`)
- REST and WebSocket API → Events: register routes (evidence: `backend/app/main.py`)
- REST and WebSocket API → Compliance and ACH reports: register routes (evidence: `backend/app/main.py`)
- REST and WebSocket API → Forecast review: register routes (evidence: `backend/app/main.py`)
- REST and WebSocket API → Redis WebSocket bridge: start Redis listener (evidence: `backend/app/main.py`)
- Redis WebSocket bridge → Redis cache and pub/sub: receive updates (evidence: `backend/app/realtime.py`)
- REST and WebSocket API → Web dashboard: serve API and live updates (evidence: `README.md`)
- Classroom status and history → PostgreSQL: read classroom history (evidence: `backend/app/routers/aulas.py`)
- Classroom status and history → Redis cache and pub/sub: read cached state (evidence: `backend/app/routers/aulas.py`)
- Compliance and ACH reports → PostgreSQL: query report data (evidence: `backend/app/routers/reportes.py`)
- Human follow-up tasks → PostgreSQL: inspect incidents (evidence: `backend/app/services/pendientes.py`)
- Human follow-up tasks → Redis cache and pub/sub: read live state (evidence: `backend/app/services/pendientes.py`)
- Read-only AI assistant → Classroom staff: answer questions (evidence: `README.md`)
- Web dashboard → Classroom detail: open classroom
- Web dashboard → Pending tasks view: open tasks
- Web dashboard → Compliance report view: open reports
- Web dashboard → Assistant bubble: offer assistant (evidence: `README.md`)
- Classroom detail → Classroom staff: offer manual controls (evidence: `README.md`)
- Classroom staff → Manual control: request manual action (evidence: `README.md`)
- Assistant bubble → Read-only AI assistant: ask questions (evidence: `README.md`)
- Historical training examples → PostgreSQL: read historical samples (evidence: `backend/aprendizaje/ejemplos.py`)
- Historical training examples → Forecast features: build feature rows (evidence: `backend/aprendizaje/ejemplos.py`)
- Forecast features → Forecast model: provide forecast inputs (evidence: `backend/aprendizaje/pronosticador.py`)
- Ingestion worker → Forecast model: forecast live CO₂ (evidence: `backend/worker/main.py`)
- Web dashboard → Dashboard data types: use typed API data
