dbt Project Structure (models, seeds, snapshots, macros, tests)
Organize models, seeds, snapshots, macros, and tests so projects stay navigable as they grow.
In plain words
Source-aligned types and names. Next, intermediate business logic with explicit refs. Finally, tests, macros, seeds, snapshots, docs, and ownership.
Think of it like…
Project structure is a warehouse zoning plan: receiving docks, preparation rooms, reusable tools, audited history, and shipping-floor models should not all be piled in one room.
Where you’ve seen it
models/staging/stripe/stg_payments.sql renames source columns; models/marts/fct_revenue.sql joins trusted refs and exposes one order-line grain; schema.yml declares relationships, not only descriptions.
Words you’ll hear
- models
- SQL/Jinja files materialized by dbt through a compiled dependency graph.
- macros
- Reusable Jinja functions that generate SQL with controlled parameters and are reviewed through compiled output.
- tests
- Assertions on models/sources, including generic YAML expectations and custom SQL/query checks.
- Operational boundary
- Models that jump from source to a complex mart couple business rules, duplicate tests, and hide circular selection, while oversized seeds quietly become an inappropriate production loader. Use shallow staging renames/type casts, focused intermediate joins, grain-explicit marts, YAML near the owned model, and packages/macros only when reuse has a stable interface.
Visual diagram
Theory & deep dive
models: the working mechanism
A dbt project separates reusable macros, seeds, source definitions, staging/intermediate/mart models, snapshots, and schema tests so dependency direction and ownership remain legible.
Source-aligned types and names. Intermediate business logic with explicit refs, then grain-owned mart or semantic model; this exposes the state governed by tests.
models/staging/stripe/stg_payments.sql renames source columns; models/marts/fct_revenue.sql joins trusted refs and exposes one order-line grain; schema.yml declares relationships, not only descriptions.
dbt Project Structure: failure mode and production response
Models that jump from source to a complex mart couple business rules, duplicate tests, and hide circular selection, while oversized seeds quietly become an inappropriate production loader.
Use shallow staging renames/type casts, focused intermediate joins, grain-explicit marts, YAML near the owned model, and packages/macros only when reuse has a stable interface. Track Directory ownership as "folder maps to domain and layer", and make Model grain visible to the dataset owner.
How it works, step by step
Step 1 of 41. Stage
Source-aligned types and names. A dbt project separates reusable macros, seeds, source definitions, staging/intermediate/mart models, snapshots, and schema tests so dependency direction and ownership remain legible.
- Directory ownership
- folder maps to domain and layer
- macros
- Reusable Jinja functions that generate SQL with controlled parameters and are reviewed through compiled output.
When to use it & trade-offs
What it is
A dbt project separates reusable macros, seeds, source definitions, staging/intermediate/mart models, snapshots, and schema tests so dependency direction and ownership remain legible. models/staging/stripe/stg_payments.sql renames source columns; models/marts/fct_revenue.sql joins trusted refs and exposes one order-line grain; schema.yml declares relationships, not only descriptions.
Why it matters: Models that jump from source to a complex mart couple business rules, duplicate tests, and hide circular selection, while oversized seeds quietly become an inappropriate production loader. Use shallow staging renames/type casts, focused intermediate joins, grain-explicit marts, YAML near the owned model, and packages/macros only when reuse has a stable interface.
When to reach for it
- Organize models, seeds, snapshots, macros, and tests so projects stay navigable as they grow.
- Choose models because it provides this capability: SQL/Jinja files materialized by dbt through a compiled dependency graph.
- Keep evidence for Directory ownership at "folder maps to domain and layer" so the last production stage-Support - tests, macros, seeds, snapshots, docs, and ownership-remains testable.
When to avoid or be careful
- Models that jump from source to a complex mart couple business rules, duplicate tests, and hide circular selection, while oversized seeds quietly become an inappropriate production loader.
- Do not conflate macros with models. The second concept contributes different behavior: Reusable Jinja functions that generate SQL with controlled parameters and are reviewed through compiled output.
- Release only after this guardrail is in place: Use shallow staging renames/type casts, focused intermediate joins, grain-explicit marts, YAML near the owned model, and packages/macros only when reuse has a stable interface.
models / macros / tests - roles, limits, and operating cost
Strengths: SQL/Jinja files materialized by dbt through a compiled dependency graph. A dbt project separates reusable macros, seeds, source definitions, staging/intermediate/mart models, snapshots, and schema tests so dependency direction and ownership remain legible.
Watch out: Models that jump from source to a complex mart couple business rules, duplicate tests, and hide circular selection, while oversized seeds quietly become an inappropriate production loader.
Strengths: Reusable Jinja functions that generate SQL with controlled parameters and are reviewed through compiled output. In this workflow it supports: Publish - grain-owned mart or semantic model.
Watch out: The operating cost is real: one sentence per mart model.
Strengths: Assertions on models/sources, including generic YAML expectations and custom SQL/query checks. Its output can be checked with Seed size.
Watch out: Operating guardrail: Use shallow staging renames/type casts, focused intermediate joins, grain-explicit marts, YAML near the owned model, and packages/macros only when reuse has a stable interface.
Interview signals & numbers to know
When this topic comes up
- “Where is the failure boundary for models, and how would Directory ownership reveal it?”
- “Why is macros distinct from this behavior: assertions on models/sources, including generic YAML expectations and custom SQL/query checks?”
- Production clue: Models that jump from source to a complex mart couple business rules, duplicate tests, and hide circular selection, while oversized seeds quietly become an inappropriate production loader.
- Design probe: Use shallow staging renames/type casts, focused intermediate joins, grain-explicit marts, YAML near the owned model, and packages/macros only when reuse has a stable interface.
Benchmarks & rules of thumb
- Directory ownership
- folder maps to domain and layer
- Model grain
- one sentence per mart model
- Seed size
- small static reference only, not application data extract
Common mistakes & follow-ups
Common interview mistakes
- Models that jump from source to a complex mart couple business rules, duplicate tests, and hide circular selection, while oversized seeds quietly become an inappropriate production loader.
- Reporting success from a job exit code without checking Directory ownership and Model grain.
- Treating this example as complete without replay, rollback, or access boundaries:
models/staging/stripe/stg_payments.sqlrenames source columns;models/marts/fct_revenue.sqljoins trusted refs and exposes one order-line grain;schema.ymldeclares relationships, not only descriptions.
Likely interviewer follow-ups
- How would you prove this contract instead of only checking that the command ran: SQL/Jinja files materialized by dbt through a compiled dependency graph.
- What does the recovery plan do when this occurs? Models that jump from source to a complex mart couple business rules, duplicate tests, and hide circular selection, while oversized seeds quietly become an inappropriate production loader.
- When is models insufficient for Model grain, and what does adding macros cost in Directory ownership?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply dbt Project Structure (models, seeds, snapshots, macros, tests) with data engineer interview Q&A and hands-on practice.