dbt project structure helps organize your data transformation work clearly. It makes your data models easy to find and manage.
dbt project structure
Start learning this pattern below
Jump into concepts and practice - no test required
or
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Syntax
dbt
my_dbt_project/ ├── models/ │ ├── staging/ │ ├── marts/ │ └── schema.yml ├── macros/ ├── tests/ ├── snapshots/ ├── analyses/ ├── data/ ├── dbt_project.yml └── profiles.yml
models/ folder contains SQL files for data transformations.
dbt_project.yml is the main config file for your project settings.
Examples
dbt
models/ ├── staging/ │ └── customers.sql ├── marts/ │ └── sales.sql └── schema.yml
dbt
macros/ └── my_macros.sql
dbt
snapshots/ └── customer_snapshot.sql
Sample Program
This config file tells dbt where to find models and macros. It also sets how models are built.
dbt
# This is a folder structure example, not runnable code # But here is a simple dbt_project.yml content example name: 'my_dbt_project' version: '1.0' config-version: 2 model-paths: ['models'] macro-paths: ['macros'] models: my_dbt_project: staging: materialized: view marts: materialized: table
Important Notes
Always keep your SQL files inside the models/ folder for dbt to find them.
Use schema.yml files to define tests and documentation for your models.
Profiles.yml is usually outside the project folder and stores connection info securely.
Summary
dbt project structure organizes your data models, macros, tests, and configs.
Use folders like models/, macros/, and snapshots/ for clear separation.
The dbt_project.yml file controls project settings and paths.
Practice
1. Which folder in a dbt project typically contains SQL files that define your data transformations?
easy
Solution
Step 1: Understand folder purposes
Themodels/folder is where SQL files for data transformations live.Step 2: Identify correct folder for SQL models
Other folders likemacros/hold reusable code,snapshots/hold snapshot definitions, andtests/hold test files.Final Answer:
models/ -> Option BQuick Check:
Data transformations = models/ folder [OK]
Hint: Models folder holds SQL transformations [OK]
Common Mistakes:
- Confusing macros/ with models/
- Thinking snapshots/ holds models
- Assuming tests/ contains SQL models
2. Which of the following is the correct name for the main configuration file in a dbt project?
easy
Solution
Step 1: Recall main config file name
The main configuration file for dbt projects is nameddbt_project.yml.Step 2: Verify other options
Other options likedbt_config.ymlordbt_settings.ymlare incorrect names.Final Answer:
dbt_project.yml -> Option AQuick Check:
Main config file = dbt_project.yml [OK]
Hint: Main config file always named dbt_project.yml [OK]
Common Mistakes:
- Using dbt_config.yml instead
- Confusing with generic project.yaml
- Assuming settings file controls project
3. Given this dbt project structure snippet:
Which file would you edit to add a reusable SQL function?
my_dbt_project/ ├── models/ │ ├── customers.sql │ └── orders.sql ├── macros/ │ └── date_utils.sql └── dbt_project.yml
Which file would you edit to add a reusable SQL function?
medium
Solution
Step 1: Identify purpose of macros/ folder
Themacros/folder holds reusable SQL functions and macros.Step 2: Locate reusable function file
The filemacros/date_utils.sqlis the right place to add reusable SQL functions.Final Answer:
macros/date_utils.sql -> Option CQuick Check:
Reusable SQL functions = macros/ folder [OK]
Hint: Reusable SQL code goes in macros/ folder [OK]
Common Mistakes:
- Adding functions inside models/ files
- Editing dbt_project.yml for SQL code
- Confusing macros/ with models/
4. You see this error when running dbt:
Compilation Error: Could not find model 'sales_summary'. Which is the most likely cause related to project structure?medium
Solution
Step 1: Understand error meaning
The error means dbt cannot find the model named 'sales_summary'.Step 2: Check model file location
Models must be in themodels/folder. If the file is missing there, dbt can't compile it.Final Answer:
The 'sales_summary.sql' file is missing from the models/ folder. -> Option AQuick Check:
Missing model file in models/ causes compilation error [OK]
Hint: Models must be in models/ folder to compile [OK]
Common Mistakes:
- Placing model files in macros/ folder
- Assuming missing dbt_project.yml causes this error
- Confusing snapshots/ with models/
5. You want to organize your dbt project so that models related to customers and orders are in separate folders inside
models/. How should you update your dbt_project.yml to reflect this structure?hard
Solution
Step 1: Understand folder-specific config in dbt_project.yml
You can specify configs per subfolder insidemodels/by nesting them under your project name.Step 2: Define separate configs for customers and orders folders
Addingcustomers:andorders:keys with materialization settings applies configs to those subfolders.Final Answer:
Add models: my_dbt_project: customers: +materialized: table orders: +materialized: table -> Option DQuick Check:
Use nested keys in dbt_project.yml for subfolder configs [OK]
Hint: Use nested keys in dbt_project.yml for subfolder configs [OK]
Common Mistakes:
- Not nesting configs under project name
- Configuring macros instead of models
- Assuming no config needed for subfolders
