# rusk0d/home-ping architecture

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

- Interactive diagram: https://gitdiagram.com/rusk0d/home-ping
- Repository: https://github.com/rusk0d/home-ping

## Overview

Home Ping is a home-environment monitoring system: ESP32 sensors publish readings and occupancy over MQTT; the backend ingests, stores and evaluates them, then serves REST data to Android and MQTT data to the read-only web dashboard. Android also manages notification preferences and location-based occupancy arming, while backend alerts reach phones through Firebase. Firmware sketch sources, contracts and some UI/runtime modules are not present in the supplied tree or excerpts, so their internal links are omitted or documented at the system boundary.

Main entry points: [`backend/alerts.py`](https://github.com/rusk0d/home-ping/blob/main/backend/alerts.py) (Alerting and settings), [`backend/store.py`](https://github.com/rusk0d/home-ping/blob/main/backend/store.py) (SQLite store), [`backend/ingest.py`](https://github.com/rusk0d/home-ping/blob/main/backend/ingest.py) (MQTT ingestion), [`backend/server.py`](https://github.com/rusk0d/home-ping/blob/main/backend/server.py) (Backend runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sensors["Sensing and transport"]
  node_esp_nodes(("ESP32 sensor nodes"))
  node_mqtt["MQTT broker"]
  node_homeping_lib["Shared node library<br/>[HomePing.h]"]
end

subgraph group_backend["Backend services"]
  node_backend_entry["Backend runtime<br/>[server.py]"]
  node_mqtt_ingest["MQTT ingestion<br/>[ingest.py]"]
  node_air_analysis["Air analysis<br/>[air.py]"]
  node_node_monitor["Node monitoring<br/>[nodes.py]"]
  node_api["REST API<br/>[api.py]"]
  node_sqlite[("SQLite store<br/>[store.py]")]
  node_runtime_state["Runtime state<br/>[state.py]"]
  node_alerts["Alerting and settings<br/>[alerts.py]"]
  node_server_checks["Server watchdog<br/>[server_checks.py]"]
  node_backup["Database backups<br/>[backup_db.py]"]
end

subgraph group_android["Android client"]
  node_android_home["Home dashboard<br/>[HomeFragment.kt]"]
  node_history["History view<br/>[HistoryActivity.kt]"]
  node_api_client["REST client<br/>[Api.kt]"]
  node_location_arm["Location arming<br/>[HomeGeofence.kt]"]
  node_arm_worker["Retry worker<br/>[ArmWorker.kt]"]
  node_notification_settings["Notification settings"]
  node_push_service["Push handling"]
  node_widget["Home-screen widget<br/>[HomeEnvWidget.kt]"]
end

subgraph group_web["Web dashboard"]
  node_web_dashboard["Web dashboard<br/>[app.js]"]
end

node_firebase["Firebase messaging"]
node_android_user(("Phone user"))
node_web_user(("Web user"))

node_esp_nodes -.->|"publishes readings"| node_mqtt
node_homeping_lib -.->|"supports node networking"| node_esp_nodes
node_mqtt -.->|"delivers messages"| node_mqtt_ingest
node_backend_entry -->|"initializes and loads"| node_sqlite
node_backend_entry -->|"registers callbacks"| node_mqtt_ingest
node_backend_entry -->|"starts monitor"| node_node_monitor
node_backend_entry -->|"starts analysis"| node_air_analysis
node_backend_entry -->|"serves routes"| node_api
node_mqtt_ingest -->|"stores readings"| node_sqlite
node_mqtt_ingest -->|"triggers alerts"| node_alerts
node_mqtt_ingest -->|"updates state"| node_runtime_state
node_air_analysis -->|"reads history"| node_sqlite
node_air_analysis -->|"triggers alerts"| node_alerts
node_node_monitor -->|"checks node records"| node_sqlite
node_node_monitor -->|"reports node events"| node_alerts
node_api -->|"reads and writes"| node_sqlite
node_api -->|"uses notification settings"| node_alerts
node_api -->|"uses history helpers"| node_mqtt_ingest
node_alerts -->|"persists alert state"| node_sqlite
node_alerts -->|"tracks cooldowns"| node_runtime_state
node_alerts -->|"sends pushes"| node_firebase
node_server_checks -.->|"raises watchdog alerts"| node_alerts
node_server_checks -.->|"checks stored state"| node_sqlite
node_backup -.->|"backs up database"| node_sqlite
node_android_user -->|"views readings"| node_android_home
node_android_home -->|"requests dashboard data"| node_api_client
node_history -->|"requests history"| node_api_client
node_api_client -.->|"calls REST endpoints"| node_api
node_notification_settings -->|"updates preferences"| node_api_client
node_notification_settings -->|"configures auto-arm"| node_location_arm
node_location_arm -->|"queues arm changes"| node_arm_worker
node_arm_worker -->|"posts arm state"| node_location_arm
node_location_arm -.->|"posts occupancy state"| node_api_client
node_firebase -.->|"delivers notifications"| node_push_service
node_web_user -->|"views sensor data"| node_web_dashboard
node_web_dashboard -.->|"subscribes over WebSockets"| node_mqtt
node_android_home -.->|"shares sensor display"| node_widget

click node_homeping_lib "https://github.com/rusk0d/home-ping/blob/main/firmware/libraries/HomePing/src/HomePing.h"
click node_backend_entry "https://github.com/rusk0d/home-ping/blob/main/backend/server.py"
click node_mqtt_ingest "https://github.com/rusk0d/home-ping/blob/main/backend/ingest.py"
click node_air_analysis "https://github.com/rusk0d/home-ping/blob/main/backend/air.py"
click node_node_monitor "https://github.com/rusk0d/home-ping/blob/main/backend/nodes.py"
click node_api "https://github.com/rusk0d/home-ping/blob/main/backend/api.py"
click node_sqlite "https://github.com/rusk0d/home-ping/blob/main/backend/store.py"
click node_runtime_state "https://github.com/rusk0d/home-ping/blob/main/backend/state.py"
click node_alerts "https://github.com/rusk0d/home-ping/blob/main/backend/alerts.py"
click node_server_checks "https://github.com/rusk0d/home-ping/blob/main/backend/server_checks.py"
click node_backup "https://github.com/rusk0d/home-ping/blob/main/backend/backup_db.py"
click node_android_home "https://github.com/rusk0d/home-ping/blob/main/android/app/src/main/java/com/david/homeenv/HomeFragment.kt"
click node_history "https://github.com/rusk0d/home-ping/blob/main/android/app/src/main/java/com/david/homeenv/HistoryActivity.kt"
click node_api_client "https://github.com/rusk0d/home-ping/blob/main/android/app/src/main/java/com/david/homeenv/Api.kt"
click node_location_arm "https://github.com/rusk0d/home-ping/blob/main/android/app/src/main/java/com/david/homeenv/HomeGeofence.kt"
click node_arm_worker "https://github.com/rusk0d/home-ping/blob/main/android/app/src/main/java/com/david/homeenv/ArmWorker.kt"
click node_notification_settings "https://github.com/rusk0d/home-ping/blob/main/android/app/src/main/java/com/david/homeenv/NotificationSettingsActivity.kt"
click node_push_service "https://github.com/rusk0d/home-ping/blob/main/android/app/src/main/java/com/david/homeenv/MyFirebaseMessagingService.kt"
click node_widget "https://github.com/rusk0d/home-ping/blob/main/android/app/src/main/java/com/david/homeenv/HomeEnvWidget.kt"
click node_web_dashboard "https://github.com/rusk0d/home-ping/blob/main/web/app.js"

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_esp_nodes,node_mqtt,node_homeping_lib,node_android_user,node_web_user toneBlue
class node_backend_entry,node_mqtt_ingest,node_air_analysis,node_node_monitor,node_api,node_sqlite,node_runtime_state,node_alerts,node_server_checks,node_backup toneAmber
class node_android_home,node_history,node_api_client,node_location_arm,node_arm_worker,node_notification_settings,node_push_service,node_widget toneMint
class node_web_dashboard toneRose
class node_firebase toneIndigo
```

## Components

### Sensing and transport

- **ESP32 sensor nodes**
- **MQTT broker**
- [Shared node library](https://github.com/rusk0d/home-ping/blob/main/firmware/libraries/HomePing/src/HomePing.h): `firmware/libraries/HomePing/src/HomePing.h`

### Backend services

- [Backend runtime](https://github.com/rusk0d/home-ping/blob/main/backend/server.py): `backend/server.py`
- [MQTT ingestion](https://github.com/rusk0d/home-ping/blob/main/backend/ingest.py): `backend/ingest.py`
- [Air analysis](https://github.com/rusk0d/home-ping/blob/main/backend/air.py): `backend/air.py`
- [Node monitoring](https://github.com/rusk0d/home-ping/blob/main/backend/nodes.py): `backend/nodes.py`
- [REST API](https://github.com/rusk0d/home-ping/blob/main/backend/api.py): `backend/api.py`
- [SQLite store](https://github.com/rusk0d/home-ping/blob/main/backend/store.py): `backend/store.py`
- [Runtime state](https://github.com/rusk0d/home-ping/blob/main/backend/state.py): `backend/state.py`
- [Alerting and settings](https://github.com/rusk0d/home-ping/blob/main/backend/alerts.py): `backend/alerts.py`
- [Server watchdog](https://github.com/rusk0d/home-ping/blob/main/backend/server_checks.py): `backend/server_checks.py`
- [Database backups](https://github.com/rusk0d/home-ping/blob/main/backend/backup_db.py): `backend/backup_db.py`

### Android client

- [Home dashboard](https://github.com/rusk0d/home-ping/blob/main/android/app/src/main/java/com/david/homeenv/HomeFragment.kt): `android/app/src/main/java/com/david/homeenv/HomeFragment.kt`
- [History view](https://github.com/rusk0d/home-ping/blob/main/android/app/src/main/java/com/david/homeenv/HistoryActivity.kt): `android/app/src/main/java/com/david/homeenv/HistoryActivity.kt`
- [REST client](https://github.com/rusk0d/home-ping/blob/main/android/app/src/main/java/com/david/homeenv/Api.kt): `android/app/src/main/java/com/david/homeenv/Api.kt`
- [Location arming](https://github.com/rusk0d/home-ping/blob/main/android/app/src/main/java/com/david/homeenv/HomeGeofence.kt): `android/app/src/main/java/com/david/homeenv/HomeGeofence.kt`
- [Retry worker](https://github.com/rusk0d/home-ping/blob/main/android/app/src/main/java/com/david/homeenv/ArmWorker.kt): `android/app/src/main/java/com/david/homeenv/ArmWorker.kt`
- [Notification settings](https://github.com/rusk0d/home-ping/blob/main/android/app/src/main/java/com/david/homeenv/NotificationSettingsActivity.kt): `android/app/src/main/java/com/david/homeenv/NotificationSettingsActivity.kt`
- [Push handling](https://github.com/rusk0d/home-ping/blob/main/android/app/src/main/java/com/david/homeenv/MyFirebaseMessagingService.kt): `android/app/src/main/java/com/david/homeenv/MyFirebaseMessagingService.kt`
- [Home-screen widget](https://github.com/rusk0d/home-ping/blob/main/android/app/src/main/java/com/david/homeenv/HomeEnvWidget.kt): `android/app/src/main/java/com/david/homeenv/HomeEnvWidget.kt`

### Web dashboard

- [Web dashboard](https://github.com/rusk0d/home-ping/blob/main/web/app.js): `web/app.js`

### Other components

- **Firebase messaging**
- **Phone user**
- **Web user**

## Connections

- ESP32 sensor nodes → MQTT broker: publishes readings
- Shared node library → ESP32 sensor nodes: supports node networking
- MQTT broker → MQTT ingestion: delivers messages
- Backend runtime → SQLite store: initializes and loads (evidence: `backend/server.py`)
- Backend runtime → MQTT ingestion: registers callbacks (evidence: `backend/server.py`)
- Backend runtime → Node monitoring: starts monitor (evidence: `backend/server.py`)
- Backend runtime → Air analysis: starts analysis (evidence: `backend/server.py`)
- Backend runtime → REST API: serves routes (evidence: `backend/server.py`)
- MQTT ingestion → SQLite store: stores readings (evidence: `backend/ingest.py`)
- MQTT ingestion → Alerting and settings: triggers alerts (evidence: `backend/ingest.py`)
- MQTT ingestion → Runtime state: updates state (evidence: `backend/ingest.py`)
- Air analysis → SQLite store: reads history (evidence: `backend/air.py`)
- Air analysis → Alerting and settings: triggers alerts (evidence: `backend/air.py`)
- Node monitoring → SQLite store: checks node records (evidence: `backend/nodes.py`)
- Node monitoring → Alerting and settings: reports node events (evidence: `backend/nodes.py`)
- REST API → SQLite store: reads and writes (evidence: `backend/api.py`)
- REST API → Alerting and settings: uses notification settings (evidence: `backend/api.py`)
- REST API → MQTT ingestion: uses history helpers (evidence: `backend/api.py`)
- Alerting and settings → SQLite store: persists alert state (evidence: `backend/alerts.py`)
- Alerting and settings → Runtime state: tracks cooldowns (evidence: `backend/alerts.py`)
- Alerting and settings → Firebase messaging: sends pushes (evidence: `backend/alerts.py`)
- Server watchdog → Alerting and settings: raises watchdog alerts (evidence: `backend/server_checks.py`)
- Server watchdog → SQLite store: checks stored state (evidence: `backend/server_checks.py`)
- Database backups → SQLite store: backs up database
- Phone user → Home dashboard: views readings
- Home dashboard → REST client: requests dashboard data (evidence: `android/app/src/main/java/com/david/homeenv/HomeFragment.kt`)
- History view → REST client: requests history (evidence: `android/app/src/main/java/com/david/homeenv/HistoryActivity.kt`)
- REST client → REST API: calls REST endpoints
- Notification settings → REST client: updates preferences (evidence: `android/app/src/main/java/com/david/homeenv/NotificationSettingsActivity.kt`)
- Notification settings → Location arming: configures auto-arm (evidence: `android/app/src/main/java/com/david/homeenv/NotificationSettingsActivity.kt`)
- Location arming → Retry worker: queues arm changes (evidence: `android/app/src/main/java/com/david/homeenv/HomeGeofence.kt`)
- Retry worker → Location arming: posts arm state (evidence: `android/app/src/main/java/com/david/homeenv/ArmWorker.kt`)
- Location arming → REST client: posts occupancy state (evidence: `android/app/src/main/java/com/david/homeenv/HomeGeofence.kt`)
- Firebase messaging → Push handling: delivers notifications
- Web user → Web dashboard: views sensor data
- Web dashboard → MQTT broker: subscribes over WebSockets
- Home dashboard → Home-screen widget: shares sensor display
