What if your messy SQL files could magically organize themselves and run perfectly every time?
Why dbt project structure? - Purpose & Use Cases
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine you have many SQL files scattered in different folders without any clear order. You want to build a data model, but you keep losing track of which file does what and how they connect.
Manually managing SQL files and dependencies is slow and confusing. You might run the wrong queries, overwrite files, or miss important steps. It's easy to make mistakes and hard to fix them.
The dbt project structure organizes your files clearly: models, tests, macros, and data sources each have their place. This structure helps dbt understand how everything fits together and runs your data transformations smoothly.
run each SQL file separately without order -- no clear folder structure
dbt run -- uses project folders and config to run models in order
With a clear dbt project structure, you can build reliable, maintainable data pipelines that run automatically and scale easily.
A data analyst working on sales data can organize raw tables, cleaned models, and reports in separate folders. dbt runs them in the right order, so the analyst gets fresh, accurate dashboards every day without manual work.
Manual SQL file management is confusing and error-prone.
dbt project structure organizes files for clarity and automation.
This structure enables smooth, reliable data transformations.
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
