# mamatsa/redshift-thesis architecture

> Architecture diagram of the GitHub repository mamatsa/redshift-thesis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mamatsa/redshift-thesis
- Repository: https://github.com/mamatsa/redshift-thesis

## Overview

1. **Project type and runtime**
   - This is a **dbt analytics transformation repo**, not an application service.
   - The main execution engine is **dbt**, which runs SQL models against a data warehouse. The warehouse itself is not specified in the repo, but dbt is the central transformation layer.

2. **End-to-end data flow**
   - The repo supports a pipeline that starts with **raw data loaded from S3**, passes through **raw warehouse tables**, then into **dbt staging models**, and finally into a **business mart**.
   - In short: **S3 → raw tables → staging models → marts → tests**.

3. **Ingestion / landing boundary**
   - `sql/create_raw_tables.sql` defines the warehouse-side raw tables.
   - `sql/load_raw_from_s3.sql` handles loading data from **S3** into those raw tables.
   - These scripts sit outside dbt models, so they represent the boundary where external data is first materialized into the warehouse.

4. **Source definition layer**
   - `models/staging/sources.yml` declares the upstream raw tables as dbt sources.
   - This is the contract between the ingestion layer and dbt transformations: dbt reads from the raw tables, but does not own their creation/loading.

5. **Staging layer**
   - `models/staging/stg_customers.sql`, `stg_orders.sql`, and `stg_products.sql` are the normalized staging models.
   - This layer likely cleans, renames, and standardizes raw source fields so downstream logic can depend on consistent shapes.
   - `models/staging/schema.yml` contains model metadata and probably staging-level tests/documentation.

6. **Mart / business logic layer**
   - `models/marts/mart_sales_by_country.sql` is the curated downstream output.
   - This is the presentation/analytics layer where business-specific aggregations are built from the staging models.
   - The naming suggests a reporting-oriented fact/aggregate by geography.

7. **Data quality and assertions**
   - `tests/assert_positive_product_cost.sql` and `tests/assert_positive_product_price.sql.sql` are custom dbt tests.
   - These enforce business rules on product attributes, likely preventing invalid negative or zero values from propagating.
   - The repository relies on both built-in dbt testing conventions and custom SQL assertions.

8. **Project configuration**
   - `dbt_project.yml` defines the dbt project structure, model paths, and build behavior.
   - This file is the top-level configuration for how dbt compiles and runs the models in `models/`.

9. **CI/CD boundary**
   - `buildspec-ci.yml` and `buildspec-deploy.yml` indicate the project is built and deployed through a CI/CD system, most likely **AWS CodeBuild**.
   - CI likely runs dbt validation/tests, while the deploy spec likely handles production execution or artifact deployment.
   - This means operational control is separated from transformation logic.

10. **Repository organization**
   - `models/` contains the transformation graph.
   - `sql/` contains warehouse setup and load scripts for raw ingestion.
   - `tests/` contains custom data validation logic.
   - This separation is important architecturally: **ingestion SQL, dbt transformations, and tests are intentionally kept in different boundaries**.

11. **What an architecture diagram should emphasize**
   - Draw the external data source as **S3** feeding ingestion SQL.
   - Show **raw warehouse tables** as the first persistent landing zone.
   - Show dbt reading those raw tables through declared sources, then producing **staging models** and a **sales-by-country mart**.
   - Add a parallel path for **tests/quality checks** running against staged or mart data.
   - Put CI/CD around the whole repo, since the buildspec files suggest automated execution and deployment.

