@zimezone/z-command 1.0.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/README.md +57 -38
  2. package/dist/cli.js +14 -2
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/init.d.ts +1 -7
  5. package/dist/commands/init.d.ts.map +1 -1
  6. package/dist/commands/init.js +101 -23
  7. package/dist/commands/init.js.map +1 -1
  8. package/dist/commands/update.d.ts +11 -0
  9. package/dist/commands/update.d.ts.map +1 -0
  10. package/dist/commands/update.js +88 -0
  11. package/dist/commands/update.js.map +1 -0
  12. package/dist/platforms.d.ts +21 -0
  13. package/dist/platforms.d.ts.map +1 -0
  14. package/dist/platforms.js +137 -0
  15. package/dist/platforms.js.map +1 -0
  16. package/dist/types.d.ts +44 -0
  17. package/dist/types.d.ts.map +1 -0
  18. package/dist/types.js +6 -0
  19. package/dist/types.js.map +1 -0
  20. package/package.json +13 -5
  21. package/templates/agents/api-documenter.agent.md +161 -0
  22. package/templates/agents/architect-review.agent.md +146 -0
  23. package/templates/agents/arm-cortex-expert.agent.md +288 -0
  24. package/templates/agents/backend-architect.agent.md +309 -0
  25. package/templates/agents/backend-security-coder.agent.md +152 -0
  26. package/templates/agents/bash-pro.agent.md +285 -0
  27. package/templates/agents/c-pro.agent.md +35 -0
  28. package/templates/agents/c4-code.agent.md +320 -0
  29. package/templates/agents/c4-component.agent.md +227 -0
  30. package/templates/agents/c4-container.agent.md +248 -0
  31. package/templates/agents/c4-context.agent.md +235 -0
  32. package/templates/agents/conductor-validator.agent.md +245 -0
  33. package/templates/agents/csharp-pro.agent.md +38 -0
  34. package/templates/agents/customer-support.agent.md +148 -0
  35. package/templates/agents/database-admin.agent.md +142 -0
  36. package/templates/agents/database-architect.agent.md +238 -0
  37. package/templates/agents/database-optimizer.agent.md +144 -0
  38. package/templates/agents/debugger.agent.md +30 -0
  39. package/templates/agents/deployment-engineer.agent.md +0 -0
  40. package/templates/agents/devops-troubleshooter.agent.md +138 -0
  41. package/templates/agents/django-pro.agent.md +159 -0
  42. package/templates/agents/docs-architect.agent.md +77 -0
  43. package/templates/agents/dotnet-architect.agent.md +175 -0
  44. package/templates/agents/dx-optimizer.agent.md +63 -0
  45. package/templates/agents/elixir-pro.agent.md +38 -0
  46. package/templates/agents/error-detective.agent.md +32 -0
  47. package/templates/agents/event-sourcing-architect.agent.md +42 -0
  48. package/templates/agents/fastapi-pro.agent.md +171 -0
  49. package/templates/agents/firmware-analyst.agent.md +330 -0
  50. package/templates/agents/frontend-security-coder.agent.md +149 -0
  51. package/templates/agents/haskell-pro.agent.md +37 -0
  52. package/templates/agents/hr-pro.agent.md +105 -0
  53. package/templates/agents/incident-responder.agent.md +190 -0
  54. package/templates/agents/ios-developer.agent.md +198 -0
  55. package/templates/agents/java-pro.agent.md +156 -0
  56. package/templates/agents/javascript-pro.agent.md +35 -0
  57. package/templates/agents/julia-pro.agent.md +187 -0
  58. package/templates/agents/legal-advisor.agent.md +49 -0
  59. package/templates/agents/malware-analyst.agent.md +272 -0
  60. package/templates/agents/mermaid-expert.agent.md +39 -0
  61. package/templates/agents/minecraft-bukkit-pro.agent.md +104 -0
  62. package/templates/agents/mobile-security-coder.agent.md +163 -0
  63. package/templates/agents/monorepo-architect.agent.md +44 -0
  64. package/templates/agents/observability-engineer.agent.md +228 -0
  65. package/templates/agents/performance-engineer.agent.md +167 -0
  66. package/templates/agents/php-pro.agent.md +43 -0
  67. package/templates/agents/posix-shell-pro.agent.md +284 -0
  68. package/templates/agents/quant-analyst.agent.md +32 -0
  69. package/templates/agents/reference-builder.agent.md +167 -0
  70. package/templates/agents/reverse-engineer.agent.md +202 -0
  71. package/templates/agents/risk-manager.agent.md +41 -0
  72. package/templates/agents/ruby-pro.agent.md +35 -0
  73. package/templates/agents/rust-pro.agent.md +156 -0
  74. package/templates/agents/sales-automator.agent.md +35 -0
  75. package/templates/agents/scala-pro.agent.md +60 -0
  76. package/templates/agents/search-specialist.agent.md +59 -0
  77. package/templates/agents/security-auditor.agent.md +138 -0
  78. package/templates/agents/seo-authority-builder.agent.md +116 -0
  79. package/templates/agents/seo-cannibalization-detector.agent.md +103 -0
  80. package/templates/agents/seo-content-auditor.agent.md +63 -0
  81. package/templates/agents/seo-content-planner.agent.md +88 -0
  82. package/templates/agents/seo-content-refresher.agent.md +98 -0
  83. package/templates/agents/seo-content-writer.agent.md +76 -0
  84. package/templates/agents/seo-keyword-strategist.agent.md +75 -0
  85. package/templates/agents/seo-meta-optimizer.agent.md +72 -0
  86. package/templates/agents/seo-snippet-hunter.agent.md +94 -0
  87. package/templates/agents/seo-structure-architect.agent.md +88 -0
  88. package/templates/agents/service-mesh-expert.agent.md +41 -0
  89. package/templates/agents/sql-pro.agent.md +146 -0
  90. package/templates/agents/tdd-orchestrator.agent.md +183 -0
  91. package/templates/agents/temporal-python-pro.agent.md +349 -0
  92. package/templates/agents/terraform-specialist.agent.md +137 -0
  93. package/templates/agents/test-automator.agent.md +203 -0
  94. package/templates/agents/threat-modeling-expert.agent.md +44 -0
  95. package/templates/agents/tutorial-engineer.agent.md +118 -0
  96. package/templates/agents/ui-ux-designer.agent.md +188 -0
  97. package/templates/agents/ui-visual-validator.agent.md +192 -0
  98. package/templates/agents/vector-database-engineer.agent.md +43 -0
  99. package/templates/skills/angular-migration/SKILL.md +410 -0
  100. package/templates/skills/api-design-principles/SKILL.md +528 -0
  101. package/templates/skills/api-design-principles/assets/api-design-checklist.md +155 -0
  102. package/templates/skills/api-design-principles/assets/rest-api-template.py +182 -0
  103. package/templates/skills/api-design-principles/references/graphql-schema-design.md +583 -0
  104. package/templates/skills/api-design-principles/references/rest-best-practices.md +408 -0
  105. package/templates/skills/architecture-decision-records/SKILL.md +428 -0
  106. package/templates/skills/architecture-patterns/SKILL.md +494 -0
  107. package/templates/skills/async-python-patterns/SKILL.md +694 -0
  108. package/templates/skills/auth-implementation-patterns/SKILL.md +634 -0
  109. package/templates/skills/changelog-automation/SKILL.md +552 -0
  110. package/templates/skills/code-review-excellence/SKILL.md +520 -0
  111. package/templates/skills/competitive-landscape/SKILL.md +479 -0
  112. package/templates/skills/context-driven-development/SKILL.md +385 -0
  113. package/templates/skills/cost-optimization/SKILL.md +274 -0
  114. package/templates/skills/cqrs-implementation/SKILL.md +554 -0
  115. package/templates/skills/data-quality-frameworks/SKILL.md +587 -0
  116. package/templates/skills/data-storytelling/SKILL.md +453 -0
  117. package/templates/skills/database-migration/SKILL.md +424 -0
  118. package/templates/skills/dbt-transformation-patterns/SKILL.md +561 -0
  119. package/templates/skills/debugging-strategies/SKILL.md +527 -0
  120. package/templates/skills/defi-protocol-templates/SKILL.md +454 -0
  121. package/templates/skills/dependency-upgrade/SKILL.md +409 -0
  122. package/templates/skills/deployment-pipeline-design/SKILL.md +359 -0
  123. package/templates/skills/distributed-tracing/SKILL.md +438 -0
  124. package/templates/skills/dotnet-backend-patterns/SKILL.md +815 -0
  125. package/templates/skills/dotnet-backend-patterns/assets/repository-template.cs +523 -0
  126. package/templates/skills/dotnet-backend-patterns/assets/service-template.cs +336 -0
  127. package/templates/skills/dotnet-backend-patterns/references/dapper-patterns.md +544 -0
  128. package/templates/skills/dotnet-backend-patterns/references/ef-core-best-practices.md +355 -0
  129. package/templates/skills/e2e-testing-patterns/SKILL.md +547 -0
  130. package/templates/skills/employment-contract-templates/SKILL.md +507 -0
  131. package/templates/skills/error-handling-patterns/SKILL.md +636 -0
  132. package/templates/skills/event-store-design/SKILL.md +437 -0
  133. package/templates/skills/fastapi-templates/SKILL.md +567 -0
  134. package/templates/skills/git-advanced-workflows/SKILL.md +400 -0
  135. package/templates/skills/github-actions-templates/SKILL.md +333 -0
  136. package/templates/skills/go-concurrency-patterns/SKILL.md +655 -0
  137. package/templates/skills/grafana-dashboards/SKILL.md +369 -0
  138. package/templates/skills/helm-chart-scaffolding/SKILL.md +544 -0
  139. package/templates/skills/helm-chart-scaffolding/assets/Chart.yaml.template +42 -0
  140. package/templates/skills/helm-chart-scaffolding/assets/values.yaml.template +185 -0
  141. package/templates/skills/helm-chart-scaffolding/references/chart-structure.md +500 -0
  142. package/templates/skills/helm-chart-scaffolding/scripts/validate-chart.sh +244 -0
  143. package/templates/skills/javascript-testing-patterns/SKILL.md +1025 -0
  144. package/templates/skills/langchain-architecture/SKILL.md +338 -0
  145. package/templates/skills/llm-evaluation/SKILL.md +471 -0
  146. package/templates/skills/microservices-patterns/SKILL.md +595 -0
  147. package/templates/skills/modern-javascript-patterns/SKILL.md +911 -0
  148. package/templates/skills/monorepo-management/SKILL.md +622 -0
  149. package/templates/skills/nextjs-app-router-patterns/SKILL.md +544 -0
  150. package/templates/skills/nodejs-backend-patterns/SKILL.md +1020 -0
  151. package/templates/skills/nx-workspace-patterns/SKILL.md +452 -0
  152. package/templates/skills/openapi-spec-generation/SKILL.md +1028 -0
  153. package/templates/skills/paypal-integration/SKILL.md +467 -0
  154. package/templates/skills/pci-compliance/SKILL.md +466 -0
  155. package/templates/skills/postgresql/SKILL.md +204 -0
  156. package/templates/skills/projection-patterns/SKILL.md +490 -0
  157. package/templates/skills/prometheus-configuration/SKILL.md +392 -0
  158. package/templates/skills/prompt-engineering-patterns/SKILL.md +201 -0
  159. package/templates/skills/prompt-engineering-patterns/assets/few-shot-examples.json +106 -0
  160. package/templates/skills/prompt-engineering-patterns/assets/prompt-template-library.md +246 -0
  161. package/templates/skills/prompt-engineering-patterns/references/chain-of-thought.md +399 -0
  162. package/templates/skills/prompt-engineering-patterns/references/few-shot-learning.md +369 -0
  163. package/templates/skills/prompt-engineering-patterns/references/prompt-optimization.md +414 -0
  164. package/templates/skills/prompt-engineering-patterns/references/prompt-templates.md +470 -0
  165. package/templates/skills/prompt-engineering-patterns/references/system-prompts.md +189 -0
  166. package/templates/skills/prompt-engineering-patterns/scripts/optimize-prompt.py +279 -0
  167. package/templates/skills/python-packaging/SKILL.md +870 -0
  168. package/templates/skills/python-performance-optimization/SKILL.md +869 -0
  169. package/templates/skills/python-testing-patterns/SKILL.md +907 -0
  170. package/templates/skills/rag-implementation/SKILL.md +403 -0
  171. package/templates/skills/react-modernization/SKILL.md +513 -0
  172. package/templates/skills/react-native-architecture/SKILL.md +671 -0
  173. package/templates/skills/react-state-management/SKILL.md +429 -0
  174. package/templates/skills/risk-metrics-calculation/SKILL.md +555 -0
  175. package/templates/skills/rust-async-patterns/SKILL.md +517 -0
  176. package/templates/skills/secrets-management/SKILL.md +346 -0
  177. package/templates/skills/security-requirement-extraction/SKILL.md +677 -0
  178. package/templates/skills/shellcheck-configuration/SKILL.md +454 -0
  179. package/templates/skills/similarity-search-patterns/SKILL.md +558 -0
  180. package/templates/skills/slo-implementation/SKILL.md +329 -0
  181. package/templates/skills/sql-optimization-patterns/SKILL.md +493 -0
  182. package/templates/skills/stripe-integration/SKILL.md +442 -0
  183. package/templates/skills/tailwind-design-system/SKILL.md +666 -0
  184. package/templates/skills/temporal-python-testing/SKILL.md +158 -0
  185. package/templates/skills/temporal-python-testing/resources/integration-testing.md +455 -0
  186. package/templates/skills/temporal-python-testing/resources/local-setup.md +553 -0
  187. package/templates/skills/temporal-python-testing/resources/replay-testing.md +462 -0
  188. package/templates/skills/temporal-python-testing/resources/unit-testing.md +328 -0
  189. package/templates/skills/terraform-module-library/SKILL.md +249 -0
  190. package/templates/skills/terraform-module-library/references/aws-modules.md +63 -0
  191. package/templates/skills/threat-mitigation-mapping/SKILL.md +745 -0
  192. package/templates/skills/track-management/SKILL.md +593 -0
  193. package/templates/skills/typescript-advanced-types/SKILL.md +717 -0
  194. package/templates/skills/ui-ux-pro-max/SKILL.md +352 -0
  195. package/templates/skills/ui-ux-pro-max/data/charts.csv +26 -0
  196. package/templates/skills/ui-ux-pro-max/data/colors.csv +97 -0
  197. package/templates/skills/ui-ux-pro-max/data/icons.csv +101 -0
  198. package/templates/skills/ui-ux-pro-max/data/landing.csv +31 -0
  199. package/templates/skills/ui-ux-pro-max/data/products.csv +97 -0
  200. package/templates/skills/ui-ux-pro-max/data/prompts.csv +24 -0
  201. package/templates/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
  202. package/templates/skills/ui-ux-pro-max/data/styles.csv +59 -0
  203. package/templates/skills/ui-ux-pro-max/data/typography.csv +58 -0
  204. package/templates/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
  205. package/templates/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
  206. package/templates/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
  207. package/templates/skills/ui-ux-pro-max/scripts/core.py +258 -0
  208. package/templates/skills/ui-ux-pro-max/scripts/design_system.py +547 -0
  209. package/templates/skills/ui-ux-pro-max/scripts/search.py +76 -0
  210. package/templates/skills/uv-package-manager/SKILL.md +831 -0
  211. package/templates/skills/vector-index-tuning/SKILL.md +521 -0
  212. package/templates/skills/wcag-audit-patterns/SKILL.md +555 -0
  213. package/templates/skills/workflow-orchestration-patterns/SKILL.md +316 -0
  214. package/templates/skills/workflow-patterns/SKILL.md +623 -0
  215. package/templates/agents/game-developer.agent.md +0 -57
  216. package/templates/agents/kubernetes-specialist.agent.md +0 -56
  217. package/templates/agents/market-researcher.agent.md +0 -47
