# amine-labscraft/walmart_streaming_flow architecture

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

- Interactive diagram: https://gitdiagram.com/amine-labscraft/walmart_streaming_flow
- Repository: https://github.com/amine-labscraft/walmart_streaming_flow

## Overview

#### Purpose and entry points
This is a retail streaming-to-lakehouse pipeline: continuously generated PostgreSQL orders are incrementally ingested into Databricks, transformed with dbt, certified by Airflow quality gates, and served to Power BI.

Operational entry points:
- Flask Order Pulse UI: `Walmart Data Engineering/Walmart dataset/generator_web_app.py`
- Transactional generator: `Walmart Data Engineering/Walmart dataset/continuous_order_generator.py`
- Source schema deployment/loading: `Walmart Data Engineering/deploy_raw_schema.py`, `Walmart Data Engineering/Walmart dataset/load_data.py`

Analytical entry point:
- Hourly Airflow DAG: `airflow/dags/orchestration.py`

#### 1. Transactional source and CDC boundary
Ghost PostgreSQL is the system of record, with normalized customers, stores, employees, products, orders, and order items. The generator selects valid active references and writes each order header plus 1–5 lines atomically; it does not invoke analytics services.

CDC is based on monotonic `change_version` for mutable order entities, assigned by source SQL sequence/triggers. This separates reliable technical ordering from business timestamps.
- `Walmart Data Engineering/Walmart dataset/ddl/walmart_schema.sql`
- `Walmart Data Engineering/Walmart dataset/ddl/001_streaming_source_upgrade.sql`
- `Walmart Data Engineering/Walmart dataset/continuous_order_generator.py`

#### 2. Independent operational control surface
The Flask application lets users start/stop continuous generation and choose customer mode. It is a local operational UI over the Python generator and PostgreSQL connection, not the platform orchestration layer.
- `Walmart Data Engineering/Walmart dataset/generator_web_app.py`
- `Walmart Data Engineering/Walmart dataset/templates/generator_index.html`
- `Walmart Data Engineering/Walmart dataset/static/generator_app.js`

#### 3. Airflow orchestration control plane
Airflow serializes the analytical lifecycle: trigger/poll a remote Databricks CDC job, clean dbt artifacts, build and test Silver Technical, build/test Silver Business, snapshot Gold dimensions, then build/test the Gold fact. A failure prevents downstream publication.

It runs containerized with Airflow 3/CeleryExecutor, Redis as broker, and PostgreSQL as Airflow metadata storage.
- `airflow/dags/orchestration.py`
- `airflow/docker-compose.yaml`
- `airflow/Dockerfile`

#### 4. Databricks ingestion and Bronze
Databricks owns ingestion from PostgreSQL into Delta Bronze tables. Airflow calls the configured Databricks job through its SDK and waits for success; the remote job is therefore a hard boundary outside this repository. Orders/items use version cursors, while reference entities use update timestamps.
- `airflow/dags/orchestration.py`
- `airflow/walmart_dbt/models/sources/sources.yml`
- `airflow/walmart_dbt/tools/migrate_ingestion_cursor.py`

#### 5. dbt medallion transformation graph
dbt reads `walmart.bronze`, incrementally merges six source-aligned entities into Silver Technical, then joins them into the Silver Business order-line table (`obt_b`). Gold derives reusable ephemeral projections, timestamp-SCD snapshots for dimensions, and a materialized fact.
- `airflow/walmart_dbt/models/silver_t/orders_t.sql`
- `airflow/walmart_dbt/models/silver_b/obt_b.sql`
- `airflow/walmart_dbt/models/gold/fact/fact_orders.sql`

#### 6. Gold contract and quality boundaries
`fact_orders` is at order-item grain; revenue and quantity are additive, while repeated order-header totals must not be summed. Five dbt snapshots retain historical dimension versions. dbt schema, relationship, reconciliation, and custom business tests gate promotion before BI refresh.
- `airflow/walmart_dbt/models/gold/fact/fact_orders.yml`
- `airflow/walmart_dbt/snapshots/dim_customers.yml`
- `airflow/walmart_dbt/tests/assert_fact_order_totals.sql`

#### 7. Serving and observability
Databricks SQL Warehouse serves Gold to Power BI. Monitoring is a separate Docker Compose stack using Prometheus, Grafana, Loki, Alloy, Blackbox, and a custom Walmart exporter; dashboards cover pipeline health, freshness/quality, generator activity, and platform status.
- `airflow/monitoring/docker-compose.monitoring.yml`
- `airflow/monitoring/exporters/walmart-exporter/app.py`
- `airflow/monitoring/grafana/dashboards/data-freshness-quality.json`

