# hamedsafikhani/takhfifan-payment-dr architecture

> Architecture diagram of the GitHub repository hamedsafikhani/takhfifan-payment-dr, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hamedsafikhani/takhfifan-payment-dr
- Repository: https://github.com/hamedsafikhani/takhfifan-payment-dr

## Overview

This repository documents a PostgreSQL payment-database disaster-recovery exercise: deploy a master and streaming replica, establish a healthy baseline, simulate dirty data during live traffic, recover to a point before the incident, and selectively merge the recovered state while preserving later valid transactions. A separate monitoring branch exposes database metrics and alerts. The graph follows the README and file tree; source excerpts were unavailable, so links whose wiring is not documented are omitted.

Main entry points: [`k8s/03-master-statefulset.yaml`](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/03-master-statefulset.yaml) (Postgres master), [`k8s/05-replica-statefulset.yaml`](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/05-replica-statefulset.yaml) (Postgres replica), [`kind/kind-config.yaml`](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/kind/kind-config.yaml) (kind cluster), [`k8s/monitoring/03-exporters.yaml`](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/monitoring/03-exporters.yaml) (DB exporters)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_database["Database topology"]
  node_cluster["kind cluster<br/>[kind-config.yaml]"]
  node_master[("Postgres master")]
  node_rw["Write service"]
  node_replica[("Postgres replica")]
  node_ro["Read service"]
  node_init["Schema initialization"]
  node_schema["Payment schema<br/>[01-schema.sql]"]
end

subgraph group_recovery["Recovery workflow"]
  node_archive[("WAL archive")]
  node_recovery[("PITR instance")]
  node_merge["Selective merge"]
end

subgraph group_workload["Payment workload"]
  node_seed["Baseline data<br/>[02-seed-data.sql]"]
  node_traffic["Traffic generator"]
  node_incident["Dirty-data incident<br/>[03-incident.sql]"]
end

subgraph group_monitoring["Monitoring"]
  node_exporters["DB exporters<br/>[03-exporters.yaml]"]
  node_prometheus["Prometheus<br/>[06-prometheus.yaml]"]
  node_rules["Alert rules"]
  node_grafana["Grafana dashboard<br/>[09-grafana.yaml]"]
end

node_operator(("DBA / operator"))

node_operator -->|"provisions"| node_cluster
node_operator -->|"operates"| node_master
node_cluster -->|"hosts"| node_master
node_cluster -->|"hosts"| node_replica
node_init -->|"initializes"| node_master
node_schema -->|"defines schema"| node_init
node_master -->|"serves writes"| node_rw
node_replica -->|"serves reads"| node_ro
node_master -->|"streams WAL"| node_replica
node_master -->|"archives WAL"| node_archive
node_operator -->|"loads baseline"| node_seed
node_seed -->|"seeds rows"| node_master
node_traffic -->|"sends traffic"| node_rw
node_operator -->|"executes"| node_incident
node_incident -->|"damages data"| node_master
node_operator -->|"starts PITR"| node_recovery
node_archive -->|"supplies WAL"| node_recovery
node_operator -->|"executes merge"| node_merge
node_merge -->|"restores selected rows"| node_master
node_master -->|"exposes metrics"| node_exporters
node_replica -->|"exposes metrics"| node_exporters
node_exporters -->|"scrapes metrics"| node_prometheus
node_rules -->|"configures alerts"| node_prometheus
node_prometheus -->|"feeds dashboards"| node_grafana