@@ -0,0 +1,561 @@
1
+ ---
2
+ name: dbt-transformation-patterns
3
+ description: Master dbt (data build tool) for analytics engineering with model organization, testing, documentation, and incremental strategies. Use when building data transformations, creating data models, or implementing analytics engineering best practices.
4
+ ---
5
+
6
+ # dbt Transformation Patterns
7
+
8
+ Production-ready patterns for dbt (data build tool) including model organization, testing strategies, documentation, and incremental processing.
9
+
10
+ ## When to Use This Skill
11
+
12
+ - Building data transformation pipelines with dbt
13
+ - Organizing models into staging, intermediate, and marts layers
14
+ - Implementing data quality tests
15
+ - Creating incremental models for large datasets
16
+ - Documenting data models and lineage
17
+ - Setting up dbt project structure
18
+
19
+ ## Core Concepts
20
+
21
+ ### 1. Model Layers (Medallion Architecture)
22
+
23
+ ```
24
+ sources/ Raw data definitions
25
+
26
+ staging/ 1:1 with source, light cleaning
27
+
28
+ intermediate/ Business logic, joins, aggregations
29
+
30
+ marts/ Final analytics tables
31
+ ```
32
+
33
+ ### 2. Naming Conventions
34
+
35
+ | Layer | Prefix | Example |
36
+ |-------|--------|---------|
37
+ | Staging | `stg_` | `stg_stripe__payments` |
38
+ | Intermediate | `int_` | `int_payments_pivoted` |
39
+ | Marts | `dim_`, `fct_` | `dim_customers`, `fct_orders` |
40
+
41
+ ## Quick Start
42
+
43
+ ```yaml
44
+ # dbt_project.yml
45
+ name: 'analytics'
46
+ version: '1.0.0'
47
+ profile: 'analytics'
48
+
49
+ model-paths: ["models"]
50
+ analysis-paths: ["analyses"]
51
+ test-paths: ["tests"]
52
+ seed-paths: ["seeds"]
53
+ macro-paths: ["macros"]
54
+
55
+ vars:
56
+ start_date: '2020-01-01'
57
+
58
+ models:
59
+ analytics:
60
+ staging:
61
+ +materialized: view
62
+ +schema: staging
63
+ intermediate:
64
+ +materialized: ephemeral
65
+ marts:
66
+ +materialized: table
67
+ +schema: analytics
68
+ ```
69
+
70
+ ```
71
+ # Project structure
72
+ models/
73
+ ├── staging/
74
+ │ ├── stripe/
75
+ │ │ ├── _stripe__sources.yml
76
+ │ │ ├── _stripe__models.yml
77
+ │ │ ├── stg_stripe__customers.sql
78
+ │ │ └── stg_stripe__payments.sql
79
+ │ └── shopify/
80
+ │ ├── _shopify__sources.yml
81
+ │ └── stg_shopify__orders.sql
82
+ ├── intermediate/
83
+ │ └── finance/
84
+ │ └── int_payments_pivoted.sql
85
+ └── marts/
86
+ ├── core/
87
+ │ ├── _core__models.yml
88
+ │ ├── dim_customers.sql
89
+ │ └── fct_orders.sql
90
+ └── finance/
91
+ └── fct_revenue.sql
92
+ ```
93
+
94
+ ## Patterns
95
+
96
+ ### Pattern 1: Source Definitions
97
+
98
+ ```yaml
99
+ # models/staging/stripe/_stripe__sources.yml
100
+ version: 2
101
+
102
+ sources:
103
+ - name: stripe
104
+ description: Raw Stripe data loaded via Fivetran
105
+ database: raw
106
+ schema: stripe
107
+ loader: fivetran
108
+ loaded_at_field: _fivetran_synced
109
+ freshness:
110
+ warn_after: {count: 12, period: hour}
111
+ error_after: {count: 24, period: hour}
112
+ tables:
113
+ - name: customers
114
+ description: Stripe customer records
115
+ columns:
116
+ - name: id
117
+ description: Primary key
118
+ tests:
119
+ - unique
120
+ - not_null
121
+ - name: email
122
+ description: Customer email
123
+ - name: created
124
+ description: Account creation timestamp
125
+
126
+ - name: payments
127
+ description: Stripe payment transactions
128
+ columns:
129
+ - name: id
130
+ tests:
131
+ - unique
132
+ - not_null
133
+ - name: customer_id
134
+ tests:
135
+ - not_null
136
+ - relationships:
137
+ to: source('stripe', 'customers')
138
+ field: id
139
+ ```
140
+
141
+ ### Pattern 2: Staging Models
142
+
143
+ ```sql
144
+ -- models/staging/stripe/stg_stripe__customers.sql
145
+ with source as (
146
+ select * from {{ source('stripe', 'customers') }}
147
+ ),
148
+
149
+ renamed as (
150
+ select
151
+ -- ids
152
+ id as customer_id,
153
+
154
+ -- strings
155
+ lower(email) as email,
156
+ name as customer_name,
157
+
158
+ -- timestamps
159
+ created as created_at,
160
+
161
+ -- metadata
162
+ _fivetran_synced as _loaded_at
163
+
164
+ from source
165
+ )
166
+
167
+ select * from renamed
168
+ ```
169
+
170
+ ```sql
171
+ -- models/staging/stripe/stg_stripe__payments.sql
172
+ {{
173
+ config(
174
+ materialized='incremental',
175
+ unique_key='payment_id',
176
+ on_schema_change='append_new_columns'
177
+ )
178
+ }}
179
+
180
+ with source as (
181
+ select * from {{ source('stripe', 'payments') }}
182
+
183
+ {% if is_incremental() %}
184
+ where _fivetran_synced > (select max(_loaded_at) from {{ this }})
185
+ {% endif %}
186
+ ),
187
+
188
+ renamed as (
189
+ select
190
+ -- ids
191
+ id as payment_id,
192
+ customer_id,
193
+ invoice_id,
194
+
195
+ -- amounts (convert cents to dollars)
196
+ amount / 100.0 as amount,
197
+ amount_refunded / 100.0 as amount_refunded,
198
+
199
+ -- status
200
+ status as payment_status,
201
+
202
+ -- timestamps
203
+ created as created_at,
204
+
205
+ -- metadata
206
+ _fivetran_synced as _loaded_at
207
+
208
+ from source
209
+ )
210
+
211
+ select * from renamed
212
+ ```
213
+
214
+ ### Pattern 3: Intermediate Models
215
+
216
+ ```sql
217
+ -- models/intermediate/finance/int_payments_pivoted_to_customer.sql
218
+ with payments as (
219
+ select * from {{ ref('stg_stripe__payments') }}
220
+ ),
221
+
222
+ customers as (
223
+ select * from {{ ref('stg_stripe__customers') }}
224
+ ),
225
+
226
+ payment_summary as (
227
+ select
228
+ customer_id,
229
+ count(*) as total_payments,
230
+ count(case when payment_status = 'succeeded' then 1 end) as successful_payments,
231
+ sum(case when payment_status = 'succeeded' then amount else 0 end) as total_amount_paid,
232
+ min(created_at) as first_payment_at,
233
+ max(created_at) as last_payment_at
234
+ from payments
235
+ group by customer_id
236
+ )
237
+
238
+ select
239
+ customers.customer_id,
240
+ customers.email,
241
+ customers.created_at as customer_created_at,
242
+ coalesce(payment_summary.total_payments, 0) as total_payments,
243
+ coalesce(payment_summary.successful_payments, 0) as successful_payments,
244
+ coalesce(payment_summary.total_amount_paid, 0) as lifetime_value,
245
+ payment_summary.first_payment_at,
246
+ payment_summary.last_payment_at
247
+
248
+ from customers
249
+ left join payment_summary using (customer_id)
250
+ ```
251
+
252
+ ### Pattern 4: Mart Models (Dimensions and Facts)
253
+
254
+ ```sql
255
+ -- models/marts/core/dim_customers.sql
256
+ {{
257
+ config(
258
+ materialized='table',
259
+ unique_key='customer_id'
260
+ )
261
+ }}
262
+
263
+ with customers as (
264
+ select * from {{ ref('int_payments_pivoted_to_customer') }}
265
+ ),
266
+
267
+ orders as (
268
+ select * from {{ ref('stg_shopify__orders') }}
269
+ ),
270
+
271
+ order_summary as (
272
+ select
273
+ customer_id,
274
+ count(*) as total_orders,
275
+ sum(total_price) as total_order_value,
276
+ min(created_at) as first_order_at,
277
+ max(created_at) as last_order_at
278
+ from orders
279
+ group by customer_id
280
+ ),
281
+
282
+ final as (
283
+ select
284
+ -- surrogate key
285
+ {{ dbt_utils.generate_surrogate_key(['customers.customer_id']) }} as customer_key,
286
+
287
+ -- natural key
288
+ customers.customer_id,
289
+
290
+ -- attributes
291
+ customers.email,
292
+ customers.customer_created_at,
293
+
294
+ -- payment metrics
295
+ customers.total_payments,
296
+ customers.successful_payments,
297
+ customers.lifetime_value,
298
+ customers.first_payment_at,
299
+ customers.last_payment_at,
300
+
301
+ -- order metrics
302
+ coalesce(order_summary.total_orders, 0) as total_orders,
303
+ coalesce(order_summary.total_order_value, 0) as total_order_value,
304
+ order_summary.first_order_at,
305
+ order_summary.last_order_at,
306
+
307
+ -- calculated fields
308
+ case
309
+ when customers.lifetime_value >= 1000 then 'high'
310
+ when customers.lifetime_value >= 100 then 'medium'
311
+ else 'low'
312
+ end as customer_tier,
313
+
314
+ -- timestamps
315
+ current_timestamp as _loaded_at
316
+
317
+ from customers
318
+ left join order_summary using (customer_id)
319
+ )
320
+
321
+ select * from final
322
+ ```
323
+
324
+ ```sql
325
+ -- models/marts/core/fct_orders.sql
326
+ {{
327
+ config(
328
+ materialized='incremental',
329
+ unique_key='order_id',
330
+ incremental_strategy='merge'
331
+ )
332
+ }}
333
+
334
+ with orders as (
335
+ select * from {{ ref('stg_shopify__orders') }}
336
+
337
+ {% if is_incremental() %}
338
+ where updated_at > (select max(updated_at) from {{ this }})
339
+ {% endif %}
340
+ ),
341
+
342
+ customers as (
343
+ select * from {{ ref('dim_customers') }}
344
+ ),
345
+
346
+ final as (
347
+ select
348
+ -- keys
349
+ orders.order_id,
350
+ customers.customer_key,
351
+ orders.customer_id,
352
+
353
+ -- dimensions
354
+ orders.order_status,
355
+ orders.fulfillment_status,
356
+ orders.payment_status,
357
+
358
+ -- measures
359
+ orders.subtotal,
360
+ orders.tax,
361
+ orders.shipping,
362
+ orders.total_price,
363
+ orders.total_discount,
364
+ orders.item_count,
365
+
366
+ -- timestamps
367
+ orders.created_at,
368
+ orders.updated_at,
369
+ orders.fulfilled_at,
370
+
371
+ -- metadata
372
+ current_timestamp as _loaded_at
373
+
374
+ from orders
375
+ left join customers on orders.customer_id = customers.customer_id
376
+ )
377
+
378
+ select * from final
379
+ ```
380
+
381
+ ### Pattern 5: Testing and Documentation
382
+
383
+ ```yaml
384
+ # models/marts/core/_core__models.yml
385
+ version: 2
386
+
387
+ models:
388
+ - name: dim_customers
389
+ description: Customer dimension with payment and order metrics
390
+ columns:
391
+ - name: customer_key
392
+ description: Surrogate key for the customer dimension
393
+ tests:
394
+ - unique
395
+ - not_null
396
+
397
+ - name: customer_id
398
+ description: Natural key from source system
399
+ tests:
400
+ - unique
401
+ - not_null
402
+
403
+ - name: email
404
+ description: Customer email address
405
+ tests:
406
+ - not_null
407
+
408
+ - name: customer_tier
409
+ description: Customer value tier based on lifetime value
410
+ tests:
411
+ - accepted_values:
412
+ values: ['high', 'medium', 'low']
413
+
414
+ - name: lifetime_value
415
+ description: Total amount paid by customer
416
+ tests:
417
+ - dbt_utils.expression_is_true:
418
+ expression: ">= 0"
419
+
420
+ - name: fct_orders
421
+ description: Order fact table with all order transactions
422
+ tests:
423
+ - dbt_utils.recency:
424
+ datepart: day
425
+ field: created_at
426
+ interval: 1
427
+ columns:
428
+ - name: order_id
429
+ tests:
430
+ - unique
431
+ - not_null
432
+ - name: customer_key
433
+ tests:
434
+ - not_null
435
+ - relationships:
436
+ to: ref('dim_customers')
437
+ field: customer_key
438
+ ```
439
+
440
+ ### Pattern 6: Macros and DRY Code
441
+
442
+ ```sql
443
+ -- macros/cents_to_dollars.sql
444
+ {% macro cents_to_dollars(column_name, precision=2) %}
445
+ round({{ column_name }} / 100.0, {{ precision }})
446
+ {% endmacro %}
447
+
448
+ -- macros/generate_schema_name.sql
449
+ {% macro generate_schema_name(custom_schema_name, node) %}
450
+ {%- set default_schema = target.schema -%}
451
+ {%- if custom_schema_name is none -%}
452
+ {{ default_schema }}
453
+ {%- else -%}
454
+ {{ default_schema }}_{{ custom_schema_name }}
455
+ {%- endif -%}
456
+ {% endmacro %}
457
+
458
+ -- macros/limit_data_in_dev.sql
459
+ {% macro limit_data_in_dev(column_name, days=3) %}
460
+ {% if target.name == 'dev' %}
461
+ where {{ column_name }} >= dateadd(day, -{{ days }}, current_date)
462
+ {% endif %}
463
+ {% endmacro %}
464
+
465
+ -- Usage in model
466
+ select * from {{ ref('stg_orders') }}
467
+ {{ limit_data_in_dev('created_at') }}
468
+ ```
469
+
470
+ ### Pattern 7: Incremental Strategies
471
+
472
+ ```sql
473
+ -- Delete+Insert (default for most warehouses)
474
+ {{
475
+ config(
476
+ materialized='incremental',
477
+ unique_key='id',
478
+ incremental_strategy='delete+insert'
479
+ )
480
+ }}
481
+
482
+ -- Merge (best for late-arriving data)
483
+ {{
484
+ config(
485
+ materialized='incremental',
486
+ unique_key='id',
487
+ incremental_strategy='merge',
488
+ merge_update_columns=['status', 'amount', 'updated_at']
489
+ )
490
+ }}
491
+
492
+ -- Insert Overwrite (partition-based)
493
+ {{
494
+ config(
495
+ materialized='incremental',
496
+ incremental_strategy='insert_overwrite',
497
+ partition_by={
498
+ "field": "created_date",
499
+ "data_type": "date",
500
+ "granularity": "day"
501
+ }
502
+ )
503
+ }}
504
+
505
+ select
506
+ *,
507
+ date(created_at) as created_date
508
+ from {{ ref('stg_events') }}
509
+
510
+ {% if is_incremental() %}
511
+ where created_date >= dateadd(day, -3, current_date)
512
+ {% endif %}
513
+ ```
514
+
515
+ ## dbt Commands
516
+
517
+ ```bash
518
+ # Development
519
+ dbt run # Run all models
520
+ dbt run --select staging # Run staging models only
521
+ dbt run --select +fct_orders # Run fct_orders and its upstream
522
+ dbt run --select fct_orders+ # Run fct_orders and its downstream
523
+ dbt run --full-refresh # Rebuild incremental models
524
+
525
+ # Testing
526
+ dbt test # Run all tests
527
+ dbt test --select stg_stripe # Test specific models
528
+ dbt build # Run + test in DAG order
529
+
530
+ # Documentation
531
+ dbt docs generate # Generate docs
532
+ dbt docs serve # Serve docs locally
533
+
534
+ # Debugging
535
+ dbt compile # Compile SQL without running
536
+ dbt debug # Test connection
537
+ dbt ls --select tag:critical # List models by tag
538
+ ```
539
+
540
+ ## Best Practices
541
+
542
+ ### Do's
543
+ - **Use staging layer** - Clean data once, use everywhere
544
+ - **Test aggressively** - Not null, unique, relationships
545
+ - **Document everything** - Column descriptions, model descriptions
546
+ - **Use incremental** - For tables > 1M rows
547
+ - **Version control** - dbt project in Git
548
+
549
+ ### Don'ts
550
+ - **Don't skip staging** - Raw → mart is tech debt
551
+ - **Don't hardcode dates** - Use `{{ var('start_date') }}`
552
+ - **Don't repeat logic** - Extract to macros
553
+ - **Don't test in prod** - Use dev target
554
+ - **Don't ignore freshness** - Monitor source data
555
+
556
+ ## Resources
557
+
558
+ - [dbt Documentation](https://docs.getdbt.com/)
559
+ - [dbt Best Practices](https://docs.getdbt.com/guides/best-practices)
560
+ - [dbt-utils Package](https://hub.getdbt.com/dbt-labs/dbt_utils/latest/)
561
+ - [dbt Discourse](https://discourse.getdbt.com/)