# divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow architecture

> Architecture diagram of the GitHub repository divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow
- Repository: https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow

## Overview

#### Purpose and Entrypoints
This is a Snowflake ELT example: dbt transforms TPCH order data in Snowflake, while Apache Airflow schedules and executes the dbt workflow. The operational entrypoint is the Airflow DAG at `dbt-dag/dags/dbt_dag.py`. The standalone dbt project is rooted at `data_pipeline/dbt_project.yml`; a deployable copy is embedded under `dbt-dag/dags/dbt/data_pipeline/dbt_project.yml`.

#### Runtime and Deployment Boundary
Airflow is containerized through `dbt-dag/Dockerfile`, with Python/Airflow dependencies in `dbt-dag/requirements.txt` and dbt package requirements in `dbt-dag/packages.txt`. The DAG-local dbt project places transformation code where the Airflow runtime can invoke it. Snowflake is the external warehouse, including its sample TPCH dataset as the source system.

#### Source and Staging Layer
dbt declares TPCH source relations in `data_pipeline/models/staging/tpch_sources.yml`. Staging models normalize the primary orders and line-item inputs:
- `data_pipeline/models/staging/stg_tpch_orders.sql`
- `data_pipeline/models/staging/stg_tpch_line_items.sql`

This boundary separates Snowflake sample/source tables from internally modeled relations and establishes dbt lineage for downstream execution.

#### Transformation and Mart Layer
Order and line-item transformations progress from reusable intermediate models into an order fact mart:
- `data_pipeline/models/marts/int_order_items.sql`
- `data_pipeline/models/marts/int_order_items_summary.sql`
- `data_pipeline/models/marts/fct_orders.sql`

The expected flow is source orders/line items → staging models → item-level intermediate data → aggregated item summary → `fct_orders`. dbt dependency references determine model build order.

#### Shared Business Logic
Pricing/discount calculation is centralized as a dbt macro in `data_pipeline/macros/pricing.sql`, rather than duplicated across models. Models that require pricing logic can compile that macro into Snowflake SQL. The same macro is carried in the Airflow-executed project at `dbt-dag/dags/dbt/data_pipeline/macros/pricing.sql`.

#### Data Quality Gates
dbt applies schema/generic checks through `data_pipeline/models/marts/generic_tests.yml` and custom SQL assertions through:
- `data_pipeline/tests/fct_orders_date_valid.sql`
- `data_pipeline/tests/fct_orders_discount.sql`

These tests are a quality boundary around the final order mart, intended to fail dbt/Airflow execution when date or discount assumptions are violated.

#### Orchestration Flow
`dbt-dag/dags/dbt_dag.py` defines the Airflow control plane: it schedules the dbt project located beneath `dbt-dag/dags/dbt/data_pipeline`, invokes dbt work, and exposes run status through Airflow. The repository therefore has two copies of dbt assets: `data_pipeline/` is the development project, while `dbt-dag/dags/dbt/data_pipeline/` is the DAG-runtime payload; changes must remain synchronized unless deployment packaging is changed.

Main entry points: [`data_pipeline/models/marts/fct_orders.sql`](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/models/marts/fct_orders.sql) (Orders fact mart), [`data_pipeline/models/marts/int_order_items.sql`](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/models/marts/int_order_items.sql) (Order items), [`data_pipeline/models/staging/tpch_sources.yml`](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/models/staging/tpch_sources.yml) (TPCH source declarations), [`dbt-dag/Dockerfile`](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/dbt-dag/Dockerfile) (Airflow image)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_airflow["Airflow deployment"]
  node_dockerfile["Airflow image<br/>container build"]
  node_airflow_dependencies["Airflow dependencies<br/>Python requirements<br/>[requirements.txt]"]
  node_dbt_packages["dbt dependencies<br/>package requirements<br/>[packages.txt]"]
  node_dag["dbt workflow DAG<br/>Airflow DAG<br/>[dbt_dag.py]"]
end