click node_cluster "https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/kind/kind-config.yaml"
click node_master "https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/03-master-statefulset.yaml"
click node_rw "https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/04-master-services.yaml"
click node_replica "https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/05-replica-statefulset.yaml"
click node_ro "https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/06-replica-services.yaml"
click node_init "https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/02-configmap-init-sql.yaml"
click node_schema "https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/sql/01-schema.sql"
click node_seed "https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/sql/02-seed-data.sql"
click node_traffic "https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/scripts/traffic-generator.sh"
click node_incident "https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/sql/03-incident.sql"
click node_archive "https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/03-master-statefulset.yaml"
click node_recovery "https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/07-recovery-pod.yaml"
click node_merge "https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/sql/04-recovery-merge.sql"
click node_exporters "https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/monitoring/03-exporters.yaml"
click node_prometheus "https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/monitoring/06-prometheus.yaml"
click node_rules "https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/monitoring/05-prometheus-config.yaml"
click node_grafana "https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/monitoring/09-grafana.yaml"

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_cluster,node_master,node_rw,node_replica,node_ro,node_init,node_schema toneBlue
class node_archive,node_recovery,node_merge toneAmber
class node_seed,node_traffic,node_incident toneMint
class node_exporters,node_prometheus,node_rules,node_grafana toneRose
class node_operator toneIndigo
```

## Components

### Database topology

- [kind cluster](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/kind/kind-config.yaml): `kind/kind-config.yaml`
- [Postgres master](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/03-master-statefulset.yaml): `k8s/03-master-statefulset.yaml`
- [Write service](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/04-master-services.yaml): `k8s/04-master-services.yaml`
- [Postgres replica](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/05-replica-statefulset.yaml): `k8s/05-replica-statefulset.yaml`
- [Read service](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/06-replica-services.yaml): `k8s/06-replica-services.yaml`
- [Schema initialization](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/02-configmap-init-sql.yaml): `k8s/02-configmap-init-sql.yaml`
- [Payment schema](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/sql/01-schema.sql): `sql/01-schema.sql`

### Recovery workflow

- [WAL archive](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/03-master-statefulset.yaml): `k8s/03-master-statefulset.yaml`
- [PITR instance](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/07-recovery-pod.yaml): `k8s/07-recovery-pod.yaml`
- [Selective merge](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/sql/04-recovery-merge.sql): `sql/04-recovery-merge.sql`

### Payment workload

- [Baseline data](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/sql/02-seed-data.sql): `sql/02-seed-data.sql`
- [Traffic generator](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/scripts/traffic-generator.sh): `scripts/traffic-generator.sh`
- [Dirty-data incident](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/sql/03-incident.sql): `sql/03-incident.sql`

### Monitoring

- [DB exporters](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/monitoring/03-exporters.yaml): `k8s/monitoring/03-exporters.yaml`
- [Prometheus](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/monitoring/06-prometheus.yaml): `k8s/monitoring/06-prometheus.yaml`
- [Alert rules](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/monitoring/05-prometheus-config.yaml): `k8s/monitoring/05-prometheus-config.yaml`
- [Grafana dashboard](https://github.com/hamedsafikhani/takhfifan-payment-dr/blob/main/k8s/monitoring/09-grafana.yaml): `k8s/monitoring/09-grafana.yaml`

### Other components

- **DBA / operator**

## Connections

- DBA / operator → kind cluster: provisions
- DBA / operator → Postgres master: operates
- kind cluster → Postgres master: hosts
- kind cluster → Postgres replica: hosts
- Schema initialization → Postgres master: initializes
- Payment schema → Schema initialization: defines schema
- Postgres master → Write service: serves writes
- Postgres replica → Read service: serves reads
- Postgres master → Postgres replica: streams WAL
- Postgres master → WAL archive: archives WAL
- DBA / operator → Baseline data: loads baseline
- Baseline data → Postgres master: seeds rows
- Traffic generator → Write service: sends traffic
- DBA / operator → Dirty-data incident: executes
- Dirty-data incident → Postgres master: damages data
- DBA / operator → PITR instance: starts PITR
- WAL archive → PITR instance: supplies WAL
- DBA / operator → Selective merge: executes merge
- Selective merge → Postgres master: restores selected rows
- Postgres master → DB exporters: exposes metrics
- Postgres replica → DB exporters: exposes metrics
- DB exporters → Prometheus: scrapes metrics
- Alert rules → Prometheus: configures alerts
- Prometheus → Grafana dashboard: feeds dashboards
