ai-flow-dev 2.7.0 → 2.8.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 (171) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +573 -570
  3. package/package.json +74 -74
  4. package/prompts/backend/flow-build-phase-0.md +535 -535
  5. package/prompts/backend/flow-build-phase-1.md +626 -626
  6. package/prompts/backend/flow-build-phase-10.md +340 -340
  7. package/prompts/backend/flow-build-phase-2.md +573 -573
  8. package/prompts/backend/flow-build-phase-3.md +834 -834
  9. package/prompts/backend/flow-build-phase-4.md +554 -554
  10. package/prompts/backend/flow-build-phase-5.md +703 -703
  11. package/prompts/backend/flow-build-phase-6.md +524 -524
  12. package/prompts/backend/flow-build-phase-7.md +1001 -1001
  13. package/prompts/backend/flow-build-phase-8.md +1407 -1407
  14. package/prompts/backend/flow-build-phase-9.md +477 -477
  15. package/prompts/backend/flow-build.md +137 -137
  16. package/prompts/backend/flow-check-review.md +656 -20
  17. package/prompts/backend/flow-check-test.md +526 -14
  18. package/prompts/backend/flow-check.md +725 -67
  19. package/prompts/backend/flow-commit.md +88 -119
  20. package/prompts/backend/flow-docs-sync.md +354 -354
  21. package/prompts/backend/flow-finish.md +919 -0
  22. package/prompts/backend/flow-release.md +949 -0
  23. package/prompts/backend/flow-work-feature.md +61 -61
  24. package/prompts/backend/flow-work-fix.md +46 -46
  25. package/prompts/backend/flow-work-refactor.md +48 -48
  26. package/prompts/backend/flow-work-resume.md +34 -34
  27. package/prompts/backend/flow-work.md +1098 -1286
  28. package/prompts/desktop/flow-build-phase-0.md +359 -359
  29. package/prompts/desktop/flow-build-phase-1.md +295 -295
  30. package/prompts/desktop/flow-build-phase-10.md +357 -357
  31. package/prompts/desktop/flow-build-phase-2.md +282 -282
  32. package/prompts/desktop/flow-build-phase-3.md +291 -291
  33. package/prompts/desktop/flow-build-phase-4.md +308 -308
  34. package/prompts/desktop/flow-build-phase-5.md +269 -269
  35. package/prompts/desktop/flow-build-phase-6.md +350 -350
  36. package/prompts/desktop/flow-build-phase-7.md +297 -297
  37. package/prompts/desktop/flow-build-phase-8.md +541 -541
  38. package/prompts/desktop/flow-build-phase-9.md +439 -439
  39. package/prompts/desktop/flow-build.md +156 -156
  40. package/prompts/desktop/flow-check-review.md +656 -20
  41. package/prompts/desktop/flow-check-test.md +526 -14
  42. package/prompts/desktop/flow-check.md +725 -67
  43. package/prompts/desktop/flow-commit.md +88 -119
  44. package/prompts/desktop/flow-docs-sync.md +354 -354
  45. package/prompts/desktop/flow-finish.md +910 -0
  46. package/prompts/desktop/flow-release.md +662 -0
  47. package/prompts/desktop/flow-work-feature.md +61 -61
  48. package/prompts/desktop/flow-work-fix.md +46 -46
  49. package/prompts/desktop/flow-work-refactor.md +48 -48
  50. package/prompts/desktop/flow-work-resume.md +34 -34
  51. package/prompts/desktop/flow-work.md +1202 -1390
  52. package/prompts/frontend/flow-build-phase-0.md +425 -425
  53. package/prompts/frontend/flow-build-phase-1.md +626 -626
  54. package/prompts/frontend/flow-build-phase-10.md +33 -33
  55. package/prompts/frontend/flow-build-phase-2.md +573 -573
  56. package/prompts/frontend/flow-build-phase-3.md +782 -782
  57. package/prompts/frontend/flow-build-phase-4.md +554 -554
  58. package/prompts/frontend/flow-build-phase-5.md +703 -703
  59. package/prompts/frontend/flow-build-phase-6.md +524 -524
  60. package/prompts/frontend/flow-build-phase-7.md +1001 -1001
  61. package/prompts/frontend/flow-build-phase-8.md +872 -872
  62. package/prompts/frontend/flow-build-phase-9.md +94 -94
  63. package/prompts/frontend/flow-build.md +137 -137
  64. package/prompts/frontend/flow-check-review.md +656 -20
  65. package/prompts/frontend/flow-check-test.md +526 -14
  66. package/prompts/frontend/flow-check.md +725 -67
  67. package/prompts/frontend/flow-commit.md +88 -119
  68. package/prompts/frontend/flow-docs-sync.md +550 -550
  69. package/prompts/frontend/flow-finish.md +910 -0
  70. package/prompts/frontend/flow-release.md +519 -0
  71. package/prompts/frontend/flow-work-api.md +1540 -0
  72. package/prompts/frontend/flow-work-feature.md +61 -61
  73. package/prompts/frontend/flow-work-fix.md +38 -38
  74. package/prompts/frontend/flow-work-refactor.md +48 -48
  75. package/prompts/frontend/flow-work-resume.md +34 -34
  76. package/prompts/frontend/flow-work.md +1583 -1320
  77. package/prompts/mobile/flow-build-phase-0.md +425 -425
  78. package/prompts/mobile/flow-build-phase-1.md +626 -626
  79. package/prompts/mobile/flow-build-phase-10.md +32 -32
  80. package/prompts/mobile/flow-build-phase-2.md +573 -573
  81. package/prompts/mobile/flow-build-phase-3.md +782 -782
  82. package/prompts/mobile/flow-build-phase-4.md +554 -554
  83. package/prompts/mobile/flow-build-phase-5.md +703 -703
  84. package/prompts/mobile/flow-build-phase-6.md +524 -524
  85. package/prompts/mobile/flow-build-phase-7.md +1001 -1001
  86. package/prompts/mobile/flow-build-phase-8.md +888 -888
  87. package/prompts/mobile/flow-build-phase-9.md +90 -90
  88. package/prompts/mobile/flow-build.md +135 -135
  89. package/prompts/mobile/flow-check-review.md +656 -20
  90. package/prompts/mobile/flow-check-test.md +526 -14
  91. package/prompts/mobile/flow-check.md +725 -67
  92. package/prompts/mobile/flow-commit.md +88 -119
  93. package/prompts/mobile/flow-docs-sync.md +620 -620
  94. package/prompts/mobile/flow-finish.md +910 -0
  95. package/prompts/mobile/flow-release.md +751 -0
  96. package/prompts/mobile/flow-work-api.md +1493 -0
  97. package/prompts/mobile/flow-work-feature.md +61 -61
  98. package/prompts/mobile/flow-work-fix.md +46 -46
  99. package/prompts/mobile/flow-work-refactor.md +48 -48
  100. package/prompts/mobile/flow-work-resume.md +34 -34
  101. package/prompts/mobile/flow-work.md +1593 -1329
  102. package/prompts/shared/mermaid-guidelines.md +102 -102
  103. package/prompts/shared/scope-levels.md +114 -114
  104. package/prompts/shared/smart-skip-preflight.md +214 -214
  105. package/prompts/shared/story-points.md +55 -55
  106. package/prompts/shared/task-format.md +74 -74
  107. package/prompts/shared/task-summary-template.md +277 -277
  108. package/templates/AGENT.template.md +443 -443
  109. package/templates/backend/.clauderules.template +112 -112
  110. package/templates/backend/.cursorrules.template +102 -102
  111. package/templates/backend/README.template.md +2 -2
  112. package/templates/backend/ai-instructions.template.md +2 -2
  113. package/templates/backend/copilot-instructions.template.md +2 -2
  114. package/templates/backend/docs/api.template.md +320 -320
  115. package/templates/backend/docs/business-flows.template.md +97 -97
  116. package/templates/backend/docs/code-standards.template.md +2 -2
  117. package/templates/backend/docs/contributing.template.md +3 -3
  118. package/templates/backend/docs/data-model.template.md +520 -520
  119. package/templates/backend/docs/testing.template.md +2 -2
  120. package/templates/backend/project-brief.template.md +2 -2
  121. package/templates/backend/specs/configuration.template.md +2 -2
  122. package/templates/backend/specs/security.template.md +2 -2
  123. package/templates/desktop/.clauderules.template +112 -112
  124. package/templates/desktop/.cursorrules.template +102 -102
  125. package/templates/desktop/README.template.md +170 -170
  126. package/templates/desktop/ai-instructions.template.md +366 -366
  127. package/templates/desktop/copilot-instructions.template.md +140 -140
  128. package/templates/desktop/docs/docs/api.template.md +320 -320
  129. package/templates/desktop/docs/docs/architecture.template.md +724 -724
  130. package/templates/desktop/docs/docs/business-flows.template.md +102 -102
  131. package/templates/desktop/docs/docs/code-standards.template.md +792 -792
  132. package/templates/desktop/docs/docs/contributing.template.md +149 -149
  133. package/templates/desktop/docs/docs/data-model.template.md +520 -520
  134. package/templates/desktop/docs/docs/operations.template.md +720 -720
  135. package/templates/desktop/docs/docs/testing.template.md +722 -722
  136. package/templates/desktop/project-brief.template.md +150 -150
  137. package/templates/desktop/specs/specs/configuration.template.md +121 -121
  138. package/templates/desktop/specs/specs/security.template.md +392 -392
  139. package/templates/frontend/README.template.md +2 -2
  140. package/templates/frontend/ai-instructions.template.md +2 -2
  141. package/templates/frontend/docs/api-integration.template.md +362 -362
  142. package/templates/frontend/docs/components.template.md +2 -2
  143. package/templates/frontend/docs/error-handling.template.md +360 -360
  144. package/templates/frontend/docs/operations.template.md +107 -107
  145. package/templates/frontend/docs/performance.template.md +124 -124
  146. package/templates/frontend/docs/pwa.template.md +119 -119
  147. package/templates/frontend/docs/state-management.template.md +2 -2
  148. package/templates/frontend/docs/styling.template.md +2 -2
  149. package/templates/frontend/docs/testing.template.md +2 -2
  150. package/templates/frontend/project-brief.template.md +2 -2
  151. package/templates/frontend/specs/accessibility.template.md +95 -95
  152. package/templates/frontend/specs/configuration.template.md +2 -2
  153. package/templates/frontend/specs/security.template.md +175 -175
  154. package/templates/fullstack/README.template.md +252 -252
  155. package/templates/fullstack/ai-instructions.template.md +444 -444
  156. package/templates/fullstack/project-brief.template.md +157 -157
  157. package/templates/fullstack/specs/configuration.template.md +340 -340
  158. package/templates/mobile/README.template.md +167 -167
  159. package/templates/mobile/ai-instructions.template.md +196 -196
  160. package/templates/mobile/docs/app-store.template.md +135 -135
  161. package/templates/mobile/docs/architecture.template.md +63 -63
  162. package/templates/mobile/docs/native-features.template.md +94 -94
  163. package/templates/mobile/docs/navigation.template.md +59 -59
  164. package/templates/mobile/docs/offline-strategy.template.md +65 -65
  165. package/templates/mobile/docs/permissions.template.md +56 -56
  166. package/templates/mobile/docs/state-management.template.md +85 -85
  167. package/templates/mobile/docs/testing.template.md +109 -109
  168. package/templates/mobile/project-brief.template.md +69 -69
  169. package/templates/mobile/specs/build-configuration.template.md +91 -91
  170. package/templates/mobile/specs/deployment.template.md +92 -92
  171. package/templates/work.template.md +47 -47
