Project guide

Project Guide | Lakehouse Contract Lab

Free lakehouse contract checklist for medallion quality gates and rejected-row review. This guide organizes the repository's original implementation notes for data engineers and platform governance owners.

Reviewed 2026-07-28. This page is derived from checked-in repository evidence and links back to its source.

Live Demo

A runnable Spark + Delta Lake medallion pipeline demo that enforces data contracts at layer boundaries, applies declarative quality gates, and frames governed KPI export paths for Snowflake and Databricks Unity Catalog review. Built as a working reference implementation for contract-first data engineering with synthetic fixture data.

---

System Overview

A contract-first data lab that turns data quality from a slide into a repeatable pipeline and review artifact.

AreaDetails
UsersData platform teams, BI teams, analytics engineers, and migration leaders.
Technical pathValidate the demo, README, architecture notes, and quality gate before deeper workflow review.
System scopeSpark/Delta-style medallion pipeline, quality gates, warehouse export, contracts, and architecture-pack framing.
Operating boundaryFixture data proves behavior; production use needs source-system contracts, ownership, lineage, and access policy.
Evaluation pathRun the pytest/ruff pipeline and inspect generated quality reports and contract outputs.

Evaluation Path

Architecture Notes

Architecture

flowchart LR
    subgraph Ingestion
        CSV["source_orders.csv<br/><i>12 rows, 4 intentional violations</i>"]
    end

    subgraph Bronze["Bronze Layer"]
        B_TABLE[("bronze_orders<br/>Delta Table")]
        B_CONTRACT["Contract:<br/>- Raw envelope preserved<br/>- ingested_at attached<br/>- source_rank for dedup"]
    end

    subgraph Silver["Silver Layer"]
        GATES{"Quality Gates<br/>4 rules"}
        S_TABLE[("silver_orders<br/>Delta Table")]
        REJECTED[/"Rejected Rows<br/>Review Queue"/]
        S_CONTRACT["Contract:<br/>- customer_id NOT NULL<br/>- region NOT NULL<br/>- amount > 0<br/>- Dedup by order_id"]
    end

    subgraph Gold["Gold Layer"]
        G_TABLE[("gold_region_kpis<br/>Delta Table")]
        G_CONTRACT["Contract:<br/>- Region-level KPIs only<br/>- Only accepted rows<br/>- Fixed output schema"]
    end

    subgraph Export["Export Layer"]
        SF["Snowflake<br/>MERGE Upsert"]
        DB["Databricks<br/>Unity Catalog"]
        S3["AWS S3<br/>Artifacts"]
    end

    subgraph API["FastAPI Service"]
        HEALTH["/health"]
        QR["/quality-report"]
        PREVIEW["/table-preview"]
    end

    CSV --> B_TABLE
    B_TABLE --> GATES
    GATES -->|"Passed"| S_TABLE
    GATES -->|"Failed"| REJECTED
    S_TABLE --> G_TABLE
    G_TABLE --> SF
    G_TABLE --> DB
    G_TABLE --> S3
    G_TABLE --> API
    REJECTED --> QR

---

Technical Proof Boundary

DimensionDetails
Primary architecture laneData contracts, analytics platform operations, and lakehouse export reliability
Strongest proofMedallion pipeline structure, quality gates, export adapters, and reviewer-readable runtime APIs
What is realSpark transforms, rejection logic, KPI rollups, Snowflake MERGE export logic, Databricks export bridges, local review surfaces
What is boundedLive Snowflake and Databricks exports only activate when credentials are configured; the seeded business dataset is synthetic

---

Tech Stack

LayerTechnologyPurpose
ComputeApache Spark (PySpark 3.5)Distributed transforms across medallion layers
StorageDelta Lake 3.2ACID transactions, schema enforcement, time travel
APIFastAPIServe quality reports, table previews, health checks
WarehouseSnowflakeGold KPI export via MERGE-based upserts
CatalogDatabricks Unity CatalogDelta table export via Statement Execution API
Object StorageAWS S3Artifact upload target
IaCTerraformGCP Cloud Run deployment configuration
ContainerDocker / Docker ComposeReproducible full-stack execution
CI/CDGitHub ActionsLint, test, build, smoke test, Docker build
Qualitypytest (81+ tests), ruffTest suite with coverage; linting and formatting

---

Local (no Docker)


## Clone and set up
git clone https://github.com/KIM3310/lakehouse-contract-lab.git
cd lakehouse-contract-lab
make install


## If your default python3 is older than 3.11:
make BOOTSTRAP_PYTHON=/path/to/python3.11 install


