How atechpro/chha works
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”