# Design Dbt Project Structure

> Use when starting a dbt (data build tool) project or analytics repo, or when an existing one has hundreds of tangled models with no clear layers — marts reading

- Skill: `jeffreytse/design-dbt-project-structure` (Agent Skill)
- Install (CLI): `npx get-skill add jeffreytse/design-dbt-project-structure`
- Raw SKILL.md: https://api.skillmd.com/api/skills/jeffreytse/design-dbt-project-structure/raw
- Safety review: pending
- Works with: any agent that reads SKILL.md (Claude Code, Claude.ai, Cursor, Codex, Windsurf, 60+ more)
- Category: Coding & Dev Tools
- Author: jeffreytse (https://skillmd.com/u/jeffreytse)
- Updated: 2026-12-03
- Page: https://skillmd.com/skills/jeffreytse/design-dbt-project-structure

---

---
name: design-dbt-project-structure
description: Use when starting a dbt (data build tool) project or analytics repo, or when an existing one has hundreds of tangled models with no clear layers — marts reading raw sources directly, duplicated business logic, inconsistent naming, and nobody sure which model is the source of truth.
source: 'dbt Labs, "How we structure our dbt projects" (Best Practice Guides), docs.getdbt.com; dbt Labs, "dbt style guide"; Kimball & Ross, "The Data Warehouse Toolkit", 3rd ed., 2013; Beauchemin, "Functional Data Engineering — a modern paradigm for batch data processing", 2018'
tags: [project-structure, dbt, analytics-engineering, data-modeling, sql, data-warehouse]
related: [design-data-pipeline, design-data-model, design-data-quality-framework, write-sql-query]
---

# Design dbt Project Structure

Organize transformations in three layers (**staging → intermediate → marts**), with consistent naming, one model per source table in staging, business logic defined once, and tests and docs next to the models.

## Why This Is Best Practice

**Adopted by:**
- dbt Labs' official "How we structure our dbt projects" guide, followed by the thousands of companies using dbt (JetBlue, GitLab, whose dbt project is public, and HubSpot).
- The marts layer applies Kimball dimensional modeling, the long-standing data-warehousing standard.

**Impact:**
- Layering confines source-specific cleanup to one place. When a source system changes, you fix one staging model instead of every downstream query.
- The DAG becomes readable, and tests at each layer catch data issues before they reach dashboards.

**Why best:**
- Without layers, every analyst rewrites the same joins and cleaning in different marts, and numbers stop matching across reports.
- Staging (clean once), intermediate (compose), and marts (serve the business) create a single source of truth with a clear direction of dependency.

Sources: dbt Labs, "How we structure our dbt projects" and "dbt style guide" (docs.getdbt.com). Kimball, R. & Ross, M. (2013), *The Data Warehouse Toolkit*, 3rd ed., Wiley. Beauchemin, M. (2018), "Functional Data Engineering".

## Steps

1. **Use the standard folder layout:**
   ```
   models/
     staging/
       stripe/
         _stripe__sources.yml
         _stripe__models.yml
         stg_stripe__payments.sql
       shopify/
         stg_shopify__orders.sql
     intermediate/
       finance/
         int_payments_pivoted_to_orders.sql
     marts/
       finance/
         fct_orders.sql
         _finance__models.yml
       marketing/
         dim_customers.sql
   seeds/   snapshots/   macros/   tests/   analyses/
   dbt_project.yml   packages.yml
   ```

2. **Staging: one model per source table, light cleanup only.**
   - Rename columns, cast types, convert units, and do basic cleaning.
   - No joins and no aggregations.
   - Folders are organized by *source system*.
   - Name models `stg_<source>__<entity>s` and materialize them as views.
   - Only staging models use `{{ source() }}`. Everything else uses `{{ ref() }}`.

3. **Intermediate: purpose-built transformation steps.**
   - Joins, pivots, and re-graining that prepare data for marts.
   - Folders are organized by *business domain*.
   - Name them `int_<entity>s_<verb>s` (for example `int_payments_pivoted_to_orders`).
   - Not exposed to end users. Usually ephemeral or views.

4. **Marts: business-facing entities.**
   - Facts (`fct_`) and dimensions (`dim_`), or wide entity tables, organized by department or domain.
   - Materialized as tables or incremental models.
   - Each concept (customer, order, revenue) is defined once and reused.

5. **Keep YAML next to models.** Use `_<dir>__sources.yml` and `_<dir>__models.yml` per folder, with descriptions and tests. Every model gets at least a primary-key `unique` + `not_null` test. Add `relationships` and `accepted_values` where meaningful. See `design-data-quality-framework`.

6. **Configure by folder in `dbt_project.yml`** (materialization, schema, tags) instead of repeating config in every model.

7. **Follow the style guide:**
   - lowercase SQL, CTEs over subqueries
   - an "import CTEs → logical CTEs → final select" structure
   - explicit column lists in marts
   - SQLFluff enforced in CI

8. **Use reusable code deliberately.**
   - Macros for repeated SQL patterns.
   - Packages (dbt_utils, dbt_expectations) instead of hand-rolled versions.
   - Seeds only for small, static mapping tables.

9. **Run CI on every pull request.** Use `dbt build --select state:modified+` against a CI schema (slim CI), so changed models and their downstreams are built and tested before merge.

## Rules

- Sources are referenced only in staging.
- Data flows staging → intermediate → marts, never backwards or sideways from marts.
- One staging model per source table, with one-to-one grain.
- Each business concept is defined in exactly one mart model.
- Every model has a description and a primary-key test.

## Common Mistakes

- **Marts selecting from `source()` directly.** Cleaning logic gets duplicated, and source changes break everything.
- **Joins in staging.** Staging becomes a second intermediate layer, and grain gets confusing.
- **Folder-per-person or per-dashboard.** The structure should follow sources and domains, not requesters.
- **Materializing everything as tables.** Slow and costly. Default staging to views and promote only as needed.
- **No tests until something breaks.** Add key tests when creating each model.

## Examples

**E-commerce analytics:** `stg_shopify__orders`, `stg_stripe__payments` → `int_payments_pivoted_to_orders` → `fct_orders` (one row per order with payment totals) and `dim_customers`. The finance and marketing dashboards both read `fct_orders`, so revenue matches everywhere.

**Source migration:** Stripe is replaced by Adyen. A new `stg_adyen__payments` is mapped to the same columns, and `int_payments_pivoted_to_orders` unions both sources. The marts are unchanged.

## When NOT to Use

- **Non-dbt transformation stacks** (Spark jobs, SQLMesh, Dataform). The layering principle still applies, but follow the tool's conventions.
- **Tiny projects with a handful of models**, where three layers add more ceremony than clarity. Start with staging plus marts.