Main entry points: [`models/staging/stg_products.sql`](https://github.com/mamatsa/redshift-thesis/blob/main/models/staging/stg_products.sql) (Products stg), [`models/staging/sources.yml`](https://github.com/mamatsa/redshift-thesis/blob/main/models/staging/sources.yml) (Sources), [`models/staging/schema.yml`](https://github.com/mamatsa/redshift-thesis/blob/main/models/staging/schema.yml) (Staging schema), [`buildspec-ci.yml`](https://github.com/mamatsa/redshift-thesis/blob/main/buildspec-ci.yml) (CI build)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ops["Operations"]
  node_dbt_project["dbt project<br/>dbt config<br/>[dbt_project.yml]"]
  node_build_ci["CI build<br/>buildspec<br/>[buildspec-ci.yml]"]
  node_build_deploy["Deploy build<br/>buildspec"]
end

subgraph group_ingest["Ingestion"]
  node_s3[("S3<br/>external source")]
  node_load_raw["Load raw<br/>sql load"]
  node_create_raw[("Raw tables<br/>sql ddl")]
  node_raw_tables[("Raw layer<br/>warehouse tables")]
end

subgraph group_dbt["dbt Transformations"]
  node_sources_yml["Sources<br/>[sources.yml]"]
  node_stg_customers["Customers stg<br/>dbt model<br/>[stg_customers.sql]"]
  node_stg_orders["Orders stg<br/>dbt model<br/>[stg_orders.sql]"]
  node_stg_products["Products stg<br/>dbt model<br/>[stg_products.sql]"]
  node_staging_schema["Staging schema<br/>dbt tests/docs<br/>[schema.yml]"]
  node_mart_sales["Sales mart<br/>dbt mart"]
  node_mart_tests["Mart checks<br/>dbt tests/docs"]
  node_pos_cost["Cost check<br/>custom test"]
  node_pos_price["Price check<br/>custom test"]
end

node_s3 -->|"files"| node_load_raw
node_load_raw -->|"populates"| node_create_raw
node_create_raw -->|"defines"| node_raw_tables
node_raw_tables -->|"exposed as"| node_sources_yml
node_dbt_project -->|"governs"| node_sources_yml
node_sources_yml -->|"feeds"| node_stg_customers
node_sources_yml -->|"feeds"| node_stg_orders
node_sources_yml -->|"feeds"| node_stg_products
node_stg_customers -->|"documented by"| node_staging_schema
node_stg_orders -->|"documented by"| node_staging_schema
node_stg_products -->|"documented by"| node_staging_schema
node_stg_customers -->|"contributes"| node_mart_sales
node_stg_orders -->|"contributes"| node_mart_sales
node_stg_products -->|"contributes"| node_mart_sales
node_stg_products -->|"checked by"| node_pos_cost
node_stg_products -->|"checked by"| node_pos_price
node_build_ci -->|"runs"| node_dbt_project
node_build_ci -->|"runs"| node_staging_schema
node_build_ci -->|"runs"| node_mart_tests
node_build_deploy -->|"runs"| node_dbt_project

click node_load_raw "https://github.com/mamatsa/redshift-thesis/blob/main/sql/load_raw_from_s3.sql"
click node_create_raw "https://github.com/mamatsa/redshift-thesis/blob/main/sql/create_raw_tables.sql"
click node_dbt_project "https://github.com/mamatsa/redshift-thesis/blob/main/dbt_project.yml"
click node_build_ci "https://github.com/mamatsa/redshift-thesis/blob/main/buildspec-ci.yml"
click node_build_deploy "https://github.com/mamatsa/redshift-thesis/blob/main/buildspec-deploy.yml"
click node_sources_yml "https://github.com/mamatsa/redshift-thesis/blob/main/models/staging/sources.yml"
click node_stg_customers "https://github.com/mamatsa/redshift-thesis/blob/main/models/staging/stg_customers.sql"
click node_stg_orders "https://github.com/mamatsa/redshift-thesis/blob/main/models/staging/stg_orders.sql"
click node_stg_products "https://github.com/mamatsa/redshift-thesis/blob/main/models/staging/stg_products.sql"
click node_staging_schema "https://github.com/mamatsa/redshift-thesis/blob/main/models/staging/schema.yml"
click node_mart_sales "https://github.com/mamatsa/redshift-thesis/blob/main/models/marts/mart_sales_by_country.sql"
click node_pos_cost "https://github.com/mamatsa/redshift-thesis/blob/main/tests/assert_positive_product_cost.sql"
click node_pos_price "https://github.com/mamatsa/redshift-thesis/blob/main/tests/assert_positive_product_price.sql.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_dbt_project,node_build_ci,node_build_deploy toneBlue
class node_s3,node_load_raw,node_create_raw,node_raw_tables toneAmber
class node_sources_yml,node_stg_customers,node_stg_orders,node_stg_products,node_staging_schema,node_mart_sales,node_mart_tests,node_pos_cost,node_pos_price toneMint
```

## Components

### Operations

CI/CD and project configuration

- [dbt project](https://github.com/mamatsa/redshift-thesis/blob/main/dbt_project.yml): dbt config · Defines project structure and build behavior · `dbt_project.yml`
- [CI build](https://github.com/mamatsa/redshift-thesis/blob/main/buildspec-ci.yml): buildspec · Automated validation and test execution · `buildspec-ci.yml`
- [Deploy build](https://github.com/mamatsa/redshift-thesis/blob/main/buildspec-deploy.yml): buildspec · Production build or deployment automation · `buildspec-deploy.yml`

### Ingestion

Warehouse landing and load scripts

- **S3**: external source · Raw object storage landing source
- [Load raw](https://github.com/mamatsa/redshift-thesis/blob/main/sql/load_raw_from_s3.sql): sql load · Loads files from S3 into warehouse raw tables · `sql/load_raw_from_s3.sql`
- [Raw tables](https://github.com/mamatsa/redshift-thesis/blob/main/sql/create_raw_tables.sql): sql ddl · Creates warehouse-side raw landing tables · `sql/create_raw_tables.sql`
- **Raw layer**: warehouse tables · Persistent landing zone before dbt

### dbt Transformations

Sources, staging, and marts

- [Sources](https://github.com/mamatsa/redshift-thesis/blob/main/models/staging/sources.yml): dbt sources · Declares raw tables as dbt sources · `models/staging/sources.yml`
- [Customers stg](https://github.com/mamatsa/redshift-thesis/blob/main/models/staging/stg_customers.sql): dbt model · Normalizes customer attributes · `models/staging/stg_customers.sql`
- [Orders stg](https://github.com/mamatsa/redshift-thesis/blob/main/models/staging/stg_orders.sql): dbt model · Normalizes order attributes · `models/staging/stg_orders.sql`
- [Products stg](https://github.com/mamatsa/redshift-thesis/blob/main/models/staging/stg_products.sql): dbt model · Normalizes product attributes · `models/staging/stg_products.sql`
- [Staging schema](https://github.com/mamatsa/redshift-thesis/blob/main/models/staging/schema.yml): dbt tests/docs · Model metadata, docs, and schema tests · `models/staging/schema.yml`
- [Sales mart](https://github.com/mamatsa/redshift-thesis/blob/main/models/marts/mart_sales_by_country.sql): dbt mart · Business aggregate by country · `models/marts/mart_sales_by_country.sql`
- **Mart checks**: dbt tests/docs · Assertions and metadata for downstream models
- [Cost check](https://github.com/mamatsa/redshift-thesis/blob/main/tests/assert_positive_product_cost.sql): custom test · Asserts product cost is positive · `tests/assert_positive_product_cost.sql`
- [Price check](https://github.com/mamatsa/redshift-thesis/blob/main/tests/assert_positive_product_price.sql.sql): custom test · Asserts product price is positive · `tests/assert_positive_product_price.sql.sql`

## Connections

- S3 → Load raw: files · Raw data is pulled from S3
- Load raw → Raw tables: populates · Load script targets warehouse raw tables
- Raw tables → Raw layer: defines · Warehouse tables form the landing layer
- Raw layer → Sources: exposed as · Raw tables are declared as dbt sources
- dbt project → Sources: governs · Project config controls dbt parsing and structure
- Sources → Customers stg: feeds · Staging models read from declared sources
- Sources → Orders stg: feeds · Staging models read from declared sources
- Sources → Products stg: feeds · Staging models read from declared sources
- Customers stg → Staging schema: documented by · Schema file holds staging metadata and tests
- Orders stg → Staging schema: documented by · Schema file holds staging metadata and tests
- Products stg → Staging schema: documented by · Schema file holds staging metadata and tests
- Customers stg → Sales mart: contributes · Customer dimensions support the sales mart
- Orders stg → Sales mart: contributes · Order facts feed the sales mart
- Products stg → Sales mart: contributes · Product attributes feed the sales mart
- Products stg → Cost check: checked by · Custom assertion validates product cost
- Products stg → Price check: checked by · Custom assertion validates product price
- CI build → dbt project: runs · CI executes dbt project validation and tests
- CI build → Staging schema: runs · CI evaluates staging checks
- CI build → Mart checks: runs · CI evaluates downstream checks
- Deploy build → dbt project: runs · Deploy automation uses the dbt project
