# fmukama/customer-heart-beat-monitoring-system architecture

> Architecture diagram of the GitHub repository fmukama/customer-heart-beat-monitoring-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fmukama/customer-heart-beat-monitoring-system
- Repository: https://github.com/fmukama/customer-heart-beat-monitoring-system

## Overview

This repository is a simulated heart-rate streaming and monitoring product. Its primary workflow generates sensor-like events, publishes them through Kafka, validates and processes them by event time, and persists raw readings and daily aggregates. A parallel operations workflow turns Prometheus alerts into firing/resolved records in PostgreSQL. The graph retains the documented observability and dead-letter capabilities; connections involving unsampled infrastructure configuration are cited to the README rather than inferred from filenames.

Main entry points: [`consumer/consumer.py`](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/consumer.py) (Kafka consumer), [`consumer/aggregator.py`](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/aggregator.py) (Daily aggregator), [`notifier/server.py`](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/notifier/server.py) (Alert webhook server), [`simulator/generator.py`](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/simulator/generator.py) (Event generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Event Ingestion"]
  node_simulator["Event generator<br/>[generator.py]"]
  node_faults["Fault injection<br/>[faults.py]"]
  node_producer["Kafka producer<br/>[producer.py]"]
  node_kafka["Kafka topics"]
end

subgraph group_processing["Stream Processing"]
  node_consumer["Kafka consumer<br/>[consumer.py]"]
  node_validation["Event validation<br/>[validation.py]"]
  node_dlq["Dead-letter publisher<br/>[dlq.py]"]
  node_classification["Abnormal classification<br/>[anomaly.py]"]
  node_aggregator["Daily aggregator<br/>[aggregator.py]"]
  node_watermark["Watermark tracking<br/>[watermark.py]"]
  node_lateness["Lateness policy<br/>[lateness.py]"]
  node_windows["Daily windows<br/>[windows.py]"]
  node_window_state["Window state<br/>[window_state.py]"]
end

subgraph group_storage["Persistence"]
  node_postgres[("PostgreSQL")]
  node_event_repository["Event and aggregate repository<br/>[repository.py]"]
  node_notification_repository["Lifecycle repository<br/>[repository.py]"]
end

subgraph group_operations["Alerting and Observability"]
  node_consumer_metrics["Consumer metrics<br/>[metrics.py]"]
  node_alert_rules["Prometheus alert rules<br/>[alerts.yml]"]
  node_prometheus["Prometheus"]
  node_alertmanager["Alertmanager"]
  node_notifier_server["Alert webhook server<br/>[server.py]"]
  node_alert_payload["Alert parser<br/>[payload.py]"]
  node_notification_store["Notification store<br/>[store.py]"]
  node_notifier_metrics["Notifier metrics<br/>[metrics.py]"]
  node_grafana["Grafana dashboards<br/>[heartbeat.json]"]
end

node_sensors(("Simulated sensors"))

node_sensors -->|"simulates readings"| node_simulator
node_simulator -->|"injects faults"| node_faults
node_simulator -->|"pipes JSON to"| node_producer
node_producer -->|"publishes events"| node_kafka
node_kafka -->|"delivers events"| node_consumer
node_consumer -->|"validates events"| node_validation
node_consumer -->|"classifies readings"| node_classification
node_consumer -->|"processes event time"| node_aggregator
node_consumer -->|"dead-letters invalid"| node_dlq
node_aggregator -->|"tracks progress"| node_watermark
node_aggregator -->|"judges lateness"| node_lateness
node_aggregator -->|"assigns day windows"| node_windows
node_aggregator -->|"updates state"| node_window_state
node_consumer -->|"persists readings and windows"| node_event_repository
node_event_repository -->|"reads and writes"| node_postgres
node_consumer -->|"records processing metrics"| node_consumer_metrics
node_consumer_metrics -->|"exposes metrics"| node_prometheus
node_prometheus -->|"evaluates rules"| node_alert_rules
node_prometheus -->|"provides metrics"| node_grafana
node_prometheus -->|"routes alerts"| node_alertmanager
node_alertmanager -->|"posts webhooks"| node_notifier_server
node_notifier_server -->|"parses alerts"| node_alert_payload
node_notifier_server -->|"saves notifications"| node_notification_store
node_notification_store -->|"records transitions"| node_notification_repository
node_notification_repository -->|"writes lifecycle rows"| node_postgres
node_notifier_server -->|"serves metrics"| node_notifier_metrics
node_notifier_metrics -->|"exposes metrics"| node_prometheus

click node_simulator "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/simulator/generator.py"
click node_faults "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/simulator/faults.py"
click node_producer "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/producer/producer.py"
click node_consumer "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/consumer.py"
click node_validation "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/validation.py"
click node_dlq "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/dlq.py"
click node_classification "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/anomaly.py"
click node_aggregator "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/aggregator.py"
click node_watermark "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/watermark.py"
click node_lateness "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/lateness.py"
click node_windows "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/windows.py"
click node_window_state "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/window_state.py"
click node_consumer_metrics "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/metrics.py"
click node_event_repository "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/repository.py"
click node_alert_rules "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/config/alerts.yml"
click node_notifier_server "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/notifier/server.py"
click node_alert_payload "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/notifier/payload.py"
click node_notification_store "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/notifier/store.py"
click node_notification_repository "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/notifier/repository.py"
click node_notifier_metrics "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/notifier/metrics.py"
click node_grafana "https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/config/grafana/dashboards/heartbeat.json"

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_simulator,node_faults,node_producer,node_kafka toneBlue
class node_consumer,node_validation,node_dlq,node_classification,node_aggregator,node_watermark,node_lateness,node_windows,node_window_state toneAmber
class node_postgres,node_event_repository,node_notification_repository toneMint
class node_consumer_metrics,node_alert_rules,node_prometheus,node_alertmanager,node_notifier_server,node_alert_payload,node_notification_store,node_notifier_metrics,node_grafana toneRose
class node_sensors toneIndigo
```

## Components

### Event Ingestion

- [Event generator](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/simulator/generator.py): `simulator/generator.py`
- [Fault injection](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/simulator/faults.py): `simulator/faults.py`
- [Kafka producer](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/producer/producer.py): `producer/producer.py`
- **Kafka topics**

### Stream Processing

- [Kafka consumer](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/consumer.py): `consumer/consumer.py`
- [Event validation](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/validation.py): `consumer/validation.py`
- [Dead-letter publisher](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/dlq.py): `consumer/dlq.py`
- [Abnormal classification](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/anomaly.py): `consumer/anomaly.py`
- [Daily aggregator](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/aggregator.py): `consumer/aggregator.py`
- [Watermark tracking](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/watermark.py): `consumer/watermark.py`
- [Lateness policy](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/lateness.py): `consumer/lateness.py`
- [Daily windows](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/windows.py): `consumer/windows.py`
- [Window state](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/window_state.py): `consumer/window_state.py`

### Persistence

- **PostgreSQL**
- [Event and aggregate repository](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/repository.py): `consumer/repository.py`
- [Lifecycle repository](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/notifier/repository.py): `notifier/repository.py`

### Alerting and Observability

- [Consumer metrics](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/consumer/metrics.py): `consumer/metrics.py`
- [Prometheus alert rules](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/config/alerts.yml): `config/alerts.yml`
- **Prometheus**
- **Alertmanager**
- [Alert webhook server](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/notifier/server.py): `notifier/server.py`
- [Alert parser](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/notifier/payload.py): `notifier/payload.py`
- [Notification store](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/notifier/store.py): `notifier/store.py`
- [Notifier metrics](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/notifier/metrics.py): `notifier/metrics.py`
- [Grafana dashboards](https://github.com/fmukama/customer-heart-beat-monitoring-system/blob/main/config/grafana/dashboards/heartbeat.json): `config/grafana/dashboards/heartbeat.json`

### Other components

- **Simulated sensors**

## Connections

- Simulated sensors → Event generator: simulates readings (evidence: `ReadMe.md`)
- Event generator → Fault injection: injects faults (evidence: `simulator/generator.py`)
- Event generator → Kafka producer: pipes JSON to (evidence: `simulator/generator.py`)
- Kafka producer → Kafka topics: publishes events (evidence: `ReadMe.md`)
- Kafka topics → Kafka consumer: delivers events (evidence: `ReadMe.md`)
- Kafka consumer → Event validation: validates events (evidence: `consumer/consumer.py`)
- Kafka consumer → Abnormal classification: classifies readings (evidence: `consumer/consumer.py`)
- Kafka consumer → Daily aggregator: processes event time (evidence: `consumer/consumer.py`)
- Kafka consumer → Dead-letter publisher: dead-letters invalid (evidence: `consumer/consumer.py`)
- Daily aggregator → Watermark tracking: tracks progress (evidence: `consumer/aggregator.py`)
- Daily aggregator → Lateness policy: judges lateness (evidence: `consumer/aggregator.py`)
- Daily aggregator → Daily windows: assigns day windows (evidence: `consumer/aggregator.py`)
- Daily aggregator → Window state: updates state (evidence: `consumer/aggregator.py`)
- Kafka consumer → Event and aggregate repository: persists readings and windows (evidence: `consumer/consumer.py`)
- Event and aggregate repository → PostgreSQL: reads and writes (evidence: `consumer/repository.py`)
- Kafka consumer → Consumer metrics: records processing metrics (evidence: `consumer/consumer.py`)
- Consumer metrics → Prometheus: exposes metrics (evidence: `ReadMe.md`)
- Prometheus → Prometheus alert rules: evaluates rules (evidence: `ReadMe.md`)
- Prometheus → Grafana dashboards: provides metrics (evidence: `ReadMe.md`)
- Prometheus → Alertmanager: routes alerts (evidence: `ReadMe.md`)
- Alertmanager → Alert webhook server: posts webhooks (evidence: `ReadMe.md`)
- Alert webhook server → Alert parser: parses alerts (evidence: `notifier/server.py`)
- Alert webhook server → Notification store: saves notifications (evidence: `notifier/server.py`)
- Notification store → Lifecycle repository: records transitions (evidence: `notifier/store.py`)
- Lifecycle repository → PostgreSQL: writes lifecycle rows (evidence: `notifier/repository.py`)
- Alert webhook server → Notifier metrics: serves metrics (evidence: `notifier/server.py`)
- Notifier metrics → Prometheus: exposes metrics (evidence: `ReadMe.md`)
