# ngohamah/kafka-patient-heartbeat-data-pipeline architecture

> Architecture diagram of the GitHub repository ngohamah/kafka-patient-heartbeat-data-pipeline, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ngohamah/kafka-patient-heartbeat-data-pipeline
- Repository: https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline

## Overview

This repository simulates customer heart-rate readings and streams them through Kafka for validation, anomaly classification, and batched PostgreSQL storage. The principal workflow runs from the producer through the Kafka topic to the consumer and database; Grafana optionally visualizes stored readings. Configuration and shared logging support the runtime components. The Grafana relationship and schema provisioning are documented in the README; dashboard internals were not sampled.

Main entry points: [`src/kafka_consumer.py`](https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/blob/master/src/kafka_consumer.py) (Kafka consumer), [`src/config.py`](https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/blob/master/src/config.py) (Pipeline configuration), [`src/kafka_producer.py`](https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/blob/master/src/kafka_producer.py) (Kafka producer), [`src/db.py`](https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/blob/master/src/db.py) (Database access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_generation["Reading generation"]
  node_generator["Reading simulator<br/>[data_generator.py]"]
end

subgraph group_streaming["Kafka pipeline"]
  node_producer["Kafka producer<br/>[kafka_producer.py]"]
  node_kafka["Kafka topic"]
  node_consumer["Kafka consumer<br/>[kafka_consumer.py]"]
  node_validation["Message validation<br/>[validation.py]"]
end

subgraph group_storage["Persistence and monitoring"]
  node_db_access["Database access<br/>[db.py]"]
  node_schema["Database schema<br/>[schema.sql]"]
  node_postgres[("PostgreSQL")]
  node_grafana["Grafana dashboards"]
end

subgraph group_support["Runtime support"]
  node_config["Pipeline configuration<br/>[config.py]"]
  node_logging["Shared logging<br/>[logging_setup.py]"]
end

node_producer -->|"generates with"| node_generator
node_producer -->|"publishes readings"| node_kafka
node_consumer -->|"subscribes and polls"| node_kafka
node_consumer -->|"parses and classifies"| node_validation
node_consumer -->|"inserts batches"| node_db_access
node_db_access -->|"writes and queries"| node_postgres
node_schema -->|"defines table and indexes"| node_postgres
node_grafana -->|"charts stored readings"| node_postgres
node_producer -->|"reads settings"| node_config
node_generator -->|"reads generation settings"| node_config
node_consumer -->|"reads settings"| node_config
node_validation -->|"reads thresholds"| node_config
node_db_access -->|"reads connection settings"| node_config
node_producer -->|"logs events"| node_logging
node_consumer -->|"logs outcomes"| node_logging
node_db_access -->|"logs database events"| node_logging
node_logging -->|"reads logging settings"| node_config

click node_producer "https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/blob/master/src/kafka_producer.py"
click node_generator "https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/blob/master/src/data_generator.py"
click node_consumer "https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/blob/master/src/kafka_consumer.py"
click node_validation "https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/blob/master/src/validation.py"
click node_db_access "https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/blob/master/src/db.py"
click node_schema "https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/blob/master/sql/schema.sql"
click node_grafana "https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/tree/master/dashboard/grafana/provisioning"
click node_config "https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/blob/master/src/config.py"
click node_logging "https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/blob/master/src/logging_setup.py"

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_generator toneBlue
class node_producer,node_kafka,node_consumer,node_validation toneAmber
class node_db_access,node_schema,node_postgres,node_grafana toneMint
class node_config,node_logging toneRose
```

## Components

### Reading generation

- [Reading simulator](https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/blob/master/src/data_generator.py): `src/data_generator.py`

### Kafka pipeline

- [Kafka producer](https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/blob/master/src/kafka_producer.py): `src/kafka_producer.py`
- **Kafka topic**
- [Kafka consumer](https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/blob/master/src/kafka_consumer.py): `src/kafka_consumer.py`
- [Message validation](https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/blob/master/src/validation.py): `src/validation.py`

### Persistence and monitoring

- [Database access](https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/blob/master/src/db.py): `src/db.py`
- [Database schema](https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/blob/master/sql/schema.sql): `sql/schema.sql`
- **PostgreSQL**
- [Grafana dashboards](https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/tree/master/dashboard/grafana/provisioning): `dashboard/grafana/provisioning`

### Runtime support

- [Pipeline configuration](https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/blob/master/src/config.py): `src/config.py`
- [Shared logging](https://github.com/ngohamah/kafka-patient-heartbeat-data-pipeline/blob/master/src/logging_setup.py): `src/logging_setup.py`

## Connections

- Kafka producer → Reading simulator: generates with (evidence: `src/kafka_producer.py`)
- Kafka producer → Kafka topic: publishes readings (evidence: `src/kafka_producer.py`)
- Kafka consumer → Kafka topic: subscribes and polls (evidence: `src/kafka_consumer.py`)
- Kafka consumer → Message validation: parses and classifies (evidence: `src/kafka_consumer.py`)
- Kafka consumer → Database access: inserts batches (evidence: `src/kafka_consumer.py`)
- Database access → PostgreSQL: writes and queries (evidence: `src/db.py`)
- Database schema → PostgreSQL: defines table and indexes (evidence: `README.md`)
- Grafana dashboards → PostgreSQL: charts stored readings (evidence: `README.md`)
- Kafka producer → Pipeline configuration: reads settings (evidence: `src/kafka_producer.py`)
- Reading simulator → Pipeline configuration: reads generation settings (evidence: `src/data_generator.py`)
- Kafka consumer → Pipeline configuration: reads settings (evidence: `src/kafka_consumer.py`)
- Message validation → Pipeline configuration: reads thresholds (evidence: `src/validation.py`)
- Database access → Pipeline configuration: reads connection settings (evidence: `src/db.py`)
- Kafka producer → Shared logging: logs events (evidence: `src/kafka_producer.py`)
- Kafka consumer → Shared logging: logs outcomes (evidence: `src/kafka_consumer.py`)
- Database access → Shared logging: logs database events (evidence: `src/db.py`)
- Shared logging → Pipeline configuration: reads logging settings (evidence: `src/logging_setup.py`)
