dbt project structure helps organize your data transformation work clearly. It makes your data models easy to find and manage.
dbt project structure
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.
models/ ├── staging/ │ └── customers.sql ├── marts/ │ └── sales.sql └── schema.yml
macros/ └── my_macros.sql
snapshots/ └── customer_snapshot.sql
This config file tells dbt where to find models and macros. It also sets how models are built.
# 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
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.
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
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]
- Confusing macros/ with models/
- Thinking snapshots/ holds models
- Assuming tests/ contains SQL models
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]
- Using dbt_config.yml instead
- Confusing with generic project.yaml
- Assuming settings file controls project
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?
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]
- Adding functions inside models/ files
- Editing dbt_project.yml for SQL code
- Confusing macros/ with models/
Compilation Error: Could not find model 'sales_summary'. Which is the most likely cause related to project structure?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]
- Placing model files in macros/ folder
- Assuming missing dbt_project.yml causes this error
- Confusing snapshots/ with models/
models/. How should you update your dbt_project.yml to reflect this structure?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]
- Not nesting configs under project name
- Configuring macros instead of models
- Assuming no config needed for subfolders
Ready to prove it?
Pass the test and this pattern moves unknown
