Skip to content

Latest commit

Β 

History

95 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›’ Retail Analytics Engineering Platform

dbt Core dbt-sqlserver SQL Server Python Docker License

An end-to-end, enterprise-grade Analytics Engineering Platform leveraging dbt (data build tool) and Microsoft SQL Server 2022. This project models a multi-domain retail business ecosystemβ€”covering Customers, Transactions, Products, Employees, Stores, Inventory, Returns, and Reviewsβ€”following industry standard Medallion Architecture (Bronze β†’ Silver β†’ Gold) and Kimball Dimensional Modeling best practices.


πŸ—οΈ High-Level Architecture & Pipeline

The platform ingests raw operational data (CSV files loaded into SQL Server), applies automated data cleaning, enforces strict schema & business logic validations, and structures data into analytical Star Schema models optimized for BI platforms (PowerBI, Tableau, Superset) and executive dashboards.

dbt Medallion Architecture

Medallion Architecture Breakdown

 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚   BRONZE (Staging)      β”‚      β”‚   SILVER (Intermediate) β”‚      β”‚      GOLD (Marts)       β”‚
 β”‚   `stg_*` (Views)       β”œβ”€β”€β”€β”€β”€β–Ίβ”‚   `int_*` (Tables)      β”œβ”€β”€β”€β”€β”€β–Ίβ”‚   `dim_*` / `fct_*`     β”‚
 β”‚  Source Cleaning &      β”‚      β”‚   Business Logic &      β”‚      β”‚   Star Schema for BI &  β”‚
 β”‚  Standardization        β”‚      β”‚   Domain Aggregations   β”‚      β”‚   Analytical Reporting  β”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                           DATA PIPELINE DAG                                           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ BRONZE LAYER (Staging)          β”‚ SILVER LAYER (Intermediate)      β”‚ GOLD LAYER (Marts)               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ stg_customers                   β”‚ int_customer_location            β”‚ dim_customers                    β”‚
β”‚                                 β”‚ int_customer_profile             β”‚                                  β”‚
β”‚                                 β”‚ int_customer_segmentation        β”‚                                  β”‚
β”‚                                 β”‚ int_customers_contact            β”‚                                  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ stg_transactions                β”‚ int_transaction_financial        β”‚ fct_transactions (Planned)       β”‚
β”‚                                 β”‚ int_transaction_fulfillment      β”‚                                  β”‚
β”‚                                 β”‚ int_transaction_order            β”‚                                  β”‚
β”‚                                 β”‚ int_transaction_status           β”‚                                  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ stg_products                    β”‚ Product aggregations & logic     β”‚ dim_products                     β”‚
β”‚ stg_employees                   β”‚ Employee hierarchy & logic       β”‚ dim_employees                    β”‚
β”‚ stg_stores                      β”‚ Store performance & mapping      β”‚ dim_stores                       β”‚
β”‚ stg_inventory                   β”‚ Stock movement aggregations      β”‚ dim_inventory                    β”‚
β”‚ stg_returns                     β”‚ Return reconciliation            β”‚ fct_returns (Planned)            β”‚
β”‚ stg_reviews                     β”‚ Review sentiment & metrics       β”‚ fct_reviews (Planned)            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Tech Stack & Key Components

Component Technology Version Description
Transformation Engine dbt-core 1.11.11 Core dbt framework for modular SQL models
Database Adapter dbt-sqlserver 1.10.0 Microsoft SQL Server adapter plugin for dbt
Database Engine MS SQL Server 2022 2022-latest Containerized relational OLAP/OLTP engine
Language Runtime Python 3.11+ CLI tools, package manager, and orchestration scripts
Containerization Docker & Compose v2+ Environment isolated local SQL Server container
CI/CD Orchestration GitHub Actions Workflows Automated testing, linting, parsing & deployment

πŸ“‚ Project Structure

