A dbt project, file by file
A dbt project is a folder with a few conventions: where models, tests, seeds and macros live, and how they are named. Following them makes a project of hundreds of models easy to navigate. This lesson walks through the files and the usual layers.
Pipelines in production · dbt · Bronze · Project basics, lesson 2 of 2
On this page
Read first: What dbt is (and is not) (skip if you know it)
In plain words first
A well-run kitchen keeps raw ingredients in one place, prepared ones in another, and finished dishes at the pass. Anyone new knows where to look.
A dbt project does the same with folders: staging for cleaned raw tables, intermediate for in-between steps, marts for the tables people use.
The files
A typical project
tunes/ ├── dbt_project.yml project name, paths, folder-level configs ├── packages.yml packages to install with dbt deps ├── models/ │ ├── staging/ │ │ ├── billing/ │ │ │ ├── _billing__sources.yml source() declarations │ │ │ ├── _billing__models.yml tests and docs │ │ │ ├── stg_billing__invoices.sql │ │ │ └── stg_billing__charges.sql │ ├── intermediate/ │ │ └── int_invoices__with_charges.sql │ └── marts/ │ ├── _marts__models.yml │ ├── dim_accounts.sql │ └── fct_invoices.sql ├── macros/ reusable Jinja ├── tests/ singular data tests ├── seeds/ small CSVs loaded with dbt seed └── snapshots/ SCD Type 2 snapshots
Connection details are not in the project. They live in profiles.yml, usually in ~/.dbt/ on a laptop or written by the CI job, so passwords never reach version control.
dbt_project.yml
name: tunes
profile: tunes # which profile in profiles.yml to use
model-paths: ["models"]
models:
tunes:
staging:
+materialized: view # every model under models/staging/
intermediate:
+materialized: ephemeral
marts:
+materialized: table
+schema: marts # build into a separate schema
The + prefix marks a config that applies to every modelmodel: A SELECT statement in a .sql file. dbt runs it and saves the result in the warehouse as a table or view named after the file. Learn more → in that folder and below. A model can still override it with {{ config(...) }} at the top of its file; the most specific setting wins: model file, then YAML properties, then dbt_project.yml.
profiles.yml and targets
tunes:
target: dev # used when you do not pass --target
outputs:
dev:
type: snowflake
account: acme-xy12345
user: alice
password: "{{ env_var('DBT_PASSWORD') }}"
database: analytics
schema: dbt_alice # each developer builds into their own schema
warehouse: transforming
threads: 8
prod:
type: snowflake
account: acme-xy12345
user: dbt_prod
password: "{{ env_var('DBT_PROD_PASSWORD') }}"
database: analytics
schema: analytics
warehouse: transforming
threads: 16
A target is one set of connection details. Alice running dbt run builds into dbt_alice; the production job runs dbt build --target prod and builds into analytics. The model code is identical. threads is how many models dbt builds at the same time.
+schema: marts, dbt's default generate_schema_name macromacro: A reusable piece of Jinja, like a function that returns SQL. You call it with {{ my_macro(...) }}. Learn more → builds into <target schema>_marts (so dbt_alice_marts in dev and analytics_marts in prod), not marts. This keeps developers from overwriting each other. Many teams override the macro so prod uses the plain custom name.Staging, intermediate, marts
| Layer | One model per | What happens there | Usually |
|---|---|---|---|
Staging (stg_) | Sourcesource: A raw table loaded by another tool, declared in YAML so models can select from it with source() and dbt can test it and check its freshness. Learn more → table | Rename, cast, fix units, light cleaning. No joins, no aggregation. | View |
Intermediate (int_) | Reusable step | Joins and reshaping that several marts share. | Ephemeral or view |
Marts (fct_, dim_) | Business entity or process | Facts and dimensions the business queries: one row per invoice, per account. | Table or incremental |
The rule that makes this work: only staging modelsstaging model: The first layer of models: one per source table, renaming and casting columns, with no joins or business logic. Learn more → read sources, and everything downstream reads staging through ref(). When a source column is renamed, you fix one staging model, not twenty marts.
Naming
stg_<source>__<entity>(double underscore) shows which system a staging model comes from:stg_billing__invoices,stg_stripe__charges.- Marts are named for the business:
fct_invoices(events, one row per invoice),dim_accounts(entities, one row per account). - YAML files start with an underscore so they sort to the top of the folder.
Common mistakes
- Committing profiles.yml with passwords — Keep it out of the repository and read secrets with
env_var(). - Joining in staging models — Staging is one model per source table. Joins go in intermediate models or marts.
- Being surprised by dbt_alice_marts — Custom schemas are appended to the target schema unless you override
generate_schema_name.
Key takeaways
- dbt_project.yml configures the project; profiles.yml holds connections and stays out of git.
- Targets let the same code build into dev schemas or production.
- Staging cleans each source once; marts serve the business; intermediate holds shared steps.
- Configs cascade: folder in dbt_project.yml, then YAML properties, then the model's config().
Interview prep
THE QUESTION
"How would you structure a dbt project, and why?"
source(). Intermediate: reusable joins and reshaping. Marts: facts and dimensions named for the business, materialized as tables or incremental models. Folder-level configs in dbt_project.yml set materializations and schemas per layer; connection details and secrets live in profiles.yml, with a target per environment so every developer builds into their own schema.Avoid: "we put all models in one folder". Explain the layers and why only staging reads sources.
Follow-ups · answer out loud, then open
Follow-up"Why does a model with +schema: marts end up in dbt_alice_marts?"
Scenario"Two developers keep overwriting each other's tables during development. What is wrong?"
Trap"profiles.yml belongs in the repository so everyone has the same settings."
Check yourself
3 questionsWhere should warehouse passwords for dbt live?
Show the answer
profiles.yml, read from environment variables. profiles.yml is outside the project; env_var() keeps secrets out of files.
A model sets materialized='table' in config() and its folder sets +materialized: view. What is built?
Show the answer
A table. The most specific config, the model's own, wins.
Which layer should call source()?
Show the answer
Staging. Only staging reads raw tables, so source changes are fixed in one place.
Practise this
Problems that use this, graded on hidden tests
Keep going
Up next · new module: Building models · 5 min readSources and staging models
Declare raw tables with source(), check their freshness, and clean them once in a staging model.
Related lessons
Previous: What dbt is (and is not)
Primary sources: How we structure our dbt projects · About dbt_project.yml