# achraf-oubakouz/pipeline-monitor architecture

> Architecture diagram of the GitHub repository achraf-oubakouz/pipeline-monitor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/achraf-oubakouz/pipeline-monitor
- Repository: https://github.com/achraf-oubakouz/pipeline-monitor

## Overview

Pipeline Monitor generates sales records, streams them through Kafka into PostgreSQL, scans stored sales for anomalies, and exposes status/anomaly views plus Groq-backed natural-language explanations. Airflow provides a separate scheduled producer→consumer→detector workflow. The architecture and sampled source support these principal stages; the Airflow and regular-package implementations are duplicated. Kafka, PostgreSQL, and Groq are external runtime services.

Main entry points: [`dags/pipeline_dag.py`](https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/dags/pipeline_dag.py) (Airflow DAG tasks), [`dags/pipelines/producer.py`](https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/dags/pipelines/producer.py) (Scheduled producer), [`dags/pipelines/consumer.py`](https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/dags/pipelines/consumer.py) (Scheduled consumer), [`dashboard/app.py`](https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/dashboard/app.py) (FastAPI dashboard and API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Sales ingestion"]
  node_salesgen["Sales generation and direct load<br/>[sales_pipeline.py]"]
  node_producer["Kafka producer<br/>[producer.py]"]
  node_consumer["Kafka consumer<br/>[consumer.py]"]
end

subgraph group_orchestration["Workflow scheduling"]
  node_dag["Airflow DAG tasks<br/>[pipeline_dag.py]"]
  node_dagproducer["Scheduled producer<br/>[producer.py]"]
  node_dagconsumer["Scheduled consumer<br/>[consumer.py]"]
  node_dagdetector["Scheduled anomaly detector"]
end

subgraph group_monitoring["Anomaly monitoring"]
  node_detector["Anomaly detection"]
end

subgraph group_presentation["Dashboard and explanations"]
  node_api["FastAPI dashboard and API<br/>[app.py]"]
  node_explainer["Anomaly explanation<br/>[explainer.py]"]
end

node_user(("Browser user"))
node_airflow(("Airflow scheduler"))
node_kafka["Kafka sales topic"]
node_postgres[("PostgreSQL sales table")]
node_groq["Groq Llama service"]

node_producer -->|"generates records"| node_salesgen
node_producer -->|"publishes records"| node_kafka
node_consumer -->|"consumes records"| node_kafka
node_consumer -->|"appends sales"| node_postgres
node_salesgen -->|"writes sales"| node_postgres
node_detector -->|"reads sales"| node_postgres
node_api -->|"requests scan"| node_detector
node_api -->|"requests explanation"| node_explainer
node_explainer -->|"requests completion"| node_groq
node_airflow -.->|"triggers schedule"| node_dag
node_dag -->|"runs first"| node_dagproducer
node_dag -->|"runs second"| node_dagconsumer
node_dag -->|"runs third"| node_dagdetector
node_dagproducer -->|"publishes records"| node_kafka
node_dagproducer -->|"generates records"| node_salesgen
node_dagconsumer -->|"consumes records"| node_kafka
node_dagconsumer -->|"appends sales"| node_postgres
node_dagdetector -->|"reads sales"| node_postgres
node_user -.->|"queries dashboard"| node_api

click node_salesgen "https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/pipelines/sales_pipeline.py"
click node_producer "https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/pipelines/producer.py"
click node_consumer "https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/pipelines/consumer.py"
click node_dag "https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/dags/pipeline_dag.py"
click node_dagproducer "https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/dags/pipelines/producer.py"
click node_dagconsumer "https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/dags/pipelines/consumer.py"
click node_dagdetector "https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/dags/monitor/anomaly_detector.py"
click node_detector "https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/monitor/anomaly_detector.py"
click node_api "https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/dashboard/app.py"
click node_explainer "https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/llm/explainer.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_salesgen,node_producer,node_consumer,node_user toneBlue
class node_dag,node_dagproducer,node_dagconsumer,node_dagdetector,node_postgres toneAmber
class node_detector toneMint
class node_api,node_explainer,node_airflow toneRose
class node_kafka,node_groq toneIndigo
```

## Components

### Sales ingestion

- [Sales generation and direct load](https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/pipelines/sales_pipeline.py): `pipelines/sales_pipeline.py`
- [Kafka producer](https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/pipelines/producer.py): `pipelines/producer.py`
- [Kafka consumer](https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/pipelines/consumer.py): `pipelines/consumer.py`

### Workflow scheduling

- [Airflow DAG tasks](https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/dags/pipeline_dag.py): `dags/pipeline_dag.py`
- [Scheduled producer](https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/dags/pipelines/producer.py): `dags/pipelines/producer.py`
- [Scheduled consumer](https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/dags/pipelines/consumer.py): `dags/pipelines/consumer.py`
- [Scheduled anomaly detector](https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/dags/monitor/anomaly_detector.py): `dags/monitor/anomaly_detector.py`

### Anomaly monitoring

- [Anomaly detection](https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/monitor/anomaly_detector.py): `monitor/anomaly_detector.py`

### Dashboard and explanations

- [FastAPI dashboard and API](https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/dashboard/app.py): `dashboard/app.py`
- [Anomaly explanation](https://github.com/achraf-oubakouz/pipeline-monitor/blob/main/llm/explainer.py): `llm/explainer.py`

### Other components

- **Browser user**
- **Airflow scheduler**
- **Kafka sales topic**
- **PostgreSQL sales table**
- **Groq Llama service**

## Connections

- Kafka producer → Sales generation and direct load: generates records (evidence: `pipelines/producer.py`)
- Kafka producer → Kafka sales topic: publishes records (evidence: `pipelines/producer.py`)
- Kafka consumer → Kafka sales topic: consumes records (evidence: `pipelines/consumer.py`)
- Kafka consumer → PostgreSQL sales table: appends sales (evidence: `pipelines/consumer.py`)
- Sales generation and direct load → PostgreSQL sales table: writes sales (evidence: `pipelines/sales_pipeline.py`)
- Anomaly detection → PostgreSQL sales table: reads sales (evidence: `monitor/anomaly_detector.py`)
- FastAPI dashboard and API → Anomaly detection: requests scan (evidence: `dashboard/app.py`)
- FastAPI dashboard and API → Anomaly explanation: requests explanation (evidence: `dashboard/app.py`)
- Anomaly explanation → Groq Llama service: requests completion (evidence: `llm/explainer.py`)
- Airflow scheduler → Airflow DAG tasks: triggers schedule (evidence: `README.md`)
- Airflow DAG tasks → Scheduled producer: runs first (evidence: `dags/pipeline_dag.py`)
- Airflow DAG tasks → Scheduled consumer: runs second (evidence: `dags/pipeline_dag.py`)
- Airflow DAG tasks → Scheduled anomaly detector: runs third (evidence: `dags/pipeline_dag.py`)
- Scheduled producer → Kafka sales topic: publishes records (evidence: `dags/pipelines/producer.py`)
- Scheduled producer → Sales generation and direct load: generates records (evidence: `dags/pipelines/producer.py`)
- Scheduled consumer → Kafka sales topic: consumes records (evidence: `dags/pipelines/consumer.py`)
- Scheduled consumer → PostgreSQL sales table: appends sales (evidence: `dags/pipelines/consumer.py`)
- Scheduled anomaly detector → PostgreSQL sales table: reads sales (evidence: `dags/monitor/anomaly_detector.py`)
- Browser user → FastAPI dashboard and API: queries dashboard (evidence: `README.md`)