dbt-analytics-engineering/
β”œβ”€β”€ .github/
β”‚   β”œβ”€β”€ profiles/
β”‚   β”‚   └── profiles.yml           # CI dbt profile configuration
β”‚   └── workflows/
β”‚       β”œβ”€β”€ dbt-ci.yml             # Pull Request validation (Lint, compile, run, test)
β”‚       β”œβ”€β”€ dbt-cd.yml             # CD deployment pipeline to production warehouse
β”‚       └── dbt-docs.yml           # Automated dbt documentation site publishing
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ staging/                   # Bronze Layer (Raw cleaning, renaming, defensive casts)
β”‚   β”‚   β”œβ”€β”€ Customers/             # stg_customers.sql
β”‚   β”‚   β”œβ”€β”€ Employees/             # stg_employees.sql
β”‚   β”‚   β”œβ”€β”€ Inventory/             # stg_inventory.sql
β”‚   β”‚   β”œβ”€β”€ Products/              # stg_products.sql
β”‚   β”‚   β”œβ”€β”€ Returns/               # stg_returns.sql
β”‚   β”‚   β”œβ”€β”€ Reviews/               # stg_reviews.sql
β”‚   β”‚   β”œβ”€β”€ Stores/                # stg_stores.sql
β”‚   β”‚   β”œβ”€β”€ Transactions/          # stg_transactions.sql
β”‚   β”‚   β”œβ”€β”€ _stg__retail__models.yml   # Staging model definitions, descriptions & tests
β”‚   β”‚   └── _stg__retail__sources.yml  # Raw source metadata definitions
β”‚   β”‚
β”‚   β”œβ”€β”€ intermediate/              # Silver Layer (Business logic, joins, aggregations)
β”‚   β”‚   β”œβ”€β”€ Customers/             # int_customer_location, profile, segmentation, contact
β”‚   β”‚   β”œβ”€β”€ Transactions/          # int_transaction_financial, fulfillment, order, status
β”‚   β”‚   β”œβ”€β”€ Employees/
β”‚   β”‚   β”œβ”€β”€ Inventory/
β”‚   β”‚   β”œβ”€β”€ Products/
β”‚   β”‚   β”œβ”€β”€ Returns/
β”‚   β”‚   β”œβ”€β”€ Reviews/
β”‚   β”‚   └── Stores/
β”‚   β”‚
β”‚   └── marts/                     # Gold Layer (Dimensional Kimball Star Schema)
β”‚       └── core/
β”‚           └── dimensions/        # Conformed Dimensions (dim_customers, dim_products, etc.)
β”‚               β”œβ”€β”€ dim_customers.sql
β”‚               β”œβ”€β”€ dim_employees.sql
β”‚               β”œβ”€β”€ dim_inventory.sql
β”‚               β”œβ”€β”€ dim_products.sql
β”‚               β”œβ”€β”€ dim_stores.sql
β”‚               └── _dim_models.yml
β”‚
β”œβ”€β”€ macros/                        # Reusable Jinja/SQL macro utilities
β”‚   β”œβ”€β”€ standardize_date.sql      # Multi-format pattern-aware date parser
β”‚   β”œβ”€β”€ standardize_phone.sql     # US phone format standardizer +1 (AAA) BBB-CCCC
β”‚   └── trim_lower.sql            # String trimming & lowercase normalization
β”‚
β”œβ”€β”€ snapshots/                     # SCD Type 2 tracking
β”‚   └── inventory_snapshot.sql    # Historical inventory snapshot tracking
β”‚
β”œβ”€β”€ seeds/                         # Static reference data (CSVs)
β”œβ”€β”€ tests/                         # Data Quality Tests (Singular & Generic)
β”œβ”€β”€ analyses/                      # Ad-hoc exploratory SQL queries
β”œβ”€β”€ scripts/                       # Database initialization & local dev helpers
β”‚   β”œβ”€β”€ setup-local-dev.sh        # Automated local setup script
β”‚   β”œβ”€β”€ wait_for_sqlserver.sh     # Health check wrapper script
β”‚   └── ci-init-db.sql            # Initial schema setup script for SQL Server
β”‚
β”œβ”€β”€ dbt_project.yml                # Core dbt project settings & materialization rules
β”œβ”€β”€ packages.yml                   # Dependencies (dbt_utils, dbt_expectations, etc.)
β”œβ”€β”€ profiles.example.yml           # Connection profile template
β”œβ”€β”€ docker-compose.yml             # Dockerized SQL Server setup
β”œβ”€β”€ requirements.txt               # Python package dependencies
β”œβ”€β”€ technical_design_document.md   # Architectural design document (ADD)
└── README.md                      # Project documentation

🎯 Data Modeling & Layering Strategy

1. πŸ₯‰ Staging Layer (Bronze)

  • Materialization: view (tags: ["staging", "bronze"])
  • Naming Convention: stg_<entity>
  • Objective: Clean raw source attributes without altering core business definitions.
  • Operations:
    • Standardizing column casing (snake_case).
    • Trimming leading/trailing whitespace.
    • Applying multi-format date parsing (ISO 8601 YYYY-MM-DD).
    • Formatting phone numbers into canonical U.S. formats (+1 (AAA) BBB-CCCC).
    • Defensive type-casting and handling missing or malformed values.

2. πŸ₯ˆ Intermediate Layer (Silver)

  • Materialization: table (tags: ["intermediate", "silver"])
  • Naming Convention: int_<domain>_<entity>
  • Objective: Implement domain business logic, complex joins, and reusable transformations.
  • Domains Covered:
    • Customers: Profile aggregation, contact info cleaning, geography/location standardization, customer segmentation rules (Bronze/Silver/Gold/Platinum).
    • Transactions: Order line handling, financial calculation reconciliations (tax, discounts, line totals), status mapping, fulfillment metrics.
    • Inventory, Products, Stores, Employees: Cross-entity mapping, tenure/compensation standardization.