Main entry points: [`airflow/dags/orchestration.py`](https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/dags/orchestration.py) (Hourly analytical DAG), [`airflow/walmart_dbt/models/gold/fact/fact_orders.sql`](https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/walmart_dbt/models/gold/fact/fact_orders.sql) (fact_orders), [`Walmart Data Engineering/Walmart dataset/continuous_order_generator.py`](https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/Walmart%20Data%20Engineering/Walmart%20dataset/continuous_order_generator.py) (Order generator), [`airflow/walmart_dbt/models/silver_b/obt_b.sql`](https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/walmart_dbt/models/silver_b/obt_b.sql) (Silver Business OBT)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_source["Transactional source"]
  node_order_generator["Order generator<br/>Python generator"]
  node_source_schema["Source schema &amp; CDC<br/>PostgreSQL DDL"]
  node_postgres[("Ghost PostgreSQL<br/>system of record")]
end

subgraph group_control["Operational control"]
  node_generator_ui["Order Pulse UI<br/>Flask app"]
  node_airflow_dag["Hourly analytical DAG<br/>Airflow DAG<br/>[orchestration.py]"]
  node_airflow_runtime["Airflow Celery runtime<br/>container stack"]
  node_quality_gates["dbt quality gates<br/>tests &amp; reconciliation"]
end

subgraph group_lakehouse["Databricks lakehouse"]
  node_databricks_cdc{{"Remote CDC job<br/>Databricks job<br/>[orchestration.py]"}}
  node_ingestion_cursors["Ingestion cursors<br/>migration utility"]
  node_bronze[("Bronze tables<br/>Delta tables<br/>[sources.yml]")]
  node_silver_technical["Silver Technical<br/>incremental dbt models<br/>[orders_t.sql]"]
  node_silver_business["Silver Business OBT<br/>dbt order-line model<br/>[obt_b.sql]"]
  node_gold_dimensions[("Gold dimensions<br/>dbt SCD snapshots<br/>[dim_customers.yml]")]
  node_gold_fact[("fact_orders<br/>dbt Gold fact<br/>[fact_orders.sql]")]
end

subgraph group_serving["Serving &amp; monitoring"]
  node_sql_warehouse[("Databricks SQL Warehouse<br/>SQL serving")]
  node_power_bi["Power BI<br/>BI consumer"]
  node_monitoring["Observability stack<br/>Docker monitoring"]
  node_walmart_exporter["Walmart exporter<br/>custom metrics exporter<br/>[app.py]"]
end

node_generator_ui -->|"starts/stops"| node_order_generator
node_order_generator -->|"writes orders"| node_postgres
node_source_schema -->|"defines CDC"| node_postgres
node_airflow_runtime -->|"executes"| node_airflow_dag
node_airflow_dag -->|"triggers and polls"| node_databricks_cdc
node_postgres -->|"CDC source"| node_databricks_cdc
node_ingestion_cursors -.->|"cursor state"| node_databricks_cdc
node_databricks_cdc -->|"ingests"| node_bronze
node_bronze -->|"incremental merge"| node_silver_technical
node_silver_technical -->|"joins entities"| node_silver_business
node_silver_business -->|"snapshots dimensions"| node_gold_dimensions
node_silver_business -->|"builds fact"| node_gold_fact
node_airflow_dag -->|"runs after each stage"| node_quality_gates
node_quality_gates -->|"gates publication"| node_gold_fact
node_gold_dimensions -->|"dimension history"| node_gold_fact
node_gold_fact -->|"serves Gold"| node_sql_warehouse
node_sql_warehouse -->|"BI queries"| node_power_bi
node_walmart_exporter -->|"metrics"| node_monitoring
node_airflow_dag -.->|"pipeline telemetry"| node_walmart_exporter
node_order_generator -.->|"generator telemetry"| node_walmart_exporter