subgraph group_development["dbt development project"]
  node_source_definitions["TPCH source declarations<br/>dbt sources<br/>[tpch_sources.yml]"]
  node_stg_orders["Staged orders<br/>dbt staging model"]
  node_stg_line_items["Staged line items<br/>dbt staging model"]
  node_pricing_macro{{"Pricing logic<br/>dbt macro<br/>[pricing.sql]"}}
  node_int_order_items["Order items<br/>dbt intermediate model"]
  node_int_item_summary["Item summary<br/>dbt intermediate model"]
  node_fct_orders[("Orders fact mart<br/>dbt mart model<br/>[fct_orders.sql]")]
  node_generic_tests["Mart schema tests<br/>dbt generic tests<br/>[generic_tests.yml]"]
  node_date_test["Order date assertion<br/>dbt SQL test"]
  node_discount_test["Discount assertion<br/>dbt SQL test"]
  node_dev_project["Development dbt project<br/>dbt project root<br/>[dbt_project.yml]"]
end

subgraph group_warehouse["Snowflake warehouse"]
  node_snowflake_tpch[("TPCH source tables<br/>Snowflake sample data")]
end

subgraph group_runtime_payload["DAG dbt payload"]
  node_runtime_project["Embedded dbt project<br/>DAG runtime payload<br/>[dbt_project.yml]"]
  node_runtime_pricing_macro{{"Embedded pricing logic<br/>dbt macro copy<br/>[pricing.sql]"}}
end

node_airflow_dependencies -->|"installed in"| node_dockerfile
node_dbt_packages -->|"installed in"| node_dockerfile
node_dockerfile -->|"runs"| node_dag
node_dag -->|"invokes"| node_runtime_project
node_dev_project -.->|"synchronized as"| node_runtime_project
node_pricing_macro -.->|"copied to"| node_runtime_pricing_macro
node_runtime_project -->|"includes"| node_runtime_pricing_macro
node_snowflake_tpch -->|"declared by"| node_source_definitions
node_source_definitions -->|"feeds"| node_stg_orders
node_source_definitions -->|"feeds"| node_stg_line_items
node_stg_orders -->|"builds"| node_int_order_items
node_stg_line_items -->|"builds"| node_int_order_items
node_pricing_macro -->|"compiled into"| node_int_order_items
node_int_order_items -->|"aggregates to"| node_int_item_summary
node_int_item_summary -->|"builds"| node_fct_orders
node_fct_orders -->|"validated by"| node_generic_tests
node_fct_orders -->|"validated by"| node_date_test
node_fct_orders -->|"validated by"| node_discount_test

