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.
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.
βββββββββββββββββββββββββββ βββββββββββββββββββββββββββ βββββββββββββββββββββββββββ
β 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) β
βββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββ
| 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 |
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
- 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.
- Standardizing column casing (
- 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.
- 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.
- 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.
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 ServerTRY_CONVERTlogic.standardize_phone(column_name): Normalizes phone strings into standard US format+1 (AAA) BBB-CCCCusing 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 is enforced at every layer using generic and custom singular tests:
- Primary & Foreign Key Integrity:
uniqueandnot_nullconstraints 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.
- Python 3.11+ installed.
- Docker & Docker Compose installed and running.
- ODBC Driver 18 for SQL Server installed on your operating system.
# 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.txtCopy the example environment file and connection profile:
cp .env.example .env
mkdir -p ~/.dbt
cp profiles.example.yml ~/.dbt/profiles.ymlEdit ~/.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: truedocker compose up -d
docker compose ps # Verify container is healthy# 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 serveThe 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. β
βββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
We welcome contributions! Please adhere to the following workflow:
- Fork the repository and create your feature branch (
git checkout -b feature/amazing-feature). - Follow SQL naming conventions (
snake_case) and model structure guidance. - Ensure all tests (
dbt test) pass before opening a PR. - Review CONTRIBUTING.md for full submission guidelines.
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