click node_generator_ui "https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/Walmart%20Data%20Engineering/Walmart%20dataset/generator_web_app.py"
click node_order_generator "https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/Walmart%20Data%20Engineering/Walmart%20dataset/continuous_order_generator.py"
click node_source_schema "https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/Walmart%20Data%20Engineering/Walmart%20dataset/ddl/001_streaming_source_upgrade.sql"
click node_airflow_dag "https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/dags/orchestration.py"
click node_airflow_runtime "https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/docker-compose.yaml"
click node_databricks_cdc "https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/dags/orchestration.py"
click node_ingestion_cursors "https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/walmart_dbt/tools/migrate_ingestion_cursor.py"
click node_bronze "https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/walmart_dbt/models/sources/sources.yml"
click node_silver_technical "https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/walmart_dbt/models/silver_t/orders_t.sql"
click node_silver_business "https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/walmart_dbt/models/silver_b/obt_b.sql"
click node_gold_dimensions "https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/walmart_dbt/snapshots/dim_customers.yml"
click node_gold_fact "https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/walmart_dbt/models/gold/fact/fact_orders.sql"
click node_quality_gates "https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/walmart_dbt/tests/assert_fact_order_totals.sql"
click node_monitoring "https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/monitoring/docker-compose.monitoring.yml"
click node_walmart_exporter "https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/monitoring/exporters/walmart-exporter/app.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_order_generator,node_source_schema,node_postgres toneBlue
class node_generator_ui,node_airflow_dag,node_airflow_runtime,node_quality_gates toneAmber
class node_databricks_cdc,node_ingestion_cursors,node_bronze,node_silver_technical,node_silver_business,node_gold_dimensions,node_gold_fact toneMint
class node_sql_warehouse,node_power_bi,node_monitoring,node_walmart_exporter toneRose
```

## Components

### Transactional source

- [Order generator](https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/Walmart%20Data%20Engineering/Walmart%20dataset/continuous_order_generator.py): Python generator · Atomically writes order headers and 1–5 order lines. · `Walmart Data Engineering/Walmart dataset/continuous_order_generator.py`
- [Source schema & CDC](https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/Walmart%20Data%20Engineering/Walmart%20dataset/ddl/001_streaming_source_upgrade.sql): PostgreSQL DDL · Sequences and triggers assign monotonic change versions. · `Walmart Data Engineering/Walmart dataset/ddl/001_streaming_source_upgrade.sql`
- **Ghost PostgreSQL**: system of record · Normalized retail entities and transactional orders.

### Operational control

- [Order Pulse UI](https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/Walmart%20Data%20Engineering/Walmart%20dataset/generator_web_app.py): Flask app · Local controls for generator state and customer mode. · `Walmart Data Engineering/Walmart dataset/generator_web_app.py`
- [Hourly analytical DAG](https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/dags/orchestration.py): Airflow DAG · Serializes CDC, dbt builds, tests, snapshots, and fact publication. · `airflow/dags/orchestration.py`
- [Airflow Celery runtime](https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/docker-compose.yaml): container stack · CeleryExecutor with Redis broker and metadata PostgreSQL. · `airflow/docker-compose.yaml`
- [dbt quality gates](https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/walmart_dbt/tests/assert_fact_order_totals.sql): tests & reconciliation · Schema, relationship, business, and order-total checks gate promotion. · `airflow/walmart_dbt/tests/assert_fact_order_totals.sql`

### Databricks lakehouse

- [Remote CDC job](https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/dags/orchestration.py): Databricks job · External job triggered and polled by Airflow. · `airflow/dags/orchestration.py`
- [Ingestion cursors](https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/walmart_dbt/tools/migrate_ingestion_cursor.py): migration utility · Version cursors for orders/items and timestamp cursors for references. · `airflow/walmart_dbt/tools/migrate_ingestion_cursor.py`
- [Bronze tables](https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/walmart_dbt/models/sources/sources.yml): Delta tables · Raw PostgreSQL entities in walmart.bronze. · `airflow/walmart_dbt/models/sources/sources.yml`
- [Silver Technical](https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/walmart_dbt/models/silver_t/orders_t.sql): incremental dbt models · Six source-aligned entities merged from Bronze. · `airflow/walmart_dbt/models/silver_t/orders_t.sql`
- [Silver Business OBT](https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/walmart_dbt/models/silver_b/obt_b.sql): dbt order-line model · Joined business order-line table. · `airflow/walmart_dbt/models/silver_b/obt_b.sql`
- [Gold dimensions](https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/walmart_dbt/snapshots/dim_customers.yml): dbt SCD snapshots · Five timestamp-SCD dimension histories. · `airflow/walmart_dbt/snapshots/dim_customers.yml`
- [fact_orders](https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/walmart_dbt/models/gold/fact/fact_orders.sql): dbt Gold fact · Materialized at order-item grain. · `airflow/walmart_dbt/models/gold/fact/fact_orders.sql`

### Serving & monitoring

- **Databricks SQL Warehouse**: SQL serving
- **Power BI**: BI consumer
- [Observability stack](https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/monitoring/docker-compose.monitoring.yml): Docker monitoring · Prometheus, Grafana, Loki, Alloy, Blackbox, and custom exporter. · `airflow/monitoring/docker-compose.monitoring.yml`
- [Walmart exporter](https://github.com/amine-labscraft/walmart_streaming_flow/blob/main/airflow/monitoring/exporters/walmart-exporter/app.py): custom metrics exporter · Exposes pipeline, freshness, quality, and generator metrics. · `airflow/monitoring/exporters/walmart-exporter/app.py`

## Connections

- Order Pulse UI → Order generator: starts/stops
- Order generator → Ghost PostgreSQL: writes orders
- Source schema & CDC → Ghost PostgreSQL: defines CDC
- Airflow Celery runtime → Hourly analytical DAG: executes
- Hourly analytical DAG → Remote CDC job: triggers and polls
- Ghost PostgreSQL → Remote CDC job: CDC source
- Ingestion cursors → Remote CDC job: cursor state
- Remote CDC job → Bronze tables: ingests
- Bronze tables → Silver Technical: incremental merge
- Silver Technical → Silver Business OBT: joins entities
- Silver Business OBT → Gold dimensions: snapshots dimensions
- Silver Business OBT → fact_orders: builds fact
- Hourly analytical DAG → dbt quality gates: runs after each stage
- dbt quality gates → fact_orders: gates publication
- Gold dimensions → fact_orders: dimension history
- fact_orders → Databricks SQL Warehouse: serves Gold
- Databricks SQL Warehouse → Power BI: BI queries
- Walmart exporter → Observability stack: metrics
- Hourly analytical DAG → Walmart exporter: pipeline telemetry
- Order generator → Walmart exporter: generator telemetry
