# atechpro/chha architecture

> Architecture diagram of the GitHub repository atechpro/chha, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/atechpro/chha
- Repository: https://github.com/atechpro/chha

## Overview

##### Project type and purpose
- This is a full-stack, monolithic IoT web application (“Centralized Hub Home Automation”) built with Flask on a Raspberry Pi server.
- It uses MQTT (Mosquitto) for real-time device communication, SQLAlchemy/SQLite for persistence, and client-side JS/HTML/CSS for the web UI.
- Purpose: centralize control of ESP-based microcontrollers (sensors/actuators), offering dashboarding, automation, scheduling, backup/restore, user/zone/feedback management.

##### File structure
- Top-level:
- app.py, view.py – Flask application entry points and route definitions
- database/database.py – ORM setup (SQLAlchemy) and DB file handling
- docker-compose.yml, Dockerfile – container definitions for Flask service (and likely Mosquitto)
- linuxpackage/coreinstall.sh – installation script for Raspberry Pi
- requirements.txt – Python dependencies
- Static assets under static/ (CSS/JS for modules: dashboard, automaterule, device manage, scheduler, etc.)
- Templates under templates/ – one subdirectory per module (automationrule, dashboard, devicemanage, feedback, loginmodule, navigation, timerscheduler, usermanage, zone) each with HTML + a tiny Flask “view” (e.g., dashboard.py) to render it.
- MQTT JS client library present in static/extlibjs/paho-mqtt.js.

##### README for additional insights
- Lists modules (Dashboard, Device Management, Timer & Scheduler, Backup & Restore, User Management, Zone Management, Feedback, Automation Rules).
- Stack: Flask, MQTT/Mosquitto, SQLAlchemy, HTML/CSS + JS, ESP clients.

##### Components
a. Main components:
- Web UI (Browser)
- Flask Application Server
- MQTT Broker (Mosquitto)
- Persistence Layer (SQLite via SQLAlchemy)
- ESP-based IoT Devices (ESP8266/ESP32)
- Deployment Host (Raspberry Pi / Docker)
b. Relationships & interactions:
- Browser ←→ Flask server over HTTP/HTTPS (REST endpoints, templated pages, WebSocket if any)
- Flask server ←→ SQLite DB via SQLAlchemy (CRUD operations)
- Flask server ←→ MQTT broker (publish control messages, subscribe sensor topics)
- ESP devices ←→ MQTT broker (publish sensor updates, subscribe control topics)
c. Architectural patterns:
- Monolithic MVC – Flask Blueprints serve as controllers, Jinja2 templates as views, SQLAlchemy models as data layer.
- Layered separation: Presentation (static + templates), Application logic (app.py, view.py, module scripts), Data (database/database.py, .db file).
d. Key technologies:
- Python/Flask – web framework
- Mosquitto – MQTT broker
- SQLAlchemy + SQLite – ORM & DB
- Paho-MQTT.JS – client-side MQTT over WebSockets (if used)
- Docker/Docker-Compose – containerization of services

##### Elements
- HTTP GET/POST between Browser → Flask
- Blue for server components
- Green for external clients (Browser, ESP)
- Orange for data stores
- Module grouping (optional):
- Static+templates under “Web UI”
- Flask modules under “Application Logic”

## Diagram (Mermaid)