3. πŸ₯‡ Marts Layer (Gold)

  • Materialization: table (tags: ["marts", "gold"])
  • Naming Convention: dim_<entity> / fct_<entity>
  • Objective: Expose analytics-ready Star Schema facts and dimensions optimized for BI consumption.
  • Core Models:
    • dim_customers: Unified conformed customer dimension.
    • dim_products: Comprehensive product catalog dimension.
    • dim_stores: Retail store location and formatting dimension.
    • dim_employees: Staff organizational hierarchy dimension.
    • dim_inventory: Current stock levels and snapshot metrics.

4. πŸ•°οΈ Snapshots (SCD Type 2)

  • Strategy: Capturing historical state changes over time using dbt snapshots (snapshots/inventory_snapshot.sql). Allows historical tracking of stock quantity variations and inventory valuation over time.

βš™οΈ Custom Macros & Data Quality Governance

Custom Utility Macros

  • standardize_date(column_name): Handles mixed date formats (e.g., YYYY-MM-DD, MM/DD/YYYY, DD-MM-YYYY, text month names) using conditional SQL Server TRY_CONVERT logic.
  • standardize_phone(column_name): Normalizes phone strings into standard US format +1 (AAA) BBB-CCCC using regex pattern parsing and string manipulation.
  • trim_lower(column_name): Strips whitespace and forces string fields to lowercase for predictable key joins and comparisons.

Data Quality & Testing Framework

Data quality is enforced at every layer using generic and custom singular tests:

  • Primary & Foreign Key Integrity: unique and not_null constraints on all primary identifiers (customer_id, transaction_id, product_id, employee_id, store_id).
  • Domain Validations: Accepted values testing for active flags, gender categories, and status codes.
  • Financial Validation: Non-negative checks on prices, salaries, quantities, and line item totals.

πŸš€ Quick Start Guide

1. Prerequisites

  • Python 3.11+ installed.
  • Docker & Docker Compose installed and running.
  • ODBC Driver 18 for SQL Server installed on your operating system.

2. Setup Virtual Environment & Install Dependencies

# Clone repository
git clone https://github.com/<your-org>/dbt-analytics-engineering.git
cd dbt-analytics-engineering

# Create and activate Python virtual environment
python3 -m venv .venv
source .venv/bin/activate    # On Windows: .venv\Scripts\activate

# Install requirements
pip install -r requirements.txt

3. Configure Database Credentials

Copy the example environment file and connection profile:

cp .env.example .env
mkdir -p ~/.dbt
cp profiles.example.yml ~/.dbt/profiles.yml

Edit ~/.dbt/profiles.yml or set environment variables in your .env:

dbt_analytics_engineering:
  target: dev
  outputs:
    dev:
      type: sqlserver
      driver: 'ODBC Driver 18 for SQL Server'
      server: localhost
      port: 1433
      database: dbt_db
      schema: dbo
      user: sa
      password: 'YourStrong!Password123'
      trust_cert: true

4. Start Local SQL Server (Docker Container)

docker compose up -d
docker compose ps   # Verify container is healthy

5. Execute dbt Pipeline

# Install external package dependencies (dbt_utils, etc.)
dbt deps

# Verify connection to SQL Server database
dbt debug

# Compile models
dbt compile

# Run transformations across all layers
dbt run

# Execute data quality tests
dbt test

# Generate and serve interactively dbt documentation & lineage DAG
dbt docs generate
dbt docs serve

πŸ”„ CI/CD Automation & GitHub Actions

The repository includes enterprise CI/CD workflows under .github/workflows/:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                            GITHUB ACTIONS WORKFLOWS                         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ `dbt-ci.yml`      β”‚ Runs on every Pull Request to `main`.                   β”‚
β”‚                   β”‚ 1. Lints SQL and validates project parsing (`dbt parse`)β”‚
β”‚                   β”‚ 2. Spins up ephemeral SQL Server docker container       β”‚
β”‚                   β”‚ 3. Executes `dbt run` and `dbt test`                    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ `dbt-cd.yml`      β”‚ Triggered on pushes to `main`. Deploys updated models   β”‚
β”‚                   β”‚ and snapshots directly to the production warehouse.     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ `dbt-docs.yml`    β”‚ Automatically compiles and deploys static dbt Docs &    β”‚
β”‚                   β”‚ DAG Lineage visualizer to GitHub Pages.                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🀝 Contributing

We welcome contributions! Please adhere to the following workflow:

  1. Fork the repository and create your feature branch (git checkout -b feature/amazing-feature).
  2. Follow SQL naming conventions (snake_case) and model structure guidance.
  3. Ensure all tests (dbt test) pass before opening a PR.
  4. Review CONTRIBUTING.md for full submission guidelines.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Developed and Maintained by Ritik β€’ Built with ❀️ using dbt Core & SQL Server

About

primary purpose : Learn dbt deeply, cover advanced dbt features, and develop strong critical thinking and problem-solving abilities.

Resources

Code of conduct

Contributing

Security policy

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages