@anhth2/spec-driven-dev-plugin 0.5.0

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 (152) hide show
  1. package/ARCHITECTURE.md +243 -0
  2. package/bin/build.js +230 -0
  3. package/bin/index.js +311 -0
  4. package/commands/debug.md +374 -0
  5. package/commands/debug.tmpl +77 -0
  6. package/commands/define-product.md +451 -0
  7. package/commands/define-product.tmpl +154 -0
  8. package/commands/fix-bug.md +379 -0
  9. package/commands/fix-bug.tmpl +82 -0
  10. package/commands/generate-bdd.md +591 -0
  11. package/commands/generate-bdd.tmpl +294 -0
  12. package/commands/generate-code.md +395 -0
  13. package/commands/generate-code.tmpl +98 -0
  14. package/commands/generate-prd.md +488 -0
  15. package/commands/generate-prd.tmpl +191 -0
  16. package/commands/generate-tech-docs.md +362 -0
  17. package/commands/generate-tech-docs.tmpl +65 -0
  18. package/commands/generate-tests.md +377 -0
  19. package/commands/generate-tests.tmpl +80 -0
  20. package/commands/refine-prd.md +408 -0
  21. package/commands/refine-prd.tmpl +111 -0
  22. package/commands/review-code.md +354 -0
  23. package/commands/review-code.tmpl +57 -0
  24. package/commands/review-context.md +646 -0
  25. package/commands/review-context.tmpl +349 -0
  26. package/commands/review-tech-docs.md +518 -0
  27. package/commands/review-tech-docs.tmpl +221 -0
  28. package/commands/run-tests.md +343 -0
  29. package/commands/run-tests.tmpl +46 -0
  30. package/commands/setup-ai-first.md +278 -0
  31. package/commands/setup-ai-first.tmpl +197 -0
  32. package/commands/smoke-test.md +366 -0
  33. package/commands/smoke-test.tmpl +69 -0
  34. package/commands/validate-traces.md +529 -0
  35. package/commands/validate-traces.tmpl +232 -0
  36. package/core/FRAMEWORK_VERSION +1 -0
  37. package/core/commands/debug.md +374 -0
  38. package/core/commands/define-product.md +451 -0
  39. package/core/commands/fix-bug.md +379 -0
  40. package/core/commands/generate-bdd.md +591 -0
  41. package/core/commands/generate-code.md +395 -0
  42. package/core/commands/generate-prd.md +488 -0
  43. package/core/commands/generate-tech-docs.md +362 -0
  44. package/core/commands/generate-tests.md +377 -0
  45. package/core/commands/refine-prd.md +408 -0
  46. package/core/commands/review-code.md +354 -0
  47. package/core/commands/review-context.md +646 -0
  48. package/core/commands/review-tech-docs.md +518 -0
  49. package/core/commands/run-tests.md +343 -0
  50. package/core/commands/setup-ai-first.md +278 -0
  51. package/core/commands/smoke-test.md +366 -0
  52. package/core/commands/validate-traces.md +529 -0
  53. package/core/hooks/data-guard.js +141 -0
  54. package/core/hooks/settings.json +18 -0
  55. package/core/modules/angular/architecture-snippets/component-patterns.md +187 -0
  56. package/core/modules/angular/module.yaml +6 -0
  57. package/core/modules/angular/stack-profile.yaml +38 -0
  58. package/core/modules/context-engineering/architecture-snippets/context-design.md +119 -0
  59. package/core/modules/context-engineering/module.yaml +9 -0
  60. package/core/modules/context-engineering/stack-profile.yaml +61 -0
  61. package/core/modules/dotnet/architecture-snippets/clean-arch.md +160 -0
  62. package/core/modules/dotnet/module.yaml +6 -0
  63. package/core/modules/dotnet/stack-profile.yaml +50 -0
  64. package/core/modules/golang/architecture-snippets/domain-layout.md +283 -0
  65. package/core/modules/golang/module.yaml +6 -0
  66. package/core/modules/golang/stack-profile.yaml +40 -0
  67. package/core/modules/java-spring/architecture-snippets/layered-arch.md +201 -0
  68. package/core/modules/java-spring/module.yaml +15 -0
  69. package/core/modules/java-spring/stack-profile.yaml +28 -0
  70. package/core/modules/nextjs/architecture-snippets/app-router-patterns.md +269 -0
  71. package/core/modules/nextjs/module.yaml +14 -0
  72. package/core/modules/nextjs/stack-profile.yaml +74 -0
  73. package/core/modules/php-laravel/architecture-snippets/service-repository.md +302 -0
  74. package/core/modules/php-laravel/module.yaml +15 -0
  75. package/core/modules/php-laravel/stack-profile.yaml +56 -0
  76. package/core/modules/react/architecture-snippets/hooks-query-patterns.md +254 -0
  77. package/core/modules/react/module.yaml +14 -0
  78. package/core/modules/react/stack-profile.yaml +63 -0
  79. package/core/rules/data-protection.md +80 -0
  80. package/core/rules/workflow.md +44 -0
  81. package/core/skills/code/SKILL.md +526 -0
  82. package/core/skills/debug/SKILL.md +584 -0
  83. package/core/skills/discovery/SKILL.md +363 -0
  84. package/core/skills/prd/SKILL.md +456 -0
  85. package/core/skills/setup-ai-first/SKILL.md +160 -0
  86. package/core/skills/spec/SKILL.md +361 -0
  87. package/core/skills/test/SKILL.md +862 -0
  88. package/core/steps/context-loader.md +163 -0
  89. package/core/steps/gate.md +81 -0
  90. package/core/steps/report-footer.md +53 -0
  91. package/core/steps/spawn-agent.md +123 -0
  92. package/core/templates/architecture.template.md +113 -0
  93. package/core/templates/feature.template +259 -0
  94. package/core/templates/platform-guide.template.md +145 -0
  95. package/core/templates/prd.template.md +312 -0
  96. package/core/templates/product-definition.template.md +168 -0
  97. package/core/templates/project-context.yaml +78 -0
  98. package/hooks/data-guard.js +141 -0
  99. package/hooks/settings.json +18 -0
  100. package/modules/angular/architecture-snippets/component-patterns.md +187 -0
  101. package/modules/angular/module.yaml +6 -0
  102. package/modules/angular/stack-profile.yaml +38 -0
  103. package/modules/context-engineering/architecture-snippets/context-design.md +119 -0
  104. package/modules/context-engineering/module.yaml +9 -0
  105. package/modules/context-engineering/stack-profile.yaml +61 -0
  106. package/modules/dotnet/architecture-snippets/clean-arch.md +160 -0
  107. package/modules/dotnet/module.yaml +6 -0
  108. package/modules/dotnet/stack-profile.yaml +50 -0
  109. package/modules/golang/architecture-snippets/domain-layout.md +283 -0
  110. package/modules/golang/module.yaml +6 -0
  111. package/modules/golang/stack-profile.yaml +40 -0
  112. package/modules/java-spring/architecture-snippets/layered-arch.md +201 -0
  113. package/modules/java-spring/module.yaml +15 -0
  114. package/modules/java-spring/stack-profile.yaml +28 -0
  115. package/modules/nextjs/architecture-snippets/app-router-patterns.md +269 -0
  116. package/modules/nextjs/module.yaml +14 -0
  117. package/modules/nextjs/stack-profile.yaml +74 -0
  118. package/modules/php-laravel/architecture-snippets/service-repository.md +302 -0
  119. package/modules/php-laravel/module.yaml +15 -0
  120. package/modules/php-laravel/stack-profile.yaml +56 -0
  121. package/modules/react/architecture-snippets/hooks-query-patterns.md +254 -0
  122. package/modules/react/module.yaml +14 -0
  123. package/modules/react/stack-profile.yaml +63 -0
  124. package/package.json +42 -0
  125. package/rules/data-protection.md +80 -0
  126. package/rules/workflow.md +44 -0
  127. package/scripts/init.sh +49 -0
  128. package/scripts/upgrade.sh +94 -0
  129. package/skills/code/SKILL.md +526 -0
  130. package/skills/code/SKILL.tmpl +176 -0
  131. package/skills/debug/SKILL.md +584 -0
  132. package/skills/debug/SKILL.tmpl +262 -0
  133. package/skills/discovery/SKILL.md +363 -0
  134. package/skills/discovery/SKILL.tmpl +147 -0
  135. package/skills/prd/SKILL.md +456 -0
  136. package/skills/prd/SKILL.tmpl +188 -0
  137. package/skills/setup-ai-first/SKILL.md +160 -0
  138. package/skills/setup-ai-first/SKILL.tmpl +107 -0
  139. package/skills/spec/SKILL.md +361 -0
  140. package/skills/spec/SKILL.tmpl +174 -0
  141. package/skills/test/SKILL.md +862 -0
  142. package/skills/test/SKILL.tmpl +296 -0
  143. package/steps/context-loader.md +163 -0
  144. package/steps/gate.md +81 -0
  145. package/steps/report-footer.md +53 -0
  146. package/steps/spawn-agent.md +123 -0
  147. package/templates/architecture.template.md +113 -0
  148. package/templates/feature.template +259 -0
  149. package/templates/platform-guide.template.md +145 -0
  150. package/templates/prd.template.md +312 -0
  151. package/templates/product-definition.template.md +168 -0
  152. package/templates/project-context.yaml +78 -0