```mermaid
flowchart TB
  subgraph "Web Tier"
    Browser["Web Browser"]:::client
    WebUI_static["Static Assets"]:::frontend
    WebUI_templates["Templates & Views"]:::frontend
    PahoJS["Paho MQTT JS Client"]:::extlib
    Browser -->|"HTTP"| FlaskApp
    WebUI_static --> FlaskApp
    WebUI_templates --> FlaskApp
    PahoJS --> FlaskApp
  end

  subgraph "Server Tier"
    FlaskApp["Flask Application"]:::server
    MQTTBroker["Mosquitto MQTT Broker"]:::server
    DB["SQLite DB"]:::database
    FlaskApp -->|CRUD| DB
    FlaskApp -->|"MQTT Pub/Sub"| MQTTBroker
  end

  subgraph "Modules"
    Dashboard["Dashboard Module"]:::module
    DeviceMgmt["Device Management Module"]:::module
    Scheduler["Timer & Scheduler Module"]:::module
    BackupRestore["Backup & Restore Module"]:::module
    UserMgmt["User Management Module"]:::module
    ZoneMgmt["Zone Management Module"]:::module
    Feedback["Feedback Module"]:::module
    Automation["Automation Rules Module"]:::module
    Login["Login & Registration Module"]:::module
    Navigation["Navigation Component"]:::module

    FlaskApp --> Dashboard
    FlaskApp --> DeviceMgmt
    FlaskApp --> Scheduler
    FlaskApp --> BackupRestore
    FlaskApp --> UserMgmt
    FlaskApp --> ZoneMgmt
    FlaskApp --> Feedback
    FlaskApp --> Automation
    FlaskApp --> Login
    FlaskApp --> Navigation
  end

  subgraph "Deployment & Tools"
    DockerfileFile["Dockerfile"]:::infra
    DockerCompose["docker-compose.yml"]:::infra
    CoreInstall["coreinstall.sh"]:::infra
    FlaskApp --> DockerfileFile
    FlaskApp --> DockerCompose
    CoreInstall --> DockerfileFile
  end

  MQTTBroker -->|"MQTT"| ESPDevices["ESP8266/ESP32 Devices"]:::client

  click WebUI_static "https://github.com/atechpro/chha/tree/core/static/"
  click WebUI_templates "https://github.com/atechpro/chha/tree/core/templates/"
  click FlaskApp "https://github.com/atechpro/chha/blob/core/app.py"
  click FlaskApp "https://github.com/atechpro/chha/blob/core/view.py"
  click DB "https://github.com/atechpro/chha/blob/core/database/database.py"
  click PahoJS "https://github.com/atechpro/chha/blob/core/static/extlibjs/paho-mqtt.js"
  click DockerfileFile "https://github.com/atechpro/chha/tree/core/Dockerfile"
  click DockerCompose "https://github.com/atechpro/chha/blob/core/docker-compose.yml"
  click CoreInstall "https://github.com/atechpro/chha/blob/core/linuxpackage/coreinstall.sh"

  click Dashboard "https://github.com/atechpro/chha/blob/core/static/dashboard/dashboard.css"
  click Dashboard "https://github.com/atechpro/chha/blob/core/static/dashboard/dashboard.js"
  click Dashboard "https://github.com/atechpro/chha/blob/core/templates/dashboard/dashboard.html"
  click Dashboard "https://github.com/atechpro/chha/blob/core/templates/dashboard/dashboard.py"

  click DeviceMgmt "https://github.com/atechpro/chha/blob/core/static/devicemanage/devicemanage.css"
  click DeviceMgmt "https://github.com/atechpro/chha/blob/core/static/devicemanage/devicemanage.js"
  click DeviceMgmt "https://github.com/atechpro/chha/blob/core/templates/devicemanage/devicemanage.html"
  click DeviceMgmt "https://github.com/atechpro/chha/blob/core/templates/devicemanage/devicemanage.py"

  click Scheduler "https://github.com/atechpro/chha/blob/core/static/timerschedule/scheduler.css"
  click Scheduler "https://github.com/atechpro/chha/blob/core/static/timerschedule/scheduler.js"
  click Scheduler "https://github.com/atechpro/chha/blob/core/static/timerschedule/timer.css"
  click Scheduler "https://github.com/atechpro/chha/blob/core/static/timerschedule/timer.js"
  click Scheduler "https://github.com/atechpro/chha/blob/core/templates/timerscheduler/scheduler.html"
  click Scheduler "https://github.com/atechpro/chha/blob/core/templates/timerscheduler/timer.html"
  click Scheduler "https://github.com/atechpro/chha/blob/core/templates/timerscheduler/timer.py"

  click BackupRestore "https://github.com/atechpro/chha/blob/core/static/backup.css"
  click BackupRestore "https://github.com/atechpro/chha/blob/core/templates/backuprestore/backuprestore.html"
  click BackupRestore "https://github.com/atechpro/chha/blob/core/templates/backuprestore/backuprestore.py"

  click UserMgmt "https://github.com/atechpro/chha/blob/core/static/usermanage.css"
  click UserMgmt "https://github.com/atechpro/chha/blob/core/static/usermanage.js"
  click UserMgmt "https://github.com/atechpro/chha/blob/core/templates/usermanage/usermanage.html"
  click UserMgmt "https://github.com/atechpro/chha/blob/core/templates/usermanage/edit_user.html"
  click UserMgmt "https://github.com/atechpro/chha/blob/core/templates/usermanage/usermanage.py"

  click ZoneMgmt "https://github.com/atechpro/chha/blob/core/static/zone/zone.css"
  click ZoneMgmt "https://github.com/atechpro/chha/blob/core/static/zone/zone.js"
  click ZoneMgmt "https://github.com/atechpro/chha/blob/core/templates/zone/zonemanage.html"
  click ZoneMgmt "https://github.com/atechpro/chha/blob/core/templates/zone/zone.py"

  click Feedback "https://github.com/atechpro/chha/blob/core/static/feedback/feedback.css"
  click Feedback "https://github.com/atechpro/chha/blob/core/static/feedback/feedback.js"
  click Feedback "https://github.com/atechpro/chha/blob/core/templates/feedback/feedback.html"
  click Feedback "https://github.com/atechpro/chha/blob/core/templates/feedback/feedback.py"

  click Automation "https://github.com/atechpro/chha/blob/core/static/automaterule/automation.css"
  click Automation "https://github.com/atechpro/chha/blob/core/static/automaterule/automation.js"
  click Automation "https://github.com/atechpro/chha/blob/core/templates/automationrule/automation.html"
  click Automation "https://github.com/atechpro/chha/blob/core/templates/automationrule/automation.py"

  click Login "https://github.com/atechpro/chha/blob/core/static/login.css"
  click Login "https://github.com/atechpro/chha/blob/core/static/register.css"
  click Login "https://github.com/atechpro/chha/blob/core/templates/loginmodule/login.html"
  click Login "https://github.com/atechpro/chha/blob/core/templates/loginmodule/register.html"

  click Navigation "https://github.com/atechpro/chha/blob/core/static/nav.css"
  click Navigation "https://github.com/atechpro/chha/blob/core/templates/navigation/nav.html"

  classDef client fill:#6f9,stroke:#333,stroke-width:1px
  classDef server fill:#89CFF0,stroke:#333,stroke-width:1px
  classDef database fill:#FFA500,stroke:#333,stroke-width:1px
  classDef frontend fill:#B0E0E6,stroke:#333,stroke-width:1px
  classDef module fill:#D3D3D3,stroke:#333,stroke-width:1px
  classDef infra fill:#F5DEB3,stroke:#333,stroke-width:1px
  classDef extlib fill:#E0FFFF,stroke:#333,stroke-width:1px
```
