# abhilashgeorge-gb/hvac-ai architecture

> Architecture diagram of the GitHub repository abhilashgeorge-gb/hvac-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abhilashgeorge-gb/hvac-ai
- Repository: https://github.com/abhilashgeorge-gb/hvac-ai

## Overview

##### Project Type & Purpose
- This is a smart, AI-powered HVAC control system that reads sensor data (temperature, humidity, CO₂, and occupancy) in real time, uses machine learning (including YOLOv8 for occupancy detection) to predict optimal temperature settings, and controls HVAC devices through IoT integration.
- It also offers a live dashboard (built with Flask) for monitoring and managing climate control.

##### Analyzing the File Structure
- Top-Level: The project root (HVAC-AI) contains a README and a src directory.
- ai_model.py: Contains the AI/ML components that likely handle training, prediction, and pattern analysis.
- hvac_control.py: Manages the interfacing with HVAC devices, probably via GPIO/IoT.
- sensors.py: Handles interfacing with various sensors (temperature, humidity, CO₂, occupancy).
- web_app.py: Implements the Flask-based live dashboard for real-time data visualization.
- main.py: Acts as an entry point that probably orchestrates the integration of these components.
- The __init__.py file indicates that the src directory is treated as a Python package.

##### Key Architectural Components
a. Sensor Subsystem:
- Responsible for collecting real-time data using libraries like Adafruit_DHT and pyserial.
- Module: sensors.py.
b. AI/Prediction Subsystem:
- Processes sensor data to predict the best temperature control strategy.
- Module: ai_model.py, which involves Scikit-Learn and possibly YOLOv8 for occupancy detection.
c. HVAC Control Subsystem:
- Implements control logic to actuate HVAC devices using GPIO-based relays and MQTT protocols.
- Module: hvac_control.py.
d. Web Dashboard & API:
- Provides a real-time interface for monitoring sensor data and HVAC control.
- Module: web_app.py built with Flask.
e. Orchestration:
- The main.py module likely ties all of these components together, managing the flow of data and control across different parts of the system.

##### Relationships & Interactions
- Sensors continuously capture environmental and occupancy data, forwarding it to the AI model.
- The AI model (ai_model.py) processes historical and current sensor data to make predictive decisions.
- The HVAC control module (hvac_control.py) receives predictions/commands from the AI module to adjust HVAC equipment.
- The Flask web_app (web_app.py) serves as the front-end dashboard, displaying data retrieved possibly from sensors and reflecting the control actions, while also offering endpoints to view historical data and sensor/API information.
- The main entry point (main.py) may coordinate the startup and continuous interactions among these modules.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Each module (sensors, AI, HVAC control, web dashboard) handles a distinct functionality.
- Modular Design: The system is broken down into self-contained components making future adaptations or extensions (like adding more sensors or advanced ML algorithms) easier.
- Real-Time Processing: Emphasis on live data flow between sensors, AI decision-making, and HVAC actuation.
- IoT Integration: Interaction with external hardware/components via MQTT and potentially GPIO control on Raspberry Pi.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Subsystems"
        orch["Orchestration/Entry Point"]:::orchestration
        subgraph "Sensor Subsystem"
            sensors["Sensor Module"]:::sensor
        end
        subgraph "AI/Prediction Subsystem"
            ai["AI/Prediction Module"]:::ai
        end
        subgraph "HVAC Control Subsystem"
            hvac["HVAC Control Module"]:::hvac
        end
        subgraph "Web Dashboard & API"
            web["Web Dashboard"]:::web
        end
    end

    sensors -->|"SensorData"| ai
    ai -->|"PredictedCommand"| hvac
    sensors -->|"LiveUpdates"| web
    ai -->|"AnalysisData"| web
    hvac -->|"ControlSignal"| web

    orch -->|"Orchestrates"| sensors
    orch -->|"Orchestrates"| ai
    orch -->|"Orchestrates"| hvac
    orch -->|"Orchestrates"| web

    click sensors "https://github.com/abhilashgeorge-gb/hvac-ai/blob/main/src/sensors.py"
    click ai "https://github.com/abhilashgeorge-gb/hvac-ai/blob/main/src/ai_model.py"
    click hvac "https://github.com/abhilashgeorge-gb/hvac-ai/blob/main/src/hvac_control.py"
    click web "https://github.com/abhilashgeorge-gb/hvac-ai/blob/main/src/web_app.py"
    click orch "https://github.com/abhilashgeorge-gb/hvac-ai/blob/main/src/main.py"

    classDef sensor fill:#f39c12,stroke:#333,stroke-width:2px;
    classDef ai fill:#27ae60,stroke:#333,stroke-width:2px;
    classDef hvac fill:#2980b9,stroke:#333,stroke-width:2px;
    classDef web fill:#8e44ad,stroke:#333,stroke-width:2px;
    classDef orchestration fill:#c0392b,stroke:#333,stroke-width:2px;
```