@@ -1,792 +1,792 @@
1
- # Code Standards
2
-
3
- > Coding conventions, quality rules, and best practices for {{PROJECT_NAME}}
4
- ---
5
- ## 🎨 Code Style
6
-
7
- ### Formatting
8
-
9
- **Indentation:** {{INDENTATION}}
10
-
11
- **Quote Style:** {{QUOTE_STYLE}}
12
-
13
- **Line Length:** {{LINE_LENGTH}} characters max
14
-
15
- **Semicolons:** {{SEMICOLON_POLICY}}
16
-
17
- **Trailing Commas:** {{TRAILING_COMMA_POLICY}}
18
-
19
- ### Formatter
20
-
21
- **Tool:** {{FORMATTER}}
22
-
23
- **Configuration:** `{{FORMATTER_CONFIG_FILE}}`
24
-
25
- **Auto-format:** {{AUTO_FORMAT_POLICY}}
26
-
27
- ```bash
28
- # Format code
29
- {{FORMAT_COMMAND}}
30
- ```
31
- ---
32
- ## 📝 Naming Conventions
33
-
34
- ### Files
35
-
36
- **Style:** {{FILE_NAMING_STYLE}}
37
-
38
- **Examples:**
39
- ```
40
- {{FILE_NAMING_EXAMPLES}}
41
- ```
42
-
43
- ### Classes and Interfaces
44
-
45
- **Style:** PascalCase
46
-
47
- **Examples:**
48
- ```{{LANGUAGE}}
49
- class UserService {}
50
- class OrderRepository {}
51
- interface {{INTERFACE_EXAMPLE}} {}
52
- ```
53
-
54
- {{#IF TYPESCRIPT}}
55
- ### Interfaces
56
-
57
- **Convention:** {{INTERFACE_NAMING_CONVENTION}}
58
-
59
- **Examples:**
60
- ```typescript
61
- {{#IF I_PREFIX}}
62
- interface IUserService {}
63
- interface IRepository<T> {}
64
- {{ELSE}}
65
- interface UserService {}
66
- interface Repository<T> {}
67
- {{/IF}}
68
- ```
69
- {{/IF}}
70
-
71
- ### Functions and Methods
72
-
73
- **Style:** camelCase
74
-
75
- **Examples:**
76
- ```{{LANGUAGE}}
77
- function getUserById(id: string) {}
78
- async function createOrder(data: OrderDto) {}
79
- ```
80
-
81
- ### Variables
82
-
83
- **Style:** camelCase
84
-
85
- **Examples:**
86
- ```{{LANGUAGE}}
87
- const userName = 'John';
88
- let orderTotal = 0;
89
- const activeUsers = [];
90
- ```
91
-
92
- ### Constants
93
-
94
- **Style:** UPPER_SNAKE_CASE
95
-
96
- **Examples:**
97
- ```{{LANGUAGE}}
98
- const MAX_RETRY_ATTEMPTS = 3;
99
- const API_BASE_URL = 'https://api.example.com';
100
- const DEFAULT_PAGE_SIZE = 20;
101
- ```
102
-
103
- ### Boolean Variables
104
-
105
- **Convention:** Use is/has/can/should prefix
106
-
107
- **Examples:**
108
- ```{{LANGUAGE}}
109
- const isActive = true;
110
- const hasPermission = false;
111
- const canEdit = checkPermissions();
112
- const shouldRefresh = false;
113
- ```
114
- ---
115
- ## 🏗️ Code Organization
116
-
117
- ### File Structure
118
-
119
- **Strategy:** {{FILE_ORGANIZATION_STRATEGY}}
120
-
121
- {{#IF FEATURE_BASED}}
122
- ### Feature-Based Example
123
-
124
- ```
125
- src/
126
- users/
127
- user.controller.ts
128
- user.service.ts
129
- user.repository.ts
130
- user.dto.ts
131
- user.entity.ts
132
- user.spec.ts
133
- index.ts
134
- ```
135
-
136
- **Benefits:**
137
- - Clear feature boundaries
138
- - Easy to locate related code
139
- - Supports team ownership
140
- - Facilitates modular architecture
141
-
142
- {{/IF}}
143
-
144
- {{#IF LAYER_BASED}}
145
- ### Layer-Based Example
146
-
147
- ```
148
- src/
149
- controllers/
150
- user.controller.ts
151
- order.controller.ts
152
- services/
153
- user.service.ts
154
- order.service.ts
155
- repositories/
156
- user.repository.ts
157
- order.repository.ts
158
- ```
159
-
160
- {{/IF}}
161
-
162
- ### Import Organization
163
-
164
- **Order:**
165
- {{#EACH IMPORT_ORDER}}
166
- {{INDEX}}. {{IMPORT_GROUP_DESCRIPTION}}
167
- {{/EACH}}
168
-
169
- **Example:**
170
- ```{{LANGUAGE}}
171
- {{IMPORT_ORDER_EXAMPLE}}
172
- ```
173
-
174
- {{#IF PATH_ALIASES}}
175
- ### Path Aliases
176
-
177
- **Enabled:** Yes
178
-
179
- **Configuration:**
180
- ```json
181
- {
182
- "paths": {
183
- "@/*": ["src/*"],
184
- "@/controllers/*": ["src/controllers/*"],
185
- "@/services/*": ["src/services/*"],
186
- "@/utils/*": ["src/utils/*"]
187
- }
188
- }
189
- ```
190
-
191
- **Usage:**
192
- ```{{LANGUAGE}}
193
- import { UserService } from '@/services/user.service';
194
- import { validateEmail } from '@/utils/validation';
195
- ```
196
-
197
- {{/IF}}
198
- ---
199
- ## {{#IF TYPESCRIPT}}📘 TypeScript Rules{{ELSE}}📘 Type System{{/IF}}
200
-
201
- {{#IF TYPESCRIPT}}
202
- ### Strict Mode
203
-
204
- **Enabled:** {{STRICT_MODE}}
205
-
206
- **Strict Checks:**
207
- - `strict`: {{STRICT}}
208
- - `noImplicitAny`: {{NO_IMPLICIT_ANY}}
209
- - `strictNullChecks`: {{STRICT_NULL_CHECKS}}
210
- - `strictFunctionTypes`: {{STRICT_FUNCTION_TYPES}}
211
- - `strictPropertyInitialization`: {{STRICT_PROPERTY_INIT}}
212
-
213
- ### Type Rules
214
-
215
- - ✅ **Always** specify return types for functions
216
- - ✅ **Always** use interfaces for object shapes
217
- - ✅ **Always** use proper types (never `any`)
218
- - ❌ **Never** use `any` - use `unknown` if type is truly unknown
219
- - ❌ **Never** disable TypeScript errors with `@ts-ignore`
220
- - ✅ **Use** `@ts-expect-error` with comment if absolutely necessary
221
-
222
- ### Type Preferences
223
-
224
- **Interfaces vs Types:**
225
- {{TYPE_VS_INTERFACE_PREFERENCE}}
226
-
227
- **Example:**
228
- ```typescript
229
- // Interfaces for object shapes
230
- interface User {
231
- id: string;
232
- email: string;
233
- name: string;
234
- }
235
-
236
- // Types for unions, intersections
237
- type Status = 'pending' | 'active' | 'suspended';
238
- type UserWithStatus = User & { status: Status };
239
- ```
240
-
241
- ### Generics
242
-
243
- **When to use:**
244
- - Reusable components
245
- - Type-safe collections
246
- - Abstract data structures
247
-
248
- **Example:**
249
- ```typescript
250
- class Repository<T> {
251
- async findById(id: string): Promise<T | null> {
252
- // implementation
253
- }
254
-
255
- async findAll(): Promise<T[]> {
256
- // implementation
257
- }
258
- }
259
- ```
260
-
261
- {{/IF}}
262
- ---
263
- ## 🚨 Error Handling
264
-
265
- ### Strategy
266
-
267
- {{ERROR_HANDLING_STRATEGY}}
268
-
269
- ### Custom Error Classes
270
-
271
- ```{{LANGUAGE}}
272
- {{ERROR_CLASS_EXAMPLE}}
273
- ```
274
-
275
- ### Try-Catch Pattern
276
-
277
- ```{{LANGUAGE}}
278
- {{TRY_CATCH_EXAMPLE}}
279
- ```
280
-
281
- ### Error Response Format
282
-
283
- ```json
284
- {{ERROR_RESPONSE_FORMAT}}
285
- ```
286
-
287
- ### Logging Errors
288
-
289
- ```{{LANGUAGE}}
290
- {{ERROR_LOGGING_EXAMPLE}}
291
- ```
292
- ---
293
- ## 📝 Logging Standards
294
-
295
- ### Log Levels
296
-
297
- **Hierarchy:** DEBUG < INFO < WARN < ERROR < FATAL
298
-
299
- **Usage Guidelines:**
300
- - **DEBUG**: Detailed information for debugging (development only)
301
- - **INFO**: General informational messages (request start, successful operations)
302
- - **WARN**: Warning messages (deprecated features, recoverable errors)
303
- - **ERROR**: Error messages (failed operations, exceptions)
304
- - **FATAL**: Critical errors (system failures, unrecoverable errors)
305
-
306
- **Default Level:** {{LOG_LEVEL}} ({{LOG_LEVEL_ENVIRONMENT}})
307
-
308
- ### Log Format
309
-
310
- **Format:** {{LOG_FORMAT}} ({{#IF JSON_LOGS}}Structured JSON{{ELSE}}Plain Text{{/IF}})
311
-
312
- **Structured Logging Example:**
313
- ```json
314
- {
315
- "timestamp": "2024-01-20T10:30:00Z",
316
- "level": "info",
317
- "message": "User logged in successfully",
318
- "context": {
319
- "userId": "123",
320
- "ip": "192.168.1.1",
321
- "userAgent": "Mozilla/5.0..."
322
- },
323
- "requestId": "req-abc123",
324
- "duration": 45
325
- }
326
- ```
327
-
328
- **Implementation:**
329
- ```{{LANGUAGE}}
330
- {{LOGGING_IMPLEMENTATION_EXAMPLE}}
331
- ```
332
-
333
- ### Log Context
334
-
335
- **Always Include:**
336
- - Request ID (for tracing)
337
- - User ID (if authenticated)
338
- - Timestamp
339
- - Log level
340
- - Message
341
-
342
- **Optional Context:**
343
- - IP address
344
- - User agent
345
- - Request path
346
- - Response status
347
- - Duration
348
- - Error stack traces
349
-
350
- ### Logging Best Practices
351
-
352
- ✅ **DO:**
353
- - Use structured logging (JSON format)
354
- - Include request ID for tracing
355
- - Log at appropriate levels
356
- - Include relevant context
357
- - Sanitize sensitive data (passwords, tokens, PII)
358
- - Use correlation IDs across services
359
-
360
- ❌ **DON'T:**
361
- - Log sensitive information (passwords, API keys, tokens)
362
- - Log excessive data (full request/response bodies)
363
- - Use console.log in production
364
- - Log in tight loops
365
- - Log PII without consent
366
-
367
- ### Log Aggregation
368
-
369
- **Tool:** {{LOG_AGGREGATION_TOOL}}
370
-
371
- **Retention:** {{LOG_RETENTION}} days
372
-
373
- **Search:** {{LOG_SEARCH_TOOL}}
374
-
375
- **Example Queries:**
376
- ```bash
377
- # Find errors in last hour
378
- {{LOG_ERROR_QUERY}}
379
-
380
- # Find slow requests
381
- {{LOG_SLOW_QUERY}}
382
-
383
- # Find by request ID
384
- {{LOG_REQUEST_ID_QUERY}}
385
- ```
386
- ---
387
- ## 📝 Comments and Documentation
388
-
389
- ### When to Comment
390
-
391
- ✅ **DO comment:**
392
- - Complex business logic
393
- - Non-obvious algorithms
394
- - Workarounds for bugs/limitations
395
- - TODOs and FIXMEs
396
- - Public API documentation
397
-
398
- ❌ **DON'T comment:**
399
- - Obvious code
400
- - What the code does (code should be self-explanatory)
401
- - Outdated information
402
-
403
- ### Documentation Comments
404
-
405
- **Format:** {{DOC_COMMENT_FORMAT}}
406
-
407
- {{#IF JSDOC}}
408
- **JSDoc Example:**
409
- ```typescript
410
- /**
411
- * Calculates the total price for an order including tax and discounts
412
- *
413
- * @param items - Array of order items
414
- * @param taxRate - Tax rate as decimal (e.g., 0.15 for 15%)
415
- * @param discountCode - Optional discount code
416
- * @returns Total price in cents
417
- * @throws {InvalidDiscountError} If discount code is invalid
418
- *
419
- * @example
420
- * ```typescript
421
- * const total = calculateOrderTotal(items, 0.15, 'SAVE10');
422
- * ```
423
- */
424
- async function calculateOrderTotal(
425
- items: OrderItem[],
426
- taxRate: number,
427
- discountCode?: string
428
- ): Promise<number> {
429
- // implementation
430
- }
431
- ```
432
- {{/IF}}
433
-
434
- {{#IF PYTHON_DOCSTRING}}
435
- **Python Docstring Example:**
436
- ```python
437
- def calculate_order_total(
438
- items: List[OrderItem],
439
- tax_rate: float,
440
- discount_code: Optional[str] = None
441
- ) -> int:
442
- """
443
- Calculate the total price for an order including tax and discounts.
444
-
445
- Args:
446
- items: List of order items
447
- tax_rate: Tax rate as decimal (e.g., 0.15 for 15%)
448
- discount_code: Optional discount code
449
-
450
- Returns:
451
- Total price in cents
452
-
453
- Raises:
454
- InvalidDiscountError: If discount code is invalid
455
-
456
- Example:
457
- >>> total = calculate_order_total(items, 0.15, 'SAVE10')
458
- >>> print(total)
459
- 1599
460
- """
461
- # implementation
462
- ```
463
- {{/IF}}
464
-
465
- ### Inline Comments
466
-
467
- ```{{LANGUAGE}}
468
- // GOOD: Explains WHY
469
- // Using exponential backoff to avoid overwhelming the API
470
- await retryWithBackoff(apiCall, { maxAttempts: 3 });
471
-
472
- // BAD: Explains WHAT (obvious from code)
473
- // Loop through users
474
- for (const user of users) {
475
- ```
476
-
477
- ### TODO Comments
478
-
479
- **Format:**
480
- ```{{LANGUAGE}}
481
- // TODO(username): Description of what needs to be done
482
- // FIXME(username): Description of bug that needs fixing
483
- // HACK(username): Explanation of why this hack exists
484
- ```
485
- ---
486
- ## 🧪 Code Quality Metrics
487
-
488
- ### Function Complexity
489
-
490
- **Maximum Cyclomatic Complexity:** {{MAX_COMPLEXITY}}
491
-
492
- **Maximum Function Length:** {{MAX_FUNCTION_LENGTH}} lines
493
-
494
- **Maximum Parameters:** {{MAX_PARAMETERS}}
495
-
496
- **Maximum Nesting Depth:** {{MAX_NESTING_DEPTH}} levels
497
-
498
- ### Class Complexity
499
-
500
- **Maximum Class Length:** {{MAX_CLASS_LENGTH}} lines
501
-
502
- **Maximum Methods per Class:** {{MAX_METHODS_PER_CLASS}}
503
-
504
- ### File Size
505
-
506
- **Maximum File Length:** {{MAX_FILE_LENGTH}} lines
507
-
508
- **When to split:** If file exceeds limit or has multiple responsibilities
509
- ---
510
- ## ✅ Code Quality Rules
511
-
512
- ### Functions
513
-
514
- - ✅ Functions should do ONE thing
515
- - ✅ Use descriptive names (no abbreviations)
516
- - ✅ Keep parameters to minimum (max {{MAX_PARAMETERS}})
517
- - ✅ Use parameter objects for 4+ parameters
518
- - ✅ Return early to avoid nesting
519
- - ❌ No side effects in getters
520
- - ❌ No Boolean parameters (use enums or separate methods)
521
-
522
- **Example:**
523
- ```{{LANGUAGE}}
524
- {{FUNCTION_QUALITY_EXAMPLE}}
525
- ```
526
-
527
- ### Classes
528
-
529
- - ✅ Single Responsibility Principle
530
- - ✅ Open/Closed Principle
531
- - ✅ Liskov Substitution Principle
532
- - ✅ Interface Segregation Principle
533
- - ✅ Dependency Inversion Principle
534
-
535
- ### DRY (Don't Repeat Yourself)
536
-
537
- - ✅ Extract repeated code into functions
538
- - ✅ Use loops instead of copy-paste
539
- - ✅ Create utilities for common operations
540
- - ❌ Copy-paste is a code smell
541
-
542
- ### KISS (Keep It Simple, Stupid)
543
-
544
- - ✅ Simplest solution that works
545
- - ✅ Avoid premature optimization
546
- - ✅ Readable over clever
547
- - ❌ Don't over-engineer
548
- ---
549
- ## 🔒 Security Coding Standards
550
-
551
- ### Input Validation
552
-
553
- ```{{LANGUAGE}}
554
- {{INPUT_VALIDATION_EXAMPLE}}
555
- ```
556
-
557
- ### SQL Injection Prevention
558
-
559
- ```{{LANGUAGE}}
560
- {{SQL_INJECTION_PREVENTION_EXAMPLE}}
561
- ```
562
-
563
- ### XSS Prevention
564
-
565
- ```{{LANGUAGE}}
566
- {{XSS_PREVENTION_EXAMPLE}}
567
- ```
568
-
569
- ### Secrets Management
570
-
571
- ```{{LANGUAGE}}
572
- {{SECRETS_EXAMPLE}}
573
- ```
574
- ---
575
- ## 🧹 Code Smell Detection
576
-
577
- ### Common Code Smells
578
-
579
- | Smell | Description | Solution |
580
- |-------|-------------|----------|
581
- | Long Method | Function over {{MAX_FUNCTION_LENGTH}} lines | Extract methods |
582
- | Large Class | Class over {{MAX_CLASS_LENGTH}} lines | Split responsibilities |
583
- | Long Parameter List | More than {{MAX_PARAMETERS}} parameters | Use parameter object |
584
- | Duplicate Code | Same code in multiple places | Extract to function/class |
585
- | Dead Code | Unused code | Delete it |
586
- | Magic Numbers | Unexplained constants | Use named constants |
587
- | Nested Conditionals | Deep if/else nesting | Use early returns, guard clauses |
588
- ---
589
- ## 📦 Dependency Management
590
-
591
- ### Rules
592
-
593
- - ✅ Keep dependencies up to date
594
- - ✅ Review security vulnerabilities regularly
595
- - ✅ Use exact versions in production
596
- - ❌ Don't add dependencies for simple utilities
597
- - ❌ Don't use deprecated packages
598
-
599
- ### Checking for Updates
600
-
601
- ```bash
602
- {{DEPENDENCY_CHECK_COMMAND}}
603
- ```
604
-
605
- ### Security Audit
606
-
607
- ```bash
608
- {{SECURITY_AUDIT_COMMAND}}
609
- ```
610
- ---
611
- ## 🔧 Linting
612
-
613
- **Tool:** {{LINTER}}
614
-
615
- **Configuration:** `{{LINTER_CONFIG_FILE}}`
616
-
617
- ### Running Linter
618
-
619
- ```bash
620
- # Check for issues
621
- {{LINT_COMMAND}}
622
-
623
- # Auto-fix issues
624
- {{LINT_FIX_COMMAND}}
625
- ```
626
-
627
- ### Critical Rules
628
-
629
- {{#EACH LINT_RULE}}
630
- - **{{RULE_NAME}}**: {{RULE_DESCRIPTION}}
631
- {{/EACH}}
632
- ---
633
- ## ✍️ Git Commit Standards
634
-
635
- ### Commit Message Format
636
-
637
- **Standard:** {{COMMIT_STANDARD}}
638
-
639
- {{#IF CONVENTIONAL_COMMITS}}
640
- ### Conventional Commits
641
-
642
- **Format:**
643
- ```
644
- <type>(<scope>): <subject>
645
-
646
- <body>
647
-
648
- <footer>
649
- ```
650
-
651
- **Types:**
652
- - `feat`: New feature
653
- - `fix`: Bug fix
654
- - `docs`: Documentation changes
655
- - `style`: Code style changes (formatting, etc.)
656
- - `refactor`: Code refactoring
657
- - `test`: Adding/updating tests
658
- - `chore`: Maintenance tasks
659
-
660
- **Example:**
661
- ```
662
- feat(auth): add JWT refresh token rotation
663
-
664
- - Implement token rotation on every refresh request
665
- - Store refresh tokens in Redis with expiration
666
- - Add cleanup job for expired tokens
667
-
668
- Closes #123
669
- ```
670
-
671
- {{/IF}}
672
-
673
- ### Branch Naming
674
-
675
- **Convention:** {{BRANCH_NAMING_CONVENTION}}
676
-
677
- **Examples:**
678
- ```
679
- {{BRANCH_NAMING_EXAMPLES}}
680
- ```
681
-
682
- ### Commit Size
683
-
684
- - ✅ Small, focused commits
685
- - ✅ One logical change per commit
686
- - ❌ Don't mix refactoring with feature changes
687
- - ❌ Don't commit broken code
688
- ---
689
- ## 📋 Code Review Checklist
690
-
691
- ### Before Requesting Review
692
-
693
- - [ ] Code follows all standards in this document
694
- - [ ] Tests written and passing ({{MIN_COVERAGE}}%+ coverage)
695
- - [ ] No linting errors
696
- - [ ] No console.logs or debugger statements
697
- - [ ] Documentation updated (if needed)
698
- - [ ] Self-reviewed the changes
699
- - [ ] Commit messages follow standard
700
-
701
- ### Reviewer Checklist
702
-
703
- - [ ] Code is understandable
704
- - [ ] Logic is correct
705
- - [ ] Edge cases are handled
706
- - [ ] Error handling is appropriate
707
- - [ ] Tests are comprehensive
708
- - [ ] No security vulnerabilities
709
- - [ ] Performance is acceptable
710
- - [ ] Follows architecture patterns
711
- ---
712
- ## 🎯 Code Examples
713
-
714
- ### Controller Example
715
-
716
- ```{{LANGUAGE}}
717
- {{CONTROLLER_EXAMPLE}}
718
- ```
719
-
720
- ### Service Example
721
-
722
- ```{{LANGUAGE}}
723
- {{SERVICE_EXAMPLE}}
724
- ```
725
-
726
- ### Repository Example
727
-
728
- ```{{LANGUAGE}}
729
- {{REPOSITORY_EXAMPLE}}
730
- ```
731
-
732
- ### DTO Example
733
-
734
- ```{{LANGUAGE}}
735
- {{DTO_EXAMPLE}}
736
- ```
737
-
738
- ### Test Example
739
-
740
- ```{{LANGUAGE}}
741
- {{TEST_EXAMPLE}}
742
- ```
743
- ---
744
- ## 🚀 Performance Guidelines
745
-
746
- ### Database
747
-
748
- - ✅ Use indexes on foreign keys and frequently queried columns
749
- - ✅ Use `select` to specify columns, not `SELECT *`
750
- - ✅ Use pagination for large result sets
751
- - ✅ Use database transactions for multi-step operations
752
- - ❌ Avoid N+1 queries (use joins or batch queries)
753
- - ❌ Don't query in loops
754
-
755
- ### API
756
-
757
- - ✅ Implement caching for expensive operations
758
- - ✅ Use compression for large responses
759
- - ✅ Implement rate limiting
760
- - ✅ Use async/await for I/O operations
761
- - ❌ Don't block the event loop (Node.js)
762
- - ❌ Don't return excessive data
763
-
764
- ### Memory
765
-
766
- - ✅ Clean up event listeners
767
- - ✅ Close database connections
768
- - ✅ Stream large files
769
- - ❌ Don't load entire files into memory
770
- - ❌ Don't create memory leaks
771
- ---
772
- ## 📚 Resources
773
-
774
- ### Official Docs
775
-
776
- {{#EACH OFFICIAL_DOC}}
777
- - [{{DOC_NAME}}]({{DOC_URL}})
778
- {{/EACH}}
779
-
780
- ### Style Guides
781
-
782
- {{#EACH STYLE_GUIDE}}
783
- - [{{GUIDE_NAME}}]({{GUIDE_URL}})
784
- {{/EACH}}
785
- ---
786
- **Document Version:** 1.0
787
-
788
- **Last Updated:** {{GENERATION_DATE}}
789
-
790
- **Generated by:** AI Flow v1.0.0
791
-
792
-
1
+ # Code Standards
2
+
3
+ > Coding conventions, quality rules, and best practices for {{PROJECT_NAME}}
4
+ ---
5
+ ## 🎨 Code Style
6
+
7
+ ### Formatting
8
+
9
+ **Indentation:** {{INDENTATION}}
10
+
11
+ **Quote Style:** {{QUOTE_STYLE}}
12
+
13
+ **Line Length:** {{LINE_LENGTH}} characters max
14
+
15
+ **Semicolons:** {{SEMICOLON_POLICY}}
16
+
17
+ **Trailing Commas:** {{TRAILING_COMMA_POLICY}}
18
+
19
+ ### Formatter
20
+
21
+ **Tool:** {{FORMATTER}}
22
+
23
+ **Configuration:** `{{FORMATTER_CONFIG_FILE}}`
24
+
25
+ **Auto-format:** {{AUTO_FORMAT_POLICY}}
26
+
27
+ ```bash
28
+ # Format code
29
+ {{FORMAT_COMMAND}}
30
+ ```
31
+ ---
32
+ ## 📝 Naming Conventions
33
+
34
+ ### Files
35
+
36
+ **Style:** {{FILE_NAMING_STYLE}}
37
+
38
+ **Examples:**
39
+ ```
40
+ {{FILE_NAMING_EXAMPLES}}
41
+ ```
42
+
43
+ ### Classes and Interfaces
44
+
45
+ **Style:** PascalCase
46
+
47
+ **Examples:**
48
+ ```{{LANGUAGE}}
49
+ class UserService {}
50
+ class OrderRepository {}
51
+ interface {{INTERFACE_EXAMPLE}} {}
52
+ ```
53
+
54
+ {{#IF TYPESCRIPT}}
55
+ ### Interfaces
56
+
57
+ **Convention:** {{INTERFACE_NAMING_CONVENTION}}
58
+
59
+ **Examples:**
60
+ ```typescript
61
+ {{#IF I_PREFIX}}
62
+ interface IUserService {}
63
+ interface IRepository<T> {}
64
+ {{ELSE}}
65
+ interface UserService {}
66
+ interface Repository<T> {}
67
+ {{/IF}}
68
+ ```
69
+ {{/IF}}
70
+
71
+ ### Functions and Methods
72
+
73
+ **Style:** camelCase
74
+
75
+ **Examples:**
76
+ ```{{LANGUAGE}}
77
+ function getUserById(id: string) {}
78
+ async function createOrder(data: OrderDto) {}
79
+ ```
80
+
81
+ ### Variables
82
+
83
+ **Style:** camelCase
84
+
85
+ **Examples:**
86
+ ```{{LANGUAGE}}
87
+ const userName = 'John';
88
+ let orderTotal = 0;
89
+ const activeUsers = [];
90
+ ```
91
+
92
+ ### Constants
93
+
94
+ **Style:** UPPER_SNAKE_CASE
95
+
96
+ **Examples:**
97
+ ```{{LANGUAGE}}
98
+ const MAX_RETRY_ATTEMPTS = 3;
99
+ const API_BASE_URL = 'https://api.example.com';
100
+ const DEFAULT_PAGE_SIZE = 20;
101
+ ```
102
+
103
+ ### Boolean Variables
104
+
105
+ **Convention:** Use is/has/can/should prefix
106
+
107
+ **Examples:**
108
+ ```{{LANGUAGE}}
109
+ const isActive = true;
110
+ const hasPermission = false;
111
+ const canEdit = checkPermissions();
112
+ const shouldRefresh = false;
113
+ ```
114
+ ---
115
+ ## 🏗️ Code Organization
116
+
117
+ ### File Structure
118
+
119
+ **Strategy:** {{FILE_ORGANIZATION_STRATEGY}}
120
+
121
+ {{#IF FEATURE_BASED}}
122
+ ### Feature-Based Example
123
+
124
+ ```
125
+ src/
126
+ users/
127
+ user.controller.ts
128
+ user.service.ts
129
+ user.repository.ts
130
+ user.dto.ts
131
+ user.entity.ts
132
+ user.spec.ts
133
+ index.ts
134
+ ```
135
+
136
+ **Benefits:**
137
+ - Clear feature boundaries
138
+ - Easy to locate related code
139
+ - Supports team ownership
140
+ - Facilitates modular architecture
141
+
142
+ {{/IF}}
143
+
144
+ {{#IF LAYER_BASED}}
145
+ ### Layer-Based Example
146
+
147
+ ```
148
+ src/
149
+ controllers/
150
+ user.controller.ts
151
+ order.controller.ts
152
+ services/
153
+ user.service.ts
154
+ order.service.ts
155
+ repositories/
156
+ user.repository.ts
157
+ order.repository.ts
158
+ ```
159
+
160
+ {{/IF}}
161
+
162
+ ### Import Organization
163
+
164
+ **Order:**
165
+ {{#EACH IMPORT_ORDER}}
166
+ {{INDEX}}. {{IMPORT_GROUP_DESCRIPTION}}
167
+ {{/EACH}}
168
+
169
+ **Example:**
170
+ ```{{LANGUAGE}}
171
+ {{IMPORT_ORDER_EXAMPLE}}
172
+ ```
173
+
174
+ {{#IF PATH_ALIASES}}
175
+ ### Path Aliases
176
+
177
+ **Enabled:** Yes
178
+
179
+ **Configuration:**
180
+ ```json
181
+ {
182
+ "paths": {
183
+ "@/*": ["src/*"],
184
+ "@/controllers/*": ["src/controllers/*"],
185
+ "@/services/*": ["src/services/*"],
186
+ "@/utils/*": ["src/utils/*"]
187
+ }
188
+ }
189
+ ```
190
+
191
+ **Usage:**
192
+ ```{{LANGUAGE}}
193
+ import { UserService } from '@/services/user.service';
194
+ import { validateEmail } from '@/utils/validation';
195
+ ```
196
+
197
+ {{/IF}}
198
+ ---
199
+ ## {{#IF TYPESCRIPT}}📘 TypeScript Rules{{ELSE}}📘 Type System{{/IF}}
200
+
201
+ {{#IF TYPESCRIPT}}
202
+ ### Strict Mode
203
+
204
+ **Enabled:** {{STRICT_MODE}}
205
+
206
+ **Strict Checks:**
207
+ - `strict`: {{STRICT}}
208
+ - `noImplicitAny`: {{NO_IMPLICIT_ANY}}
209
+ - `strictNullChecks`: {{STRICT_NULL_CHECKS}}
210
+ - `strictFunctionTypes`: {{STRICT_FUNCTION_TYPES}}
211
+ - `strictPropertyInitialization`: {{STRICT_PROPERTY_INIT}}
212
+
213
+ ### Type Rules
214
+
215
+ - ✅ **Always** specify return types for functions
216
+ - ✅ **Always** use interfaces for object shapes
217
+ - ✅ **Always** use proper types (never `any`)
218
+ - ❌ **Never** use `any` - use `unknown` if type is truly unknown
219
+ - ❌ **Never** disable TypeScript errors with `@ts-ignore`
220
+ - ✅ **Use** `@ts-expect-error` with comment if absolutely necessary
221
+
222
+ ### Type Preferences
223
+
224
+ **Interfaces vs Types:**
225
+ {{TYPE_VS_INTERFACE_PREFERENCE}}
226
+
227
+ **Example:**
228
+ ```typescript
229
+ // Interfaces for object shapes
230
+ interface User {
231
+ id: string;
232
+ email: string;
233
+ name: string;
234
+ }
235
+
236
+ // Types for unions, intersections
237
+ type Status = 'pending' | 'active' | 'suspended';
238
+ type UserWithStatus = User & { status: Status };
239
+ ```
240
+
241
+ ### Generics
242
+
243
+ **When to use:**
244
+ - Reusable components
245
+ - Type-safe collections
246
+ - Abstract data structures
247
+
248
+ **Example:**
249
+ ```typescript
250
+ class Repository<T> {
251
+ async findById(id: string): Promise<T | null> {
252
+ // implementation
253
+ }
254
+
255
+ async findAll(): Promise<T[]> {
256
+ // implementation
257
+ }
258
+ }
259
+ ```
260
+
261
+ {{/IF}}
262
+ ---
263
+ ## 🚨 Error Handling
264
+
265
+ ### Strategy
266
+
267
+ {{ERROR_HANDLING_STRATEGY}}
268
+
269
+ ### Custom Error Classes
270
+
271
+ ```{{LANGUAGE}}
272
+ {{ERROR_CLASS_EXAMPLE}}
273
+ ```
274
+
275
+ ### Try-Catch Pattern
276
+
277
+ ```{{LANGUAGE}}
278
+ {{TRY_CATCH_EXAMPLE}}
279
+ ```
280
+
281
+ ### Error Response Format
282
+
283
+ ```json
284
+ {{ERROR_RESPONSE_FORMAT}}
285
+ ```
286
+
287
+ ### Logging Errors
288
+
289
+ ```{{LANGUAGE}}
290
+ {{ERROR_LOGGING_EXAMPLE}}
291
+ ```
292
+ ---
293
+ ## 📝 Logging Standards
294
+
295
+ ### Log Levels
296
+
297
+ **Hierarchy:** DEBUG < INFO < WARN < ERROR < FATAL
298
+
299
+ **Usage Guidelines:**
300
+ - **DEBUG**: Detailed information for debugging (development only)
301
+ - **INFO**: General informational messages (request start, successful operations)
302
+ - **WARN**: Warning messages (deprecated features, recoverable errors)
303
+ - **ERROR**: Error messages (failed operations, exceptions)
304
+ - **FATAL**: Critical errors (system failures, unrecoverable errors)
305
+
306
+ **Default Level:** {{LOG_LEVEL}} ({{LOG_LEVEL_ENVIRONMENT}})
307
+
308
+ ### Log Format
309
+
310
+ **Format:** {{LOG_FORMAT}} ({{#IF JSON_LOGS}}Structured JSON{{ELSE}}Plain Text{{/IF}})
311
+
312
+ **Structured Logging Example:**
313
+ ```json
314
+ {
315
+ "timestamp": "2024-01-20T10:30:00Z",
316
+ "level": "info",
317
+ "message": "User logged in successfully",
318
+ "context": {
319
+ "userId": "123",
320
+ "ip": "192.168.1.1",
321
+ "userAgent": "Mozilla/5.0..."
322
+ },
323
+ "requestId": "req-abc123",
324
+ "duration": 45
325
+ }
326
+ ```
327
+
328
+ **Implementation:**
329
+ ```{{LANGUAGE}}
330
+ {{LOGGING_IMPLEMENTATION_EXAMPLE}}
331
+ ```
332
+
333
+ ### Log Context
334
+
335
+ **Always Include:**
336
+ - Request ID (for tracing)
337
+ - User ID (if authenticated)
338
+ - Timestamp
339
+ - Log level
340
+ - Message
341
+
342
+ **Optional Context:**
343
+ - IP address
344
+ - User agent
345
+ - Request path
346
+ - Response status
347
+ - Duration
348
+ - Error stack traces
349
+
350
+ ### Logging Best Practices
351
+
352
+ ✅ **DO:**
353
+ - Use structured logging (JSON format)
354
+ - Include request ID for tracing
355
+ - Log at appropriate levels
356
+ - Include relevant context
357
+ - Sanitize sensitive data (passwords, tokens, PII)
358
+ - Use correlation IDs across services
359
+
360
+ ❌ **DON'T:**
361
+ - Log sensitive information (passwords, API keys, tokens)
362
+ - Log excessive data (full request/response bodies)
363
+ - Use console.log in production
364
+ - Log in tight loops
365
+ - Log PII without consent
366
+
367
+ ### Log Aggregation
368
+
369
+ **Tool:** {{LOG_AGGREGATION_TOOL}}
370
+
371
+ **Retention:** {{LOG_RETENTION}} days
372
+
373
+ **Search:** {{LOG_SEARCH_TOOL}}
374
+
375
+ **Example Queries:**
376
+ ```bash
377
+ # Find errors in last hour
378
+ {{LOG_ERROR_QUERY}}
379
+
380
+ # Find slow requests
381
+ {{LOG_SLOW_QUERY}}
382
+
383
+ # Find by request ID
384
+ {{LOG_REQUEST_ID_QUERY}}
385
+ ```
386
+ ---
387
+ ## 📝 Comments and Documentation
388
+
389
+ ### When to Comment
390
+
391
+ ✅ **DO comment:**
392
+ - Complex business logic
393
+ - Non-obvious algorithms
394
+ - Workarounds for bugs/limitations
395
+ - TODOs and FIXMEs
396
+ - Public API documentation
397
+
398
+ ❌ **DON'T comment:**
399
+ - Obvious code
400
+ - What the code does (code should be self-explanatory)
401
+ - Outdated information
402
+
403
+ ### Documentation Comments
404
+
405
+ **Format:** {{DOC_COMMENT_FORMAT}}
406
+
407
+ {{#IF JSDOC}}
408
+ **JSDoc Example:**
409
+ ```typescript
410
+ /**
411
+ * Calculates the total price for an order including tax and discounts
412
+ *
413
+ * @param items - Array of order items
414
+ * @param taxRate - Tax rate as decimal (e.g., 0.15 for 15%)
415
+ * @param discountCode - Optional discount code
416
+ * @returns Total price in cents
417
+ * @throws {InvalidDiscountError} If discount code is invalid
418
+ *
419
+ * @example
420
+ * ```typescript
421
+ * const total = calculateOrderTotal(items, 0.15, 'SAVE10');
422
+ * ```
423
+ */
424
+ async function calculateOrderTotal(
425
+ items: OrderItem[],
426
+ taxRate: number,
427
+ discountCode?: string
428
+ ): Promise<number> {
429
+ // implementation
430
+ }
431
+ ```
432
+ {{/IF}}
433
+
434
+ {{#IF PYTHON_DOCSTRING}}
435
+ **Python Docstring Example:**
436
+ ```python
437
+ def calculate_order_total(
438
+ items: List[OrderItem],
439
+ tax_rate: float,
440
+ discount_code: Optional[str] = None
441
+ ) -> int:
442
+ """
443
+ Calculate the total price for an order including tax and discounts.
444
+
445
+ Args:
446
+ items: List of order items
447
+ tax_rate: Tax rate as decimal (e.g., 0.15 for 15%)
448
+ discount_code: Optional discount code
449
+
450
+ Returns:
451
+ Total price in cents
452
+
453
+ Raises:
454
+ InvalidDiscountError: If discount code is invalid
455
+
456
+ Example:
457
+ >>> total = calculate_order_total(items, 0.15, 'SAVE10')
458
+ >>> print(total)
459
+ 1599
460
+ """
461
+ # implementation
462
+ ```
463
+ {{/IF}}
464
+
465
+ ### Inline Comments
466
+
467
+ ```{{LANGUAGE}}
468
+ // GOOD: Explains WHY
469
+ // Using exponential backoff to avoid overwhelming the API
470
+ await retryWithBackoff(apiCall, { maxAttempts: 3 });
471
+
472
+ // BAD: Explains WHAT (obvious from code)
473
+ // Loop through users
474
+ for (const user of users) {
475
+ ```
476
+
477
+ ### TODO Comments
478
+
479
+ **Format:**
480
+ ```{{LANGUAGE}}
481
+ // TODO(username): Description of what needs to be done
482
+ // FIXME(username): Description of bug that needs fixing
483
+ // HACK(username): Explanation of why this hack exists
484
+ ```
485
+ ---
486
+ ## 🧪 Code Quality Metrics
487
+
488
+ ### Function Complexity
489
+
490
+ **Maximum Cyclomatic Complexity:** {{MAX_COMPLEXITY}}
491
+
492
+ **Maximum Function Length:** {{MAX_FUNCTION_LENGTH}} lines
493
+
494
+ **Maximum Parameters:** {{MAX_PARAMETERS}}
495
+
496
+ **Maximum Nesting Depth:** {{MAX_NESTING_DEPTH}} levels
497
+
498
+ ### Class Complexity
499
+
500
+ **Maximum Class Length:** {{MAX_CLASS_LENGTH}} lines
501
+
502
+ **Maximum Methods per Class:** {{MAX_METHODS_PER_CLASS}}
503
+
504
+ ### File Size
505
+
506
+ **Maximum File Length:** {{MAX_FILE_LENGTH}} lines
507
+
508
+ **When to split:** If file exceeds limit or has multiple responsibilities
509
+ ---
510
+ ## ✅ Code Quality Rules
511
+
512
+ ### Functions
513
+
514
+ - ✅ Functions should do ONE thing
515
+ - ✅ Use descriptive names (no abbreviations)
516
+ - ✅ Keep parameters to minimum (max {{MAX_PARAMETERS}})
517
+ - ✅ Use parameter objects for 4+ parameters
518
+ - ✅ Return early to avoid nesting
519
+ - ❌ No side effects in getters
520
+ - ❌ No Boolean parameters (use enums or separate methods)
521
+
522
+ **Example:**
523
+ ```{{LANGUAGE}}
524
+ {{FUNCTION_QUALITY_EXAMPLE}}
525
+ ```
526
+
527
+ ### Classes
528
+
529
+ - ✅ Single Responsibility Principle
530
+ - ✅ Open/Closed Principle
531
+ - ✅ Liskov Substitution Principle
532
+ - ✅ Interface Segregation Principle
533
+ - ✅ Dependency Inversion Principle
534
+
535
+ ### DRY (Don't Repeat Yourself)
536
+
537
+ - ✅ Extract repeated code into functions
538
+ - ✅ Use loops instead of copy-paste
539
+ - ✅ Create utilities for common operations
540
+ - ❌ Copy-paste is a code smell
541
+
542
+ ### KISS (Keep It Simple, Stupid)
543
+
544
+ - ✅ Simplest solution that works
545
+ - ✅ Avoid premature optimization
546
+ - ✅ Readable over clever
547
+ - ❌ Don't over-engineer
548
+ ---
549
+ ## 🔒 Security Coding Standards
550
+
551
+ ### Input Validation
552
+
553
+ ```{{LANGUAGE}}
554
+ {{INPUT_VALIDATION_EXAMPLE}}
555
+ ```
556
+
557
+ ### SQL Injection Prevention
558
+
559
+ ```{{LANGUAGE}}
560
+ {{SQL_INJECTION_PREVENTION_EXAMPLE}}
561
+ ```
562
+
563
+ ### XSS Prevention
564
+
565
+ ```{{LANGUAGE}}
566
+ {{XSS_PREVENTION_EXAMPLE}}
567
+ ```
568
+
569
+ ### Secrets Management
570
+
571
+ ```{{LANGUAGE}}
572
+ {{SECRETS_EXAMPLE}}
573
+ ```
574
+ ---
575
+ ## 🧹 Code Smell Detection
576
+
577
+ ### Common Code Smells
578
+
579
+ | Smell | Description | Solution |
580
+ |-------|-------------|----------|
581
+ | Long Method | Function over {{MAX_FUNCTION_LENGTH}} lines | Extract methods |
582
+ | Large Class | Class over {{MAX_CLASS_LENGTH}} lines | Split responsibilities |
583
+ | Long Parameter List | More than {{MAX_PARAMETERS}} parameters | Use parameter object |
584
+ | Duplicate Code | Same code in multiple places | Extract to function/class |
585
+ | Dead Code | Unused code | Delete it |
586
+ | Magic Numbers | Unexplained constants | Use named constants |
587
+ | Nested Conditionals | Deep if/else nesting | Use early returns, guard clauses |
588
+ ---
589
+ ## 📦 Dependency Management
590
+
591
+ ### Rules
592
+
593
+ - ✅ Keep dependencies up to date
594
+ - ✅ Review security vulnerabilities regularly
595
+ - ✅ Use exact versions in production
596
+ - ❌ Don't add dependencies for simple utilities
597
+ - ❌ Don't use deprecated packages
598
+
599
+ ### Checking for Updates
600
+
601
+ ```bash
602
+ {{DEPENDENCY_CHECK_COMMAND}}
603
+ ```
604
+
605
+ ### Security Audit
606
+
607
+ ```bash
608
+ {{SECURITY_AUDIT_COMMAND}}
609
+ ```
610
+ ---
611
+ ## 🔧 Linting
612
+
613
+ **Tool:** {{LINTER}}
614
+
615
+ **Configuration:** `{{LINTER_CONFIG_FILE}}`
616
+
617
+ ### Running Linter
618
+
619
+ ```bash
620
+ # Check for issues
621
+ {{LINT_COMMAND}}
622
+
623
+ # Auto-fix issues
624
+ {{LINT_FIX_COMMAND}}
625
+ ```
626
+
627
+ ### Critical Rules
628
+
629
+ {{#EACH LINT_RULE}}
630
+ - **{{RULE_NAME}}**: {{RULE_DESCRIPTION}}
631
+ {{/EACH}}
632
+ ---
633
+ ## ✍️ Git Commit Standards
634
+
635
+ ### Commit Message Format
636
+
637
+ **Standard:** {{COMMIT_STANDARD}}
638
+
639
+ {{#IF CONVENTIONAL_COMMITS}}
640
+ ### Conventional Commits
641
+
642
+ **Format:**
643
+ ```
644
+ <type>(<scope>): <subject>
645
+
646
+ <body>
647
+
648
+ <footer>
649
+ ```
650
+
651
+ **Types:**
652
+ - `feat`: New feature
653
+ - `fix`: Bug fix
654
+ - `docs`: Documentation changes
655
+ - `style`: Code style changes (formatting, etc.)
656
+ - `refactor`: Code refactoring
657
+ - `test`: Adding/updating tests
658
+ - `chore`: Maintenance tasks
659
+
660
+ **Example:**
661
+ ```
662
+ feat(auth): add JWT refresh token rotation
663
+
664
+ - Implement token rotation on every refresh request
665
+ - Store refresh tokens in Redis with expiration
666
+ - Add cleanup job for expired tokens
667
+
668
+ Closes #123
669
+ ```
670
+
671
+ {{/IF}}
672
+
673
+ ### Branch Naming
674
+
675
+ **Convention:** {{BRANCH_NAMING_CONVENTION}}
676
+
677
+ **Examples:**
678
+ ```
679
+ {{BRANCH_NAMING_EXAMPLES}}
680
+ ```
681
+
682
+ ### Commit Size
683
+
684
+ - ✅ Small, focused commits
685
+ - ✅ One logical change per commit
686
+ - ❌ Don't mix refactoring with feature changes
687
+ - ❌ Don't commit broken code
688
+ ---
689
+ ## 📋 Code Review Checklist
690
+
691
+ ### Before Requesting Review
692
+
693
+ - [ ] Code follows all standards in this document
694
+ - [ ] Tests written and passing ({{MIN_COVERAGE}}%+ coverage)
695
+ - [ ] No linting errors
696
+ - [ ] No console.logs or debugger statements
697
+ - [ ] Documentation updated (if needed)
698
+ - [ ] Self-reviewed the changes
699
+ - [ ] Commit messages follow standard
700
+
701
+ ### Reviewer Checklist
702
+
703
+ - [ ] Code is understandable
704
+ - [ ] Logic is correct
705
+ - [ ] Edge cases are handled
706
+ - [ ] Error handling is appropriate
707
+ - [ ] Tests are comprehensive
708
+ - [ ] No security vulnerabilities
709
+ - [ ] Performance is acceptable
710
+ - [ ] Follows architecture patterns
711
+ ---
712
+ ## 🎯 Code Examples
713
+
714
+ ### Controller Example
715
+
716
+ ```{{LANGUAGE}}
717
+ {{CONTROLLER_EXAMPLE}}
718
+ ```
719
+
720
+ ### Service Example
721
+
722
+ ```{{LANGUAGE}}
723
+ {{SERVICE_EXAMPLE}}
724
+ ```
725
+
726
+ ### Repository Example
727
+
728
+ ```{{LANGUAGE}}
729
+ {{REPOSITORY_EXAMPLE}}
730
+ ```
731
+
732
+ ### DTO Example
733
+
734
+ ```{{LANGUAGE}}
735
+ {{DTO_EXAMPLE}}
736
+ ```
737
+
738
+ ### Test Example
739
+
740
+ ```{{LANGUAGE}}
741
+ {{TEST_EXAMPLE}}
742
+ ```
743
+ ---
744
+ ## 🚀 Performance Guidelines
745
+
746
+ ### Database
747
+
748
+ - ✅ Use indexes on foreign keys and frequently queried columns
749
+ - ✅ Use `select` to specify columns, not `SELECT *`
750
+ - ✅ Use pagination for large result sets
751
+ - ✅ Use database transactions for multi-step operations
752
+ - ❌ Avoid N+1 queries (use joins or batch queries)
753
+ - ❌ Don't query in loops
754
+
755
+ ### API
756
+
757
+ - ✅ Implement caching for expensive operations
758
+ - ✅ Use compression for large responses
759
+ - ✅ Implement rate limiting
760
+ - ✅ Use async/await for I/O operations
761
+ - ❌ Don't block the event loop (Node.js)
762
+ - ❌ Don't return excessive data
763
+
764
+ ### Memory
765
+
766
+ - ✅ Clean up event listeners
767
+ - ✅ Close database connections
768
+ - ✅ Stream large files
769
+ - ❌ Don't load entire files into memory
770
+ - ❌ Don't create memory leaks
771
+ ---
772
+ ## 📚 Resources
773
+
774
+ ### Official Docs
775
+
776
+ {{#EACH OFFICIAL_DOC}}
777
+ - [{{DOC_NAME}}]({{DOC_URL}})
778
+ {{/EACH}}
779
+
780
+ ### Style Guides
781
+
782
+ {{#EACH STYLE_GUIDE}}
783
+ - [{{GUIDE_NAME}}]({{GUIDE_URL}})
784
+ {{/EACH}}
785
+ ---
786
+ **Document Version:** 1.0
787
+
788
+ **Last Updated:** {{GENERATION_DATE}}
789
+
790
+ **Generated by:** AI Flow v1.0.0
791
+
792
+