# AGENTS.md: dbt project

## Commands
- `dbt deps` · `dbt build --select state:modified+ --defer --state prod-artifacts/` (or `dbt build -s <model>+` locally)
- Lint SQL: `sqlfluff lint models/` (if configured)

## Layers
- `models/staging/<source>/stg_<source>__<table>.sql`: one per source table, rename/cast only, materialized as views.
- `models/intermediate/int_*.sql`: joins and business logic, not exposed.
- `models/marts/<domain>/fct_*.sql` and `dim_*.sql`: what BI tools read.
- Sources are declared in `_<source>__sources.yml` with freshness checks; reference with `{{ source() }}`, models with `{{ ref() }}`. Never hard-code schema names.

## SQL style
- CTEs at the top (`with orders as (select * from {{ ref('stg_shop__orders') }})`), one final `select`.
- Lowercase keywords, explicit column lists in marts, no `select *` in the final CTE.
- Large tables are `incremental` with a `unique_key` and an `is_incremental()` filter.

## Tests and docs
- Every model has a primary key with `unique` + `not_null` tests in its YAML.
- Add `relationships` and `accepted_values` tests where they apply; use unit tests (`unit_tests:`) for tricky logic.
- Every model and key column gets a `description`.

## Don't
Don't run `dbt run --full-refresh` on production or change a mart's grain without calling it out.