@@ -0,0 +1,187 @@
1
+ # Angular — Component Architecture Patterns
2
+
3
+ ## Smart / Container Component Pattern
4
+
5
+ ```typescript
6
+ // order-list.component.ts — Smart component: manages state, injects services
7
+ import { Component, OnInit, inject } from '@angular/core';
8
+ import { CommonModule } from '@angular/common';
9
+ import { OrderService } from '../services/order.service';
10
+ import { OrderListItemComponent } from './order-list-item.component';
11
+ import { Order } from '../models/order.model';
12
+
13
+ @Component({
14
+ selector: 'app-order-list',
15
+ standalone: true,
16
+ imports: [CommonModule, OrderListItemComponent],
17
+ template: `
18
+ <div class="order-list">
19
+ <app-order-list-item
20
+ *ngFor="let order of orders"
21
+ [order]="order"
22
+ (cancel)="onCancelOrder($event)"
23
+ />
24
+ </div>
25
+ `
26
+ })
27
+ export class OrderListComponent implements OnInit {
28
+ private orderService = inject(OrderService);
29
+ orders: Order[] = [];
30
+
31
+ ngOnInit(): void {
32
+ this.orderService.getOrders().subscribe(orders => this.orders = orders);
33
+ }
34
+
35
+ onCancelOrder(orderId: number): void {
36
+ this.orderService.cancelOrder(orderId).subscribe(() => {
37
+ this.orders = this.orders.filter(o => o.id !== orderId);
38
+ });
39
+ }
40
+ }
41
+ ```
42
+
43
+ ## Dumb / Presentational Component Pattern
44
+
45
+ ```typescript
46
+ // order-list-item.component.ts — Dumb component: pure I/O, OnPush, no service injection
47
+ import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
48
+ import { Order } from '../models/order.model';
49
+
50
+ @Component({
51
+ selector: 'app-order-list-item',
52
+ standalone: true,
53
+ changeDetection: ChangeDetectionStrategy.OnPush,
54
+ template: `
55
+ <div class="order-item">
56
+ <span>{{ order.id }}</span>
57
+ <span>{{ order.status }}</span>
58
+ <button (click)="cancel.emit(order.id)" [disabled]="order.status === 'CANCELLED'">
59
+ Cancel
60
+ </button>
61
+ </div>
62
+ `
63
+ })
64
+ export class OrderListItemComponent {
65
+ @Input({ required: true }) order!: Order;
66
+ @Output() cancel = new EventEmitter<number>();
67
+ }
68
+ ```
69
+
70
+ ## Service with HttpClient Pattern
71
+
72
+ ```typescript
73
+ // order.service.ts
74
+ import { Injectable, inject } from '@angular/core';
75
+ import { HttpClient, HttpParams } from '@angular/common/http';
76
+ import { Observable } from 'rxjs';
77
+ import { Order, CreateOrderRequest, OrderResponse } from '../models/order.model';
78
+ import { environment } from '@env/environment';
79
+
80
+ @Injectable({ providedIn: 'root' })
81
+ export class OrderService {
82
+ private http = inject(HttpClient);
83
+ private baseUrl = `${environment.apiUrl}/v1/orders`;
84
+
85
+ getOrders(customerId?: number): Observable<Order[]> {
86
+ let params = new HttpParams();
87
+ if (customerId) params = params.set('customerId', customerId.toString());
88
+ return this.http.get<Order[]>(this.baseUrl, { params });
89
+ }
90
+
91
+ getOrder(id: number): Observable<Order> {
92
+ return this.http.get<Order>(`${this.baseUrl}/${id}`);
93
+ }
94
+
95
+ createOrder(request: CreateOrderRequest): Observable<OrderResponse> {
96
+ return this.http.post<OrderResponse>(this.baseUrl, request);
97
+ }
98
+
99
+ cancelOrder(id: number): Observable<void> {
100
+ return this.http.patch<void>(`${this.baseUrl}/${id}/cancel`, {});
101
+ }
102
+ }
103
+ ```
104
+
105
+ ## Signal-Based State Pattern (Angular 17+)
106
+
107
+ ```typescript
108
+ // order.store.ts — using Angular Signals for state management
109
+ import { Injectable, signal, computed } from '@angular/core';
110
+ import { Order } from '../models/order.model';
111
+
112
+ @Injectable({ providedIn: 'root' })
113
+ export class OrderStore {
114
+ private _orders = signal<Order[]>([]);
115
+ private _loading = signal(false);
116
+ private _error = signal<string | null>(null);
117
+
118
+ // Public readable signals
119
+ readonly orders = this._orders.asReadonly();
120
+ readonly loading = this._loading.asReadonly();
121
+ readonly error = this._error.asReadonly();
122
+
123
+ // Computed signals
124
+ readonly pendingOrders = computed(() =>
125
+ this._orders().filter(o => o.status === 'PENDING')
126
+ );
127
+ readonly orderCount = computed(() => this._orders().length);
128
+
129
+ setOrders(orders: Order[]): void {
130
+ this._orders.set(orders);
131
+ }
132
+
133
+ setLoading(loading: boolean): void {
134
+ this._loading.set(loading);
135
+ }
136
+
137
+ setError(error: string | null): void {
138
+ this._error.set(error);
139
+ }
140
+
141
+ removeOrder(id: number): void {
142
+ this._orders.update(orders => orders.filter(o => o.id !== id));
143
+ }
144
+ }
145
+ ```
146
+
147
+ ## Route Guard Pattern
148
+
149
+ ```typescript
150
+ // auth.guard.ts
151
+ import { inject } from '@angular/core';
152
+ import { CanActivateFn, Router } from '@angular/router';
153
+ import { AuthService } from '../services/auth.service';
154
+
155
+ export const authGuard: CanActivateFn = (route, state) => {
156
+ const auth = inject(AuthService);
157
+ const router = inject(Router);
158
+
159
+ if (auth.isAuthenticated()) {
160
+ return true;
161
+ }
162
+ return router.createUrlTree(['/login'], { queryParams: { returnUrl: state.url } });
163
+ };
164
+ ```
165
+
166
+ ## Standalone Component with Lazy Loading
167
+
168
+ ```typescript
169
+ // app.routes.ts
170
+ import { Routes } from '@angular/router';
171
+ import { authGuard } from './guards/auth.guard';
172
+
173
+ export const APP_ROUTES: Routes = [
174
+ {
175
+ path: 'orders',
176
+ canActivate: [authGuard],
177
+ loadComponent: () =>
178
+ import('./features/orders/order-list.component').then(m => m.OrderListComponent)
179
+ },
180
+ {
181
+ path: 'orders/:id',
182
+ canActivate: [authGuard],
183
+ loadComponent: () =>
184
+ import('./features/orders/order-detail.component').then(m => m.OrderDetailComponent)
185
+ }
186
+ ];
187
+ ```
@@ -0,0 +1,6 @@
1
+ name: "Angular"
2
+ version: "1.0.0"
3
+ description: "Angular 17+ frontend with component-based architecture"
4
+ language: "TypeScript"
5
+ framework: "Angular"
6
+ stack_type: "frontend"
@@ -0,0 +1,38 @@
1
+ build:
2
+ compile: "ng build"
3
+ test: "ng test --watch=false"
4
+ run: "ng serve"
5
+
6
+ architecture:
7
+ style: "Component → Service → HTTP Client → Backend API"
8
+ key_rules:
9
+ - "Smart (container) components manage state and inject services"
10
+ - "Dumb (presentational) components receive data via @Input and emit via @Output"
11
+ - "Business logic lives in services, not in component classes"
12
+ - "Use OnPush change detection for all pure presentational components"
13
+ - "HTTP calls must be in services, never in component files"
14
+
15
+ coding_standards:
16
+ naming:
17
+ components: "PascalCase + Component suffix (e.g., OrderListComponent)"
18
+ services: "PascalCase + Service suffix (e.g., OrderService)"
19
+ pipes: "PascalCase + Pipe suffix (e.g., CurrencyFormatPipe)"
20
+ directives: "PascalCase + Directive suffix (e.g., HighlightDirective)"
21
+ guards: "PascalCase + Guard suffix (e.g., AuthGuard)"
22
+ files:
23
+ component: "{feature}.component.ts / .html / .scss"
24
+ service: "{feature}.service.ts"
25
+ model: "{feature}.model.ts"
26
+ store: "{feature}.store.ts"
27
+ patterns:
28
+ state_management: "NgRx (complex) or Angular Signals (simple/medium)"
29
+ http_error_handling: "HttpInterceptor catches 4xx/5xx globally"
30
+ lazy_loading: "All feature modules must be lazily loaded"
31
+
32
+ testing:
33
+ unit: "Jasmine + Karma or Jest"
34
+ e2e: "Cypress or Playwright"
35
+ patterns:
36
+ - "Use TestBed.configureTestingModule for component tests"
37
+ - "Mock services with jasmine.createSpyObj or jest.fn()"
38
+ - "Test component DOM via DebugElement and By.css selectors"
@@ -0,0 +1,119 @@
1
+ # Context Engineering — Design Templates and Patterns
2
+
3
+ ## System Context Design Template
4
+
5
+ ```markdown
6
+ # System Context: {Agent Name}
7
+
8
+ ## Role
9
+ You are {role description}. You help {target user} to {primary purpose}.
10
+
11
+ ## Scope
12
+ In scope:
13
+ - {capability 1}
14
+ - {capability 2}
15
+
16
+ Out of scope (do not attempt):
17
+ - {excluded capability 1}
18
+ - {excluded capability 2}
19
+
20
+ ## Output Format
21
+ Always respond with:
22
+ - {format requirement 1, e.g., "structured YAML when producing artifacts"}
23
+ - {format requirement 2, e.g., "numbered steps for procedural instructions"}
24
+ - {format requirement 3, e.g., "a CHECKPOINT before any destructive action"}
25
+
26
+ ## Constraints
27
+ - {constraint 1, e.g., "Never make changes without explicit user confirmation"}
28
+ - {constraint 2, e.g., "Always cite source files when referencing code"}
29
+
30
+ ## Tools Available
31
+ - {tool name}: {what it does and when to use it}
32
+ ```
33
+
34
+ ## Context Layering: Persistent vs Ephemeral
35
+
36
+ ```
37
+ ┌─────────────────────────────────────────────────┐
38
+ │ PERSISTENT (system prompt — stable, pre-loaded) │
39
+ │ - Role and persona │
40
+ │ - Output format requirements │
41
+ │ - Constraint rules │
42
+ │ - Domain knowledge (project context) │
43
+ └────────────────────┬────────────────────────────┘
44
+ │ passed once at session start
45
+ ┌────────────────────▼────────────────────────────┐
46
+ │ SESSION (loaded once per task) │
47
+ │ - Project-context.yaml │
48
+ │ - CLAUDE.md │
49
+ │ - Business dictionary │
50
+ └────────────────────┬────────────────────────────┘
51
+ │ loaded on demand
52
+ ┌────────────────────▼────────────────────────────┐
53
+ │ EPHEMERAL (per-turn, discarded after use) │
54
+ │ - Tool results │
55
+ │ - File contents read mid-task │
56
+ │ - User clarification answers │
57
+ └─────────────────────────────────────────────────┘
58
+ ```
59
+
60
+ ## Context Handoff Between Agents
61
+
62
+ When passing work from one agent to another, include a structured handoff payload:
63
+
64
+ ```yaml
65
+ # Agent Handoff Payload
66
+ handoff_from: "{source agent name}"
67
+ handoff_to: "{target agent name}"
68
+ task_id: "{unique task identifier}"
69
+ status: "partial_complete" # pending | partial_complete | blocked | ready_for_review
70
+
71
+ # What was accomplished
72
+ completed:
73
+ - "{step 1 done}"
74
+ - "{step 2 done}"
75
+
76
+ # What the next agent must do
77
+ pending:
78
+ - "{step 3 to do}"
79
+ - "{step 4 to do}"
80
+
81
+ # Decisions made (so next agent doesn't re-litigate)
82
+ decisions:
83
+ - decision: "{what was decided}"
84
+ rationale: "{why}"
85
+
86
+ # Artifacts produced (file paths)
87
+ artifacts:
88
+ - path: "{file path}"
89
+ type: "{type: spec | code | test | report}"
90
+ status: "{draft | approved | final}"
91
+
92
+ # Context the next agent needs immediately
93
+ context_snapshot:
94
+ project_name: "{name}"
95
+ domain: "{domain}"
96
+ uc_id: "{UC-ID}"
97
+ tech_stack: "{stack}"
98
+ ```
99
+
100
+ ## Context Compression Pattern
101
+
102
+ When conversation history grows large, compress before the next turn:
103
+
104
+ ```
105
+ CONTEXT SUMMARY (replaces N previous turns):
106
+ Task: {what we are doing}
107
+ Progress: {what has been completed so far}
108
+ Current state: {where we are now}
109
+ Key decisions: {decisions that must not be reversed}
110
+ Pending: {what still needs to be done}
111
+ Files produced: {list of artifact paths}
112
+ ```
113
+
114
+ Compression rules:
115
+ 1. Keep all decisions and their rationale.
116
+ 2. Keep all file paths that were created.
117
+ 3. Drop intermediate reasoning that led to a confirmed decision.
118
+ 4. Keep any user corrections or explicit preferences.
119
+ 5. Keep any open questions that are still unresolved.
@@ -0,0 +1,9 @@
1
+ name: "Context Engineering"
2
+ version: "1.0.0"
3
+ description: "AI context design, prompt engineering, and system context workflows"
4
+ stack_type: "ai-first"
5
+ use_cases:
6
+ - "Designing AI system contexts"
7
+ - "Reverse engineering existing prompts"
8
+ - "Context window optimization"
9
+ - "Multi-agent coordination"
@@ -0,0 +1,61 @@
1
+ context_types:
2
+ system:
3
+ description: "Persistent instruction context that defines agent behavior and constraints"
4
+ lifetime: "entire session"
5
+ examples:
6
+ - "Role and persona definition"
7
+ - "Output format requirements"
8
+ - "Capability constraints and safety boundaries"
9
+ user:
10
+ description: "Per-turn input from the human, including instructions and data"
11
+ lifetime: "current turn"
12
+ tool:
13
+ description: "Results returned from tool calls (function outputs, search results)"
14
+ lifetime: "current turn or until referenced"
15
+ memory:
16
+ description: "Persistent state stored and retrieved across turns or sessions"
17
+ lifetime: "configurable — session, project, or long-term"
18
+
19
+ context_optimization:
20
+ rules:
21
+ - "Front-load the most decision-relevant context (primacy effect)"
22
+ - "Remove redundant instructions — each rule stated once"
23
+ - "Separate stable context (system prompt) from dynamic context (user message)"
24
+ - "Use structured formats (YAML/JSON/Markdown headers) for scannable context"
25
+ - "Compress historical context before adding new turns (rolling summary)"
26
+ - "Reference external documents by path rather than inlining large content"
27
+ token_budget_targets:
28
+ system_prompt: "under 2000 tokens for most use cases"
29
+ context_window_reserve: "20% of max window for model output"
30
+
31
+ evaluation_criteria:
32
+ clarity:
33
+ description: "Is each instruction unambiguous and actionable?"
34
+ test: "Would two different agents interpret this identically?"
35
+ completeness:
36
+ description: "Does context include all information the agent needs?"
37
+ test: "Can the agent complete the task without asking for clarification?"
38
+ relevance:
39
+ description: "Is every sentence load-bearing for the task?"
40
+ test: "Would removing this sentence change agent behavior?"
41
+ consistency:
42
+ description: "Are there no contradictory instructions?"
43
+ test: "Can all rules be simultaneously satisfied?"
44
+
45
+ common_patterns:
46
+ rag:
47
+ name: "Retrieval-Augmented Generation"
48
+ use_when: "Agent needs knowledge beyond training cutoff or domain-specific facts"
49
+ structure: "System: role + instructions | User: query | Tool: retrieved chunks | User: synthesize"
50
+ chain_of_thought:
51
+ name: "Chain of Thought"
52
+ use_when: "Complex reasoning tasks requiring intermediate steps"
53
+ structure: "Include 'think step by step' or explicit reasoning scaffold in system prompt"
54
+ few_shot:
55
+ name: "Few-Shot Examples"
56
+ use_when: "Output format or classification must match specific patterns"
57
+ structure: "Provide 2-5 input/output pairs before the actual task"
58
+ multi_agent:
59
+ name: "Multi-Agent Coordination"
60
+ use_when: "Task can be parallelized or requires specialist sub-agents"
61
+ structure: "Orchestrator context + worker contexts + handoff format definition"
@@ -0,0 +1,160 @@
1
+ # .NET Clean Architecture — Code Patterns
2
+
3
+ ## Command and Query with MediatR
4
+
5
+ ```csharp
6
+ // Application/Orders/Commands/CreateOrder/CreateOrderCommand.cs
7
+ // @trace.implements=ORDER-UC1-SC1
8
+ public record CreateOrderCommand(
9
+ long CustomerId,
10
+ List<OrderItemDto> Items,
11
+ string ShippingAddress
12
+ ) : IRequest<CreateOrderResult>;
13
+
14
+ // Application/Orders/Commands/CreateOrder/CreateOrderCommandHandler.cs
15
+ public class CreateOrderCommandHandler : IRequestHandler<CreateOrderCommand, CreateOrderResult>
16
+ {
17
+ private readonly IOrderRepository _orderRepository;
18
+ private readonly IUnitOfWork _unitOfWork;
19
+
20
+ public CreateOrderCommandHandler(IOrderRepository orderRepository, IUnitOfWork unitOfWork)
21
+ {
22
+ _orderRepository = orderRepository;
23
+ _unitOfWork = unitOfWork;
24
+ }
25
+
26
+ public async Task<CreateOrderResult> Handle(CreateOrderCommand command, CancellationToken ct)
27
+ {
28
+ var order = Order.Create(command.CustomerId, command.Items, command.ShippingAddress);
29
+ await _orderRepository.AddAsync(order, ct);
30
+ await _unitOfWork.SaveChangesAsync(ct);
31
+ return new CreateOrderResult(order.Id, order.Status.ToString());
32
+ }
33
+ }
34
+
35
+ // Application/Orders/Queries/GetOrder/GetOrderQuery.cs
36
+ // @trace.implements=ORDER-UC1-SC2
37
+ public record GetOrderQuery(long OrderId) : IRequest<OrderDto>;
38
+ ```
39
+
40
+ ## FluentValidation for Commands
41
+
42
+ ```csharp
43
+ // Application/Orders/Commands/CreateOrder/CreateOrderCommandValidator.cs
44
+ public class CreateOrderCommandValidator : AbstractValidator<CreateOrderCommand>
45
+ {
46
+ public CreateOrderCommandValidator()
47
+ {
48
+ RuleFor(x => x.CustomerId).GreaterThan(0);
49
+ RuleFor(x => x.Items).NotEmpty().WithMessage("Order must have at least one item.");
50
+ RuleFor(x => x.ShippingAddress).NotEmpty().MaximumLength(500);
51
+ RuleForEach(x => x.Items).ChildRules(item =>
52
+ {
53
+ item.RuleFor(i => i.ProductId).GreaterThan(0);
54
+ item.RuleFor(i => i.Quantity).InclusiveBetween(1, 999);
55
+ });
56
+ }
57
+ }
58
+ ```
59
+
60
+ ## Domain Entity Pattern
61
+
62
+ ```csharp
63
+ // Domain/Entities/Order.cs
64
+ public class Order : BaseEntity
65
+ {
66
+ private readonly List<OrderItem> _items = new();
67
+
68
+ public long CustomerId { get; private set; }
69
+ public OrderStatus Status { get; private set; }
70
+ public string ShippingAddress { get; private set; } = string.Empty;
71
+ public IReadOnlyCollection<OrderItem> Items => _items.AsReadOnly();
72
+ public decimal TotalAmount => _items.Sum(i => i.Subtotal);
73
+
74
+ private Order() { } // EF Core constructor
75
+
76
+ public static Order Create(long customerId, IEnumerable<OrderItemDto> items, string shippingAddress)
77
+ {
78
+ var order = new Order
79
+ {
80
+ CustomerId = customerId,
81
+ ShippingAddress = shippingAddress,
82
+ Status = OrderStatus.Pending,
83
+ CreatedAt = DateTime.UtcNow
84
+ };
85
+
86
+ foreach (var item in items)
87
+ order._items.Add(OrderItem.Create(item.ProductId, item.Quantity, item.UnitPrice));
88
+
89
+ order.AddDomainEvent(new OrderCreatedEvent(order.Id, order.CustomerId));
90
+ return order;
91
+ }
92
+
93
+ public void Cancel()
94
+ {
95
+ if (Status == OrderStatus.Shipped)
96
+ throw new DomainException("Cannot cancel an order that has already been shipped.");
97
+ Status = OrderStatus.Cancelled;
98
+ }
99
+ }
100
+ ```
101
+
102
+ ## Repository Implementation with EF Core
103
+
104
+ ```csharp
105
+ // Infrastructure/Persistence/Repositories/OrderRepository.cs
106
+ public class OrderRepository : IOrderRepository
107
+ {
108
+ private readonly AppDbContext _context;
109
+
110
+ public OrderRepository(AppDbContext context) => _context = context;
111
+
112
+ public async Task<Order?> GetByIdAsync(long id, CancellationToken ct = default)
113
+ => await _context.Orders
114
+ .Include(o => o.Items)
115
+ .FirstOrDefaultAsync(o => o.Id == id, ct);
116
+
117
+ public async Task AddAsync(Order order, CancellationToken ct = default)
118
+ => await _context.Orders.AddAsync(order, ct);
119
+
120
+ public async Task<IReadOnlyList<Order>> GetByCustomerAsync(long customerId, CancellationToken ct = default)
121
+ => await _context.Orders
122
+ .Where(o => o.CustomerId == customerId)
123
+ .OrderByDescending(o => o.CreatedAt)
124
+ .ToListAsync(ct);
125
+ }
126
+ ```
127
+
128
+ ## Minimal API Controller Pattern
129
+
130
+ ```csharp
131
+ // Presentation/Endpoints/OrderEndpoints.cs
132
+ // @trace.implements=ORDER-UC1
133
+ public static class OrderEndpoints
134
+ {
135
+ public static void MapOrderEndpoints(this IEndpointRouteBuilder app)
136
+ {
137
+ var group = app.MapGroup("/v1/orders").RequireAuthorization();
138
+
139
+ // @trace.implements=ORDER-UC1-SC1
140
+ group.MapPost("/", async (CreateOrderCommand command, IMediator mediator, CancellationToken ct) =>
141
+ {
142
+ var result = await mediator.Send(command, ct);
143
+ return Results.Created($"/v1/orders/{result.Id}", result);
144
+ })
145
+ .WithName("CreateOrder")
146
+ .Produces<CreateOrderResult>(StatusCodes.Status201Created)
147
+ .ProducesValidationProblem();
148
+
149
+ // @trace.implements=ORDER-UC1-SC2
150
+ group.MapGet("/{id:long}", async (long id, IMediator mediator, CancellationToken ct) =>
151
+ {
152
+ var result = await mediator.Send(new GetOrderQuery(id), ct);
153
+ return result is null ? Results.NotFound() : Results.Ok(result);
154
+ })
155
+ .WithName("GetOrder")
156
+ .Produces<OrderDto>()
157
+ .Produces(StatusCodes.Status404NotFound);
158
+ }
159
+ }
160
+ ```
@@ -0,0 +1,6 @@
1
+ name: ".NET"
2
+ version: "1.0.0"
3
+ description: ".NET 8 with Clean Architecture"
4
+ language: "C#"
5
+ framework: ".NET 8 / ASP.NET Core"
6
+ stack_type: "backend"
@@ -0,0 +1,50 @@
1
+ build:
2
+ compile: "dotnet build"
3
+ test: "dotnet test"
4
+ run: "dotnet run --project src/{ProjectName}.Api"
5
+
6
+ architecture:
7
+ style: "Clean Architecture"
8
+ layers:
9
+ - name: "Domain"
10
+ contains: "Entities, Value Objects, Domain Events, Interfaces"
11
+ rules:
12
+ - "No dependencies on outer layers"
13
+ - "Pure business logic only"
14
+ - name: "Application"
15
+ contains: "Commands, Queries, Handlers (MediatR), DTOs, Validators"
16
+ rules:
17
+ - "Depends only on Domain"
18
+ - "All use cases are Commands or Queries"
19
+ - "Validation via FluentValidation"
20
+ - name: "Infrastructure"
21
+ contains: "EF Core DbContext, Repository implementations, External service adapters"
22
+ rules:
23
+ - "Implements interfaces from Application and Domain"
24
+ - "No business logic"
25
+ - name: "Presentation"
26
+ contains: "Controllers (or Minimal API endpoints), Middleware"
27
+ rules:
28
+ - "Dispatches to MediatR only"
29
+ - "No direct service injection (only IMediator)"
30
+
31
+ coding_standards:
32
+ naming:
33
+ classes: "PascalCase"
34
+ methods: "PascalCase"
35
+ interfaces: "IPascalCase (with I prefix)"
36
+ async_methods: "PascalCase + Async suffix (e.g., GetOrderAsync)"
37
+ patterns:
38
+ cqrs: "MediatR — IRequest<T> for commands/queries, IRequestHandler<T,R> for handlers"
39
+ validation: "FluentValidation — one AbstractValidator<T> per command/query"
40
+ error_handling: "Result pattern or domain exceptions, caught by global middleware"
41
+ response_type: "IActionResult with ProblemDetails for errors (RFC 7807)"
42
+
43
+ testing:
44
+ unit: "xUnit + Moq + FluentAssertions"
45
+ integration: "WebApplicationFactory<Program> + Testcontainers"
46
+ patterns:
47
+ - "Arrange / Act / Assert structure"
48
+ - "Method names: MethodName_WhenCondition_ShouldExpectation"
49
+ - "Use FluentAssertions for readable assertions"
50
+ - "Mock only the direct dependencies of the unit under test"