How raunakmali08/self-healing-infra works
1. This repo is not just one app; it contains a small task-management product plus a full observability/self-healing stack around it. The main production path is the self-healing-task-manager/ directory, while the root-level prometheus/, grafana/, loki/, promtail/, alertmanager/, and webhook-receiver/ directories form the monitoring and alerting plane.
2. The core application flow is: browser → React frontend → Node.js/Express backend → PostgreSQL. The frontend is a Vite-built React SPA, typically served from an Nginx container. It handles task CRUD interactions and calls the backend over HTTP.
3. The backend is the application boundary for business logic. It exposes task endpoints plus /health and /metrics, which makes it both the API service and the observability source. Its db.js file manages the PostgreSQL connection pool, and server.js is the request/response hub.
4. PostgreSQL is the persistence layer. The postgres/init.sql file bootstraps schema/data, and the backend connects through DATABASE_URL and pool settings from .env. This is the durable state boundary for tasks; everything else is disposable container state.
5. Self-healing is implemented at the container orchestration layer, not inside the app logic. Docker health checks probe PostgreSQL with pg_isready, the backend with /health, and the frontend with /health. Docker Compose restarts unhealthy services automatically, so the recovery mechanism is external to the code.
6. The observability pipeline starts with the backend exporting Prometheus metrics. prometheus/prometheus.yml and prometheus/alert_rules.yml define scrape and alerting behavior. Grafana is provisioned automatically with Prometheus as a datasource and dashboards for the task manager and logs.
7. Logging is handled as a separate path from metrics. promtail/config.yml ships container logs into Loki (loki/config.yml), and Grafana includes a logs overview dashboard. This means metrics and logs are intentionally split into two monitoring backends: Prometheus for time-series health/performance, Loki for log aggregation.
8. Alerting flows from Prometheus to Alertmanager (alertmanager/alertmanager.yml). The presence of webhook-receiver/receiver.py suggests alerts are forwarded to a simple webhook endpoint rather than a complex ticketing system, making alert handling an explicit integration boundary.
9. There are two Docker Compose scopes in the repo: the app-specific compose file under self-healing-task-manager/ and a root-level docker-compose.yml for the wider monitoring stack. The repo also includes setup-network.sh and an Ansible playbook/inventory, which imply the deployment model can be bootstrapped locally or automated on remote hosts.
10. The flask-app/ and top-level Node/, metrics/, Prometheus Stats, Prometheus 2.0 Stats, Grafana metrics, and logs Overview entries look like auxiliary demos, notes, or experiments rather than the main runtime path. For an architecture diagram, they should be treated as supporting examples unless you are explicitly documenting the whole repo as a lab environment.
11. The important runtime boundaries to draw are: user/browser boundary, frontend UI boundary, API/service boundary, data store boundary, and observability boundary. The key external integrations are Docker Compose for orchestration, PostgreSQL for persistence, Prometheus/Grafana/Loki for monitoring, and Alertmanager/webhook for alert delivery.
Main entry points: docker-compose.yml Stack Compose · provisioning Grafana · backend Backend API · prometheus.yml Prometheus
Components 19
Task Manager
Main production application stack
- Browser · Human entry point for the task manager UI
- Frontend · Vite-built task UI served via Nginx
self-healing-task-manager/frontend - Backend API · Task endpoints plus health and metrics exposure
self-healing-task-manager/backend - DB Pool · Database connection management and pooling
self-healing-task-manager/backend/db.js - PostgreSQL · Durable task state and initialized schema
self-healing-task-manager/postgres/init.sql
Observability
Metrics, logs, alerts, and dashboards
- Prometheus · Scrapes backend metrics and evaluates alert rules
prometheus/prometheus.yml - Alert Rules · Thresholds and conditions for task manager alerts
prometheus/alert_rules.yml - Alertmanager · Routes Prometheus alerts onward
alertmanager/alertmanager.yml - Webhook Receiver · Simple webhook endpoint for alert delivery
webhook-receiver/receiver.py - Grafana · Provisioned visualization layer for metrics and logs
grafana/provisioning - Prometheus DS · Auto-provisioned Prometheus data source
grafana/provisioning/datasources/prometheus.yml - Task Dashboard · Task manager metrics dashboard
grafana/provisioning/dashboards/task-manager.json - Logs Dashboard · Logs overview dashboard
grafana/provisioning/dashboards/logs-overview.json - Promtail · Ships container logs to Loki
promtail/config.yml - Loki · Central log aggregation backend
loki/config.yml
Deployment
Compose and automation for local or remote bootstrap
- App Compose · Application stack orchestration and health checks
self-healing-task-manager/docker-compose.yml - Stack Compose · Root orchestration for observability services
docker-compose.yml - Ansible · Inventory and playbook for host bootstrap
ansible/playbook.yml - Network Setup · Script for preparing shared runtime networking
setup-network.sh
Connections 22
- Browser → Frontend: uses · User interacts with the SPA
- Frontend → Backend API: HTTP API · Task CRUD requests over HTTP
- Backend API → DB Pool: queries · Business logic accesses the connection pool
- DB Pool → PostgreSQL: SQL · Persistent task storage
- App Compose → Frontend: runs · Defines frontend container and health check
- App Compose → Backend API: runs · Defines backend service and restart policy
- App Compose → PostgreSQL: runs · Defines PostgreSQL service and readiness probe
- Stack Compose → Prometheus: runs · Orchestrates metrics backend
- Stack Compose → Grafana: runs · Orchestrates dashboards
- Stack Compose → Loki: runs · Orchestrates log store
- Stack Compose → Promtail: runs · Orchestrates log shipping
- Stack Compose → Alertmanager: runs · Orchestrates alert routing
- Stack Compose → Webhook Receiver: runs · Orchestrates webhook delivery endpoint
- Backend API → Prometheus: metrics · Backend exposes /metrics for scraping
- Prometheus → Alert Rules: evaluates · Applies alerting rules to scraped metrics
- Prometheus → Alertmanager: alerts · Forwards firing alerts
- Alertmanager → Webhook Receiver: webhook · Delivers alerts to receiver service
- Grafana → Prometheus DS: provisions · Connects Grafana to Prometheus
- Grafana → Task Dashboard: provisions · Loads task manager dashboard
- Grafana → Logs Dashboard: provisions · Loads logs overview dashboard
- Promtail → Loki: ships logs · Forwards container logs to Loki
- Ansible → Network Setup: bootstrap · Supports deployment setup and host preparation