click node_dockerfile "https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/dbt-dag/Dockerfile"
click node_airflow_dependencies "https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/dbt-dag/requirements.txt"
click node_dbt_packages "https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/dbt-dag/packages.txt"
click node_dag "https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/dbt-dag/dags/dbt_dag.py"
click node_source_definitions "https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/models/staging/tpch_sources.yml"
click node_stg_orders "https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/models/staging/stg_tpch_orders.sql"
click node_stg_line_items "https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/models/staging/stg_tpch_line_items.sql"
click node_pricing_macro "https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/macros/pricing.sql"
click node_int_order_items "https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/models/marts/int_order_items.sql"
click node_int_item_summary "https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/models/marts/int_order_items_summary.sql"
click node_fct_orders "https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/models/marts/fct_orders.sql"
click node_generic_tests "https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/models/marts/generic_tests.yml"
click node_date_test "https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/tests/fct_orders_date_valid.sql"
click node_discount_test "https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/tests/fct_orders_discount.sql"
click node_dev_project "https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/dbt_project.yml"
click node_runtime_project "https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/dbt-dag/dags/dbt/data_pipeline/dbt_project.yml"
click node_runtime_pricing_macro "https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/dbt-dag/dags/dbt/data_pipeline/macros/pricing.sql"

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_dockerfile,node_airflow_dependencies,node_dbt_packages,node_dag toneBlue
class node_source_definitions,node_stg_orders,node_stg_line_items,node_pricing_macro,node_int_order_items,node_int_item_summary,node_fct_orders,node_generic_tests,node_date_test,node_discount_test,node_dev_project toneAmber
class node_snowflake_tpch toneMint
class node_runtime_project,node_runtime_pricing_macro toneRose
```

## Components

### Airflow deployment

- [Airflow image](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/dbt-dag/Dockerfile): container build · `dbt-dag/Dockerfile`
- [Airflow dependencies](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/dbt-dag/requirements.txt): Python requirements · `dbt-dag/requirements.txt`
- [dbt dependencies](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/dbt-dag/packages.txt): package requirements · `dbt-dag/packages.txt`
- [dbt workflow DAG](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/dbt-dag/dags/dbt_dag.py): Airflow DAG · Schedules and runs the embedded dbt project. · `dbt-dag/dags/dbt_dag.py`

### dbt development project

- [TPCH source declarations](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/models/staging/tpch_sources.yml): dbt sources · `data_pipeline/models/staging/tpch_sources.yml`
- [Staged orders](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/models/staging/stg_tpch_orders.sql): dbt staging model · `data_pipeline/models/staging/stg_tpch_orders.sql`
- [Staged line items](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/models/staging/stg_tpch_line_items.sql): dbt staging model · `data_pipeline/models/staging/stg_tpch_line_items.sql`
- [Pricing logic](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/macros/pricing.sql): dbt macro · Centralizes pricing and discount calculation. · `data_pipeline/macros/pricing.sql`
- [Order items](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/models/marts/int_order_items.sql): dbt intermediate model · `data_pipeline/models/marts/int_order_items.sql`
- [Item summary](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/models/marts/int_order_items_summary.sql): dbt intermediate model · `data_pipeline/models/marts/int_order_items_summary.sql`
- [Orders fact mart](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/models/marts/fct_orders.sql): dbt mart model · `data_pipeline/models/marts/fct_orders.sql`
- [Mart schema tests](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/models/marts/generic_tests.yml): dbt generic tests · `data_pipeline/models/marts/generic_tests.yml`
- [Order date assertion](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/tests/fct_orders_date_valid.sql): dbt SQL test · `data_pipeline/tests/fct_orders_date_valid.sql`
- [Discount assertion](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/tests/fct_orders_discount.sql): dbt SQL test · `data_pipeline/tests/fct_orders_discount.sql`
- [Development dbt project](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/data_pipeline/dbt_project.yml): dbt project root · Source project maintained outside the Airflow runtime. · `data_pipeline/dbt_project.yml`

### Snowflake warehouse

- **TPCH source tables**: Snowflake sample data

### DAG dbt payload

- [Embedded dbt project](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/dbt-dag/dags/dbt/data_pipeline/dbt_project.yml): DAG runtime payload · Deployable copy invoked by Airflow. · `dbt-dag/dags/dbt/data_pipeline/dbt_project.yml`
- [Embedded pricing logic](https://github.com/divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow/blob/main/dbt-dag/dags/dbt/data_pipeline/macros/pricing.sql): dbt macro copy · `dbt-dag/dags/dbt/data_pipeline/macros/pricing.sql`

## Connections

- Airflow dependencies → Airflow image: installed in
- dbt dependencies → Airflow image: installed in
- Airflow image → dbt workflow DAG: runs
- dbt workflow DAG → Embedded dbt project: invokes
- Development dbt project → Embedded dbt project: synchronized as
- Pricing logic → Embedded pricing logic: copied to
- Embedded dbt project → Embedded pricing logic: includes
- TPCH source tables → TPCH source declarations: declared by
- TPCH source declarations → Staged orders: feeds
- TPCH source declarations → Staged line items: feeds
- Staged orders → Order items: builds
- Staged line items → Order items: builds
- Pricing logic → Order items: compiled into
- Order items → Item summary: aggregates to
- Item summary → Orders fact mart: builds
- Orders fact mart → Mart schema tests: validated by
- Orders fact mart → Order date assertion: validated by
- Orders fact mart → Discount assertion: validated by
