# raunakmali08/self-healing-infra architecture

> Architecture diagram of the GitHub repository raunakmali08/self-healing-infra, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/raunakmali08/self-healing-infra
- Repository: https://github.com/raunakmali08/self-healing-infra

## Overview

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`](https://github.com/raunakmali08/self-healing-infra/blob/main/docker-compose.yml) (Stack Compose), [`grafana/provisioning`](https://github.com/raunakmali08/self-healing-infra/tree/main/grafana/provisioning) (Grafana), [`self-healing-task-manager/backend`](https://github.com/raunakmali08/self-healing-infra/tree/main/self-healing-task-manager/backend) (Backend API), [`prometheus/prometheus.yml`](https://github.com/raunakmali08/self-healing-infra/blob/main/prometheus/prometheus.yml) (Prometheus)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Task Manager"]
  node_browser(("Browser<br/>user client"))
  node_frontend["Frontend<br/>React SPA"]
  node_api["Backend API<br/>Node/Express"]
  node_dbpool["DB Pool<br/>Postgres client<br/>[db.js]"]
  node_taskdb[("PostgreSQL<br/>data store<br/>[init.sql]")]
end

subgraph group_obs["Observability"]
  node_prometheus["Prometheus<br/>metrics backend<br/>[prometheus.yml]"]
  node_alerts["Alert Rules<br/>prometheus rules<br/>[alert_rules.yml]"]
  node_alertmanager["Alertmanager<br/>alert router<br/>[alertmanager.yml]"]
  node_webhook["Webhook Receiver<br/>python service<br/>[receiver.py]"]
  node_grafana["Grafana<br/>dashboarding"]
  node_grafdatasource["Prometheus DS<br/>grafana datasource<br/>[prometheus.yml]"]
  node_taskdash["Task Dashboard<br/>grafana dashboard<br/>[task-manager.json]"]
  node_logdash["Logs Dashboard<br/>grafana dashboard<br/>[logs-overview.json]"]
  node_promtail["Promtail<br/>log shipper<br/>[config.yml]"]
  node_loki[("Loki<br/>log store<br/>[config.yml]")]
end

subgraph group_deploy["Deployment"]
  node_composeapp["App Compose<br/>docker compose<br/>[docker-compose.yml]"]
  node_rootcompose["Stack Compose<br/>docker compose<br/>[docker-compose.yml]"]
  node_ansible["Ansible<br/>automation<br/>[playbook.yml]"]
  node_network["Network Setup<br/>shell bootstrap<br/>[setup-network.sh]"]
end

node_browser -->|"uses"| node_frontend
node_frontend -->|"HTTP API"| node_api
node_api -->|"queries"| node_dbpool
node_dbpool -->|"SQL"| node_taskdb
node_composeapp -->|"runs"| node_frontend
node_composeapp -->|"runs"| node_api
node_composeapp -->|"runs"| node_taskdb
node_rootcompose -->|"runs"| node_prometheus
node_rootcompose -->|"runs"| node_grafana
node_rootcompose -->|"runs"| node_loki
node_rootcompose -->|"runs"| node_promtail
node_rootcompose -->|"runs"| node_alertmanager
node_rootcompose -->|"runs"| node_webhook
node_api -->|"metrics"| node_prometheus
node_prometheus -->|"evaluates"| node_alerts
node_prometheus -->|"alerts"| node_alertmanager
node_alertmanager -->|"webhook"| node_webhook
node_grafana -->|"provisions"| node_grafdatasource
node_grafana -->|"provisions"| node_taskdash
node_grafana -->|"provisions"| node_logdash
node_promtail -->|"ships logs"| node_loki
node_ansible -->|"bootstrap"| node_network

click node_frontend "https://github.com/raunakmali08/self-healing-infra/tree/main/self-healing-task-manager/frontend"
click node_api "https://github.com/raunakmali08/self-healing-infra/tree/main/self-healing-task-manager/backend"
click node_dbpool "https://github.com/raunakmali08/self-healing-infra/blob/main/self-healing-task-manager/backend/db.js"
click node_taskdb "https://github.com/raunakmali08/self-healing-infra/blob/main/self-healing-task-manager/postgres/init.sql"
click node_composeapp "https://github.com/raunakmali08/self-healing-infra/blob/main/self-healing-task-manager/docker-compose.yml"
click node_rootcompose "https://github.com/raunakmali08/self-healing-infra/blob/main/docker-compose.yml"
click node_ansible "https://github.com/raunakmali08/self-healing-infra/blob/main/ansible/playbook.yml"
click node_network "https://github.com/raunakmali08/self-healing-infra/blob/main/setup-network.sh"
click node_prometheus "https://github.com/raunakmali08/self-healing-infra/blob/main/prometheus/prometheus.yml"
click node_alerts "https://github.com/raunakmali08/self-healing-infra/blob/main/prometheus/alert_rules.yml"
click node_alertmanager "https://github.com/raunakmali08/self-healing-infra/blob/main/alertmanager/alertmanager.yml"
click node_webhook "https://github.com/raunakmali08/self-healing-infra/blob/main/webhook-receiver/receiver.py"
click node_grafana "https://github.com/raunakmali08/self-healing-infra/tree/main/grafana/provisioning"
click node_grafdatasource "https://github.com/raunakmali08/self-healing-infra/blob/main/grafana/provisioning/datasources/prometheus.yml"
click node_taskdash "https://github.com/raunakmali08/self-healing-infra/blob/main/grafana/provisioning/dashboards/task-manager.json"
click node_logdash "https://github.com/raunakmali08/self-healing-infra/blob/main/grafana/provisioning/dashboards/logs-overview.json"
click node_promtail "https://github.com/raunakmali08/self-healing-infra/blob/main/promtail/config.yml"
click node_loki "https://github.com/raunakmali08/self-healing-infra/blob/main/loki/config.yml"

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_browser,node_frontend,node_api,node_dbpool,node_taskdb toneBlue
class node_prometheus,node_alerts,node_alertmanager,node_webhook,node_grafana,node_grafdatasource,node_taskdash,node_logdash,node_promtail,node_loki toneAmber
class node_composeapp,node_rootcompose,node_ansible,node_network toneMint
```