## Run the full pipeline: lint, test, build artifacts
make pipeline


## Start the API server
make serve
open http://127.0.0.1:8096/docs

Docker (recommended for full Spark + Delta rebuild)

cp .env.example .env
docker compose up --build

## API available at http://localhost:8096/docs

No Java Runtime?

If Java is not installed, the pipeline validates checked-in prebuilt artifacts instead of rebuilding Spark/Delta outputs. Tests and the API layer work without a JVM.

make test       # runs 81+ tests against prebuilt artifacts
make serve      # starts the API server

Makefile Reference

CommandDescription
make installCreate venv and install all dependencies
make testRun the full pytest suite
make lintRun ruff linter
make buildRun the medallion pipeline and generate artifacts
make pipelineFull pipeline: lint + test + build
make verifyFull verification: pipeline + API smoke test
make serveStart FastAPI dev server with hot reload
make docker-runRun via Docker Compose

---

Quality Gates (Bronze to Silver)

RuleFieldConditionRejected Label
customer_presentcustomer_idMust not be nullmissing_customer
region_presentregionMust not be nullmissing_region
positive_amountamountMust be > 0non_positive_amount
latest_order_recordorder_idDedup, keep neweststale_duplicate

Rules are defined declaratively in data/quality_rules.json and enforced as chained PySpark WHEN expressions. Failed rows land in a rejected DataFrame with a rejection_reason label, accessible at /api/runtime/quality-report. Rejected rows are never discarded -- they form a review queue for data engineers to investigate upstream quality issues.

Gold aggregates accepted silver rows by region into KPI columns: gross_revenue_usd, accepted_orders, completed_orders, pipeline_orders, distinct_customers.

---

Consolidated Operating Pattern

Data platform operating patterns folds demo-pack and rollout-playbook material into the canonical contract-first path used by this repository.

---

Core API

MethodPathDescription
GET/healthService health with quality-artifact links
GET/api/runtime/quality-reportData quality gate results with rejected row preview
GET/api/runtime/table-captures/{layer}Layer preview: bronze / silver / gold
GET/api/runtime/pipeline-summaryPipeline metrics across all three layers
GET/api/runtime/export-statusSnowflake, Databricks, S3 export configuration status

---

Deployment

All cloud integrations are env-var gated -- the project runs fully locally without any cloud credentials.

Snowflake -- set SNOWFLAKE_ACCOUNT, SNOWFLAKE_USER, SNOWFLAKE_PASSWORD. Gold KPIs are written via MERGE-based upserts to LAKEHOUSE_LAB.GOLD.REGION_KPIS.

Databricks Unity Catalog -- set DATABRICKS_HOST + auth (CLI profile, service-principal OAuth, or token). Gold KPIs land as Delta tables; catalog/schema auto-created.

AWS S3 -- set AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, S3_ARTIFACT_BUCKET to enable artifact upload.

GCP Cloud Run -- Terraform config in infra/terraform/.

---

Project Structure

lakehouse-contract-lab/
|-- app/
|   |-- main.py                  # FastAPI app serving pipeline artifacts
|   |-- snowflake_adapter.py     # Snowflake MERGE-based export adapter
|   |-- databricks_adapter.py    # Databricks Unity Catalog export adapter
|   |-- resource_pack.py         # Source data and config loaders
|-- scripts/
|   |-- build_lakehouse_artifacts.py  # Full medallion pipeline (Bronze/Silver/Gold)
|-- data/
|   |-- source_orders.csv        # 12-row synthetic dataset with quality violations
|   |-- quality_rules.json       # Declarative quality gate definitions
|   |-- export_targets.json      # Export target configurations
|   |-- validation_cases.json    # Test validation cases
|-- artifacts/                   # Generated pipeline outputs (JSON + Delta)
|-- tests/                       # 81+ pytest tests (adapters, API, pipeline, resource pack)
|-- docs/
|   |-- adr/                     # Architecture Decision Records
|   |-- data-platform-operating-patterns.md # Consolidated rollout and demo patterns
|   |-- data-contracts.md        # Contract-first approach documentation
|   |-- medallion-architecture.md # Layer-by-layer architecture guide
|-- infra/terraform/             # GCP Cloud Run deployment
|-- .github/workflows/ci.yml     # CI: lint, test, build, smoke, Docker

---

Operating Commands

---

Related Projects

ProjectDescription
Nexus-HiveGoverned NL-to-SQL analytics on top of this data
enterprise-llm-adoption-kitEnterprise LLM governance framework

---

Cloud + AI Architecture

Enterprise Productization

System Architecture

Service Architecture

Search And Service Surface