## Components

### Task Manager

Main production application stack

- **Browser**: user client · Human entry point for the task manager UI
- [Frontend](https://github.com/raunakmali08/self-healing-infra/tree/main/self-healing-task-manager/frontend): React SPA · Vite-built task UI served via Nginx · `self-healing-task-manager/frontend`
- [Backend API](https://github.com/raunakmali08/self-healing-infra/tree/main/self-healing-task-manager/backend): Node/Express · Task endpoints plus health and metrics exposure · `self-healing-task-manager/backend`
- [DB Pool](https://github.com/raunakmali08/self-healing-infra/blob/main/self-healing-task-manager/backend/db.js): Postgres client · Database connection management and pooling · `self-healing-task-manager/backend/db.js`
- [PostgreSQL](https://github.com/raunakmali08/self-healing-infra/blob/main/self-healing-task-manager/postgres/init.sql): data store · Durable task state and initialized schema · `self-healing-task-manager/postgres/init.sql`

### Observability

Metrics, logs, alerts, and dashboards

- [Prometheus](https://github.com/raunakmali08/self-healing-infra/blob/main/prometheus/prometheus.yml): metrics backend · Scrapes backend metrics and evaluates alert rules · `prometheus/prometheus.yml`
- [Alert Rules](https://github.com/raunakmali08/self-healing-infra/blob/main/prometheus/alert_rules.yml): prometheus rules · Thresholds and conditions for task manager alerts · `prometheus/alert_rules.yml`
- [Alertmanager](https://github.com/raunakmali08/self-healing-infra/blob/main/alertmanager/alertmanager.yml): alert router · Routes Prometheus alerts onward · `alertmanager/alertmanager.yml`
- [Webhook Receiver](https://github.com/raunakmali08/self-healing-infra/blob/main/webhook-receiver/receiver.py): python service · Simple webhook endpoint for alert delivery · `webhook-receiver/receiver.py`
- [Grafana](https://github.com/raunakmali08/self-healing-infra/tree/main/grafana/provisioning): dashboarding · Provisioned visualization layer for metrics and logs · `grafana/provisioning`
- [Prometheus DS](https://github.com/raunakmali08/self-healing-infra/blob/main/grafana/provisioning/datasources/prometheus.yml): grafana datasource · Auto-provisioned Prometheus data source · `grafana/provisioning/datasources/prometheus.yml`
- [Task Dashboard](https://github.com/raunakmali08/self-healing-infra/blob/main/grafana/provisioning/dashboards/task-manager.json): grafana dashboard · Task manager metrics dashboard · `grafana/provisioning/dashboards/task-manager.json`
- [Logs Dashboard](https://github.com/raunakmali08/self-healing-infra/blob/main/grafana/provisioning/dashboards/logs-overview.json): grafana dashboard · Logs overview dashboard · `grafana/provisioning/dashboards/logs-overview.json`
- [Promtail](https://github.com/raunakmali08/self-healing-infra/blob/main/promtail/config.yml): log shipper · Ships container logs to Loki · `promtail/config.yml`
- [Loki](https://github.com/raunakmali08/self-healing-infra/blob/main/loki/config.yml): log store · Central log aggregation backend · `loki/config.yml`

### Deployment

Compose and automation for local or remote bootstrap

- [App Compose](https://github.com/raunakmali08/self-healing-infra/blob/main/self-healing-task-manager/docker-compose.yml): docker compose · Application stack orchestration and health checks · `self-healing-task-manager/docker-compose.yml`
- [Stack Compose](https://github.com/raunakmali08/self-healing-infra/blob/main/docker-compose.yml): docker compose · Root orchestration for observability services · `docker-compose.yml`
- [Ansible](https://github.com/raunakmali08/self-healing-infra/blob/main/ansible/playbook.yml): automation · Inventory and playbook for host bootstrap · `ansible/playbook.yml`
- [Network Setup](https://github.com/raunakmali08/self-healing-infra/blob/main/setup-network.sh): shell bootstrap · Script for preparing shared runtime networking · `setup-network.sh`

## Connections

- 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
