@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,123 @@
1
+ # Sub-Agent Orchestration Pattern
2
+
3
+ Used by heavy commands when the target exceeds the complexity threshold.
4
+ The main session becomes a **lightweight orchestrator** — it only coordinates.
5
+ Each unit of work runs in its own sub-agent with a fresh context window.
6
+
7
+ ---
8
+
9
+ ## Complexity Thresholds
10
+
11
+ | Signal | Threshold | Action |
12
+ |--------|-----------|--------|
13
+ | UC count in PRD | > 3 UCs | spawn 1 agent per UC |
14
+ | PRD length | > 300 lines | spawn agents regardless of UC count |
15
+
16
+ If **either** threshold is exceeded → switch to orchestration mode.
17
+
18
+ ---
19
+
20
+ ## Orchestrator Steps (main session)
21
+
22
+ ### Step A — Build slim context
23
+
24
+ Extract only what sub-agents need — do NOT pass full CLAUDE.md or full business-dictionary:
25
+
26
+ ```json
27
+ {
28
+ "project_name": "{project.name}",
29
+ "tech_stack": {
30
+ "language": "{tech_stack.language}",
31
+ "framework": "{tech_stack.framework}",
32
+ "build_tool": "{tech_stack.build_tool}",
33
+ "test_framework": "{tech_stack.test_framework}",
34
+ "database": "{tech_stack.database}",
35
+ "module": "{tech_stack.module}"
36
+ },
37
+ "conventions": {
38
+ "build_command": "{conventions.build_command}",
39
+ "commit_format": "{conventions.commit_format}"
40
+ },
41
+ "paths": {
42
+ "specs_dir": "{paths.specs_dir}",
43
+ "prd_dir": "{paths.prd_dir}",
44
+ "trace_dir": "{paths.trace_dir}",
45
+ "tech_docs_dir": "{paths.tech_docs_dir}"
46
+ },
47
+ "architecture_summary": "<3-5 bullet points: layer order + key rules only>",
48
+ "domains": ["{domain1}", "{domain2}"],
49
+ "banned_terms": ["{term1}", "{term2}"]
50
+ }
51
+ ```
52
+
53
+ ### Step B — Extract UC list
54
+
55
+ Scan the target PRD for `#### {TICKET-ID}-UC{N}:` headings.
56
+ Build list: `[ { uc_id, uc_name, line_start, line_end } ]`
57
+
58
+ ### Step C — Announce plan
59
+
60
+ ```
61
+ High complexity detected — {N} UCs / {L} lines in {prd_file}
62
+ Spawning {N} sub-agents (1 per UC)...
63
+ Agent 1 → {TICKET-ID}-UC1: {UC name}
64
+ Agent 2 → {TICKET-ID}-UC2: {UC name}
65
+ ...
66
+ ```
67
+
68
+ ### Step D — Spawn one sub-agent per UC
69
+
70
+ Build payload and invoke Agent tool for each UC:
71
+
72
+ ```json
73
+ {
74
+ "_agent_mode": true,
75
+ "command": "{generate-bdd | generate-code | generate-tests}",
76
+ "uc_id": "{TICKET-ID}-UC{N}",
77
+ "target_file": "{absolute path to PRD or feature file}",
78
+ "uc_section": { "line_start": {N}, "line_end": {N} },
79
+ "context": { "<slim context from Step A>" }
80
+ }
81
+ ```
82
+
83
+ Serialize this JSON and pass as `$ARGUMENTS` when invoking the sub-agent command.
84
+
85
+ ### Step E — Collect and merge results
86
+
87
+ Each sub-agent returns:
88
+ ```json
89
+ {
90
+ "uc_id": "{TICKET-ID}-UC{N}",
91
+ "files_created": ["path/to/file1", "path/to/file2"],
92
+ "status": "success | error",
93
+ "errors": []
94
+ }
95
+ ```
96
+
97
+ Merge into a single report (follow report-footer.md format).
98
+ If any sub-agent errors → list them clearly and suggest re-run for that UC only.
99
+
100
+ ---
101
+
102
+ ## Sub-Agent Entry Point (called commands)
103
+
104
+ When `gate.md Step 0` detects `_agent_mode: true`:
105
+
106
+ 1. Parse full payload from `$ARGUMENTS`
107
+ 2. **Skip context-loader.md** — use `payload.context` directly
108
+ 3. **Scope to `payload.uc_id` only** — do not process other UCs in the file
109
+ 4. Read only the PRD section between `payload.uc_section.line_start` and `line_end`
110
+ 5. Execute the command's normal logic for this single UC
111
+ 6. Return structured result JSON (Step E format above)
112
+
113
+ ---
114
+
115
+ ## Context Window Savings
116
+
117
+ | Mode | What loads per session |
118
+ |------|------------------------|
119
+ | Single session (≤ 3 UC) | Full context + full PRD + all UCs |
120
+ | Orchestrator | Slim context + UC headings only |
121
+ | Each sub-agent | Slim context + **1 UC section only** |
122
+
123
+ The larger the PRD, the bigger the saving per sub-agent.
@@ -0,0 +1,113 @@
1
+ # §1. Project Overview
2
+
3
+ Project : {{PROJECT_NAME}}
4
+ Language : {{LANGUAGE}} # e.g., Java 17 / TypeScript / C# / Go
5
+ Framework : {{FRAMEWORK}} # e.g., Spring Boot 3.2 / Angular 17 / .NET 8
6
+ Build : {{BUILD_COMMAND}} # e.g., mvn clean install -DskipTests / dotnet build / ng build
7
+ Test : {{TEST_COMMAND}} # e.g., mvn test / dotnet test / ng test
8
+ Domains : {{COMMA_SEPARATED_DOMAINS}}
9
+
10
+ # §2. Architecture
11
+
12
+ style: "{{ARCH_STYLE}}" # e.g., Layered / Clean / Hexagonal / Component-based
13
+
14
+ layers: "{{LAYER_STACK}}"
15
+ # Examples:
16
+ # Java/Spring: Controller → Facade → Service → Repository
17
+ # .NET Clean: Presentation → Application → Domain → Infrastructure
18
+ # Angular: Component → Service → HTTP Client → Backend API
19
+ # Go: Handler → UseCase → Repository → Domain
20
+
21
+ rules:
22
+ - "{{ARCH_RULE_1}}" # e.g., Controllers must not contain business logic
23
+ - "{{ARCH_RULE_2}}" # e.g., Services own transaction boundaries
24
+ - "{{ARCH_RULE_3}}" # e.g., Repositories must not call services
25
+
26
+ # Layer dependency direction (inner layers must not depend on outer):
27
+ # {{OUTER_LAYER}} → {{MIDDLE_LAYER}} → {{INNER_LAYER}}
28
+
29
+ # §3. Coding Standards
30
+
31
+ naming:
32
+ classes: "{{CLASS_NAMING}}" # e.g., PascalCase / PascalCase+Suffix
33
+ methods: "{{METHOD_NAMING}}" # e.g., camelCase / PascalCase
34
+ packages: "{{PACKAGE_NAMING}}" # e.g., lowercase / lowercase.snake_case
35
+ files: "{{FILE_NAMING}}" # e.g., PascalCase.java / kebab-case.ts
36
+
37
+ patterns:
38
+ response_wrapper: "{{RESPONSE_WRAPPER}}" # e.g., ApiResponse<T> / Result<T> / IActionResult
39
+ mapping: "{{MAPPING_LIBRARY}}" # e.g., MapStruct / AutoMapper / manual
40
+ exception_base: "{{BASE_EXCEPTION}}" # e.g., ResourceNotFoundException / DomainException
41
+
42
+ forbidden:
43
+ - "Magic numbers — use named constants"
44
+ - "Debug print statements in production code"
45
+ - "{{PROJECT_SPECIFIC_FORBIDDEN_PATTERN}}"
46
+
47
+ # §4. API Conventions
48
+
49
+ versioning: "{{API_VERSIONING}}" # e.g., /v1/ prefix / header-based / query param
50
+ auth: "{{AUTH_MECHANISM}}" # e.g., JWT Bearer / OAuth2 / API Key
51
+
52
+ http_status:
53
+ get_list: 200 # paginated or full list
54
+ get_single: 200
55
+ create: 201
56
+ update: 200
57
+ delete: 204
58
+ bad_request: 400
59
+ unauthorized: 401
60
+ forbidden: 403
61
+ not_found: 404
62
+ server_error: 500
63
+
64
+ error_response_format: |
65
+ {
66
+ "code": "ERROR_CODE",
67
+ "message": "Human readable message",
68
+ "details": {} // optional field-level errors
69
+ }
70
+
71
+ # §5. Error Handling
72
+
73
+ not_found_exception: "{{NOT_FOUND_EXCEPTION_CLASS}}" # e.g., ResourceNotFoundException
74
+ validation_exception: "{{VALIDATION_EXCEPTION_CLASS}}" # e.g., ValidationException
75
+ domain_exception: "{{DOMAIN_EXCEPTION_CLASS}}" # e.g., DomainException / BusinessRuleViolationException
76
+
77
+ global_handler: "{{GLOBAL_EXCEPTION_HANDLER}}" # e.g., @ControllerAdvice / ExceptionHandlerMiddleware
78
+
79
+ rules:
80
+ - "Never swallow exceptions silently"
81
+ - "Log at error level with full stack trace for 5xx"
82
+ - "{{PROJECT_SPECIFIC_ERROR_RULE}}"
83
+
84
+ # §6. Testing Standards
85
+
86
+ unit_test_framework: "{{UNIT_TEST_FW}}" # e.g., JUnit 5 + Mockito / xUnit + Moq / Jest
87
+ integration_test_framework: "{{IT_TEST_FW}}" # e.g., Spring Boot Test / WebApplicationFactory
88
+
89
+ coverage_targets:
90
+ unit: "{{UNIT_COVERAGE_PCT}}%" # e.g., 80%
91
+ integration: "{{IT_COVERAGE_PCT}}%" # e.g., key flows covered
92
+
93
+ naming_pattern: "{{TEST_METHOD_NAMING}}" # e.g., methodName_whenCondition_shouldExpectation
94
+
95
+ rules:
96
+ - "Unit tests mock direct dependencies only"
97
+ - "Integration tests cover happy path + main error paths"
98
+ - "Every scenario in .feature must have a corresponding test"
99
+
100
+ # §7. Git Conventions
101
+
102
+ branch_feature: "feature/{{TICKET_PREFIX}}-{N}-{slug}"
103
+ branch_fix: "fix/{{TICKET_PREFIX}}-{N}-{slug}"
104
+ branch_chore: "chore/{slug}"
105
+
106
+ commit_feature: "feat({{TICKET_PREFIX}}-{N}): {description}"
107
+ commit_fix: "fix({{TICKET_PREFIX}}-{N}): {description}"
108
+ commit_chore: "chore: {description}"
109
+ commit_docs: "docs: {description}"
110
+
111
+ pr_title: "{{TICKET_PREFIX}}-{N}: {feature name}"
112
+ pr_requires_review: true
113
+ pr_branch_protection: "{{BASE_BRANCH}}" # e.g., main / develop
@@ -0,0 +1,259 @@
1
+ # ============================================================
2
+ # BDD Feature Template — KVLoyalty AI Native Pipeline (v2)
3
+ # ============================================================
4
+ # Instructions:
5
+ # 1. Copy this file và rename: {TICKET_ID}-UC{N}-feature-name.feature
6
+ # 2. Điền @trace metadata (required)
7
+ # 3. Khai báo Context của UC (1 lần, đầu file)
8
+ # 4. Tạo/cập nhật dataset YAML cùng domain: specs/features/{domain}.testdata.yaml
9
+ # 5. Viết Scenario — mỗi SC PHẢI có dòng `# Side-effects:` ngay trên
10
+ # 6. Đặt file ở: specs/features/{domain}/
11
+ # 7. Chạy: /generate-code
12
+ # ============================================================
13
+ #
14
+ # RULE VIẾT BDD BẮT BUỘC (xem bdd-writing-guide.md PART A + C):
15
+ # R1 Given/When/Then Semantics — Given=state, When=action, Then=outcome (mỗi SC đủ G/W/T)
16
+ # R2 One Behavior Per Scenario — 1 SC = 1 behavior; KHÔNG chain When-Then
17
+ # R3 Ubiquitous Language — KHÔNG dùng UI selector / API name / tech term
18
+ # R4 Outside-in Naming — Tên SC mô tả business outcome, KHÔNG có "click"/"(Case X)"/component name
19
+ # R5 Declarative over Imperative — Mô tả WHAT (intent business), KHÔNG HOW (UI mechanic)
20
+ # R6 Observable Outcomes Only — Then assert outcome quan sát được, KHÔNG UI trung gian/internal state
21
+ # R7 Key Examples / Concrete — Dùng concrete values, KHÔNG "hợp lệ" chung chung
22
+ # R8 Independence — SC chạy độc lập, KHÔNG phụ thuộc state SC khác
23
+ # R9 Test Data Completeness — Data table có đủ field external system để derive expected Then
24
+ # R10 Scope Boundary Explicit — Cross-UC reference dùng wording navigation + Note comment
25
+ # PROJECT COMPLIANCE (must-pass, fail review nếu thiếu):
26
+ # C.1 Wireframe Coverage — Mọi component/action wireframe có ≥1 SC
27
+ # C.2 PRD Traceability — Mọi AC/BR (kèm bullet) map về ≥1 SC
28
+ # C.3 Business Dictionary — Dùng đúng term, đề xuất term mới qua DICTIONARY-SUGGESTION
29
+ # C.4 Banned Terms Compliance — 0 banned term (auto-grep): SKU/Customer/JS SDK/Cửa hàng/...
30
+ # C.5 NHÓM Grouping Convention — Scenarios gom theo CHỦ ĐỀ NGHIỆP VỤ (NHÓM N) — xem §NHÓM GROUPING CONVENTION dưới
31
+ # ============================================================
32
+
33
+ # --- TRACE METADATA (REQUIRED) ---
34
+ # @trace.id: {TICKET_ID}-UC{N}
35
+ # @trace.title: <Tên tính năng bằng tiếng Việt>
36
+ # @trace.revision: 1
37
+ # @trace.domain: <identity|loyalty|membership|messaging|store-management>
38
+ # @trace.service: <KVLoyalty.Identity|KVLoyalty.Loyalty|...>
39
+ # @trace.status: draft|review|approved
40
+ # @trace.author: <tên tác giả>
41
+ # @trace.created_at: <YYYY-MM-DD>
42
+ # @trace.prd: <TICKET-ID hoặc để trống>
43
+ # @trace.prd_version: <version PRD tại thời điểm viết — để drift-detector so sánh>
44
+ # @trace.business_rules: <{TICKET_ID}-UC{N}-BR{M}, ...>
45
+ # @trace.dataset: <{domain}.testdata.yaml — bắt buộc nếu BDD reference dataset>
46
+
47
+ # === CONTEXT (áp dụng cho toàn Feature) ===
48
+ # Actor: <vai trò thực hiện hành động, vd: Consumer, Staff, System>
49
+ # Screens: <các màn liên quan, vd: Cart → Confirm Order → Order Detail>
50
+ # Entities: <entity nghiệp vụ, vd: Order, OrderItem, Consumer, Branch>
51
+ # Pre-state: <state chung trước khi vào các scenario>
52
+
53
+ # === SCOPE ===
54
+ # In: <những gì UC này cover>
55
+ # Out: <những gì KHÔNG thuộc UC này — link sang UC khác / feature khác (R10)>
56
+
57
+ # === BUSINESS DEFINITION (MANDATORY) ===
58
+ # Quick reference các thuật ngữ dùng trong feature này. SoT chi tiết: business-dictionary.md
59
+ # Mục đích: reader đọc 1 lần hiểu ngay khái niệm trước khi xem scenarios.
60
+ #
61
+ # <Term 1> (English mapping): <định nghĩa ngắn gọn, vd cấu trúc, scope>
62
+ # <Term 2>: <định nghĩa>
63
+ # ...
64
+ #
65
+ # === Test data convention (R9) ===
66
+ # Khai báo default value khi data table không có cột tương ứng.
67
+ # VD: "SC không khai báo cột customerOrdered → ngầm hiểu customerOrdered = 0 (chưa có khách đặt)"
68
+ # VD: "SC không khai báo cột toggle → ngầm hiểu toggle = Hiện (default Ẩn/Hiện trạng thái)"
69
+ #
70
+ # === Popup/Modal Lifecycle (B.2.4 — bắt buộc nếu feature là popup/modal) ===
71
+ # - Open trigger: <khi nào popup hiển thị, vd: click menu sidebar>
72
+ # - Close trigger: <khi nào popup đóng, vd: F5 / click X / ESC / navigate away>
73
+ # - Refresh model: <data refresh khi nào, vd: mỗi lần open (NO CACHE) / persisted / polling>
74
+ # - State reset: <state nào reset khi đóng/mở lại, vd: pagination, expand, dropdown selection>
75
+
76
+ # === DISPLAY LOGIC MATRIX (optional — bắt buộc nếu display logic phụ thuộc ≥2 dimension, B.1.7) ===
77
+ # Enumerate full matrix N×M case + map mỗi case → SC.
78
+ # Tên SC theo pattern: `<cấu trúc>: <outcome>` — KHÔNG dùng "(Case X)" suffix.
79
+ # VD ma trận `{số thuộc tính: 0/1/≥2} × {số đơn vị tính: 0/1/≥2}` = 9 case:
80
+ #
81
+ # | # | Dim1 | Dim2 | Format hiển thị | SC |
82
+ # |---|------|------|----------------------------------------------|------|
83
+ # | 1 | 0 | 0 | `Tên hàng` | SC{} |
84
+ # | 2 | 0 | 1 | `Tên hàng (đơn vị)` | SC{} |
85
+ # | ... | ... | ... | ... | ... |
86
+
87
+ # === DICTIONARY REFERENCES (R3 + C.4) ===
88
+ # Liệt kê các term từ business-dictionary.md mà feature này dùng → pointer cho reviewer auto-check.
89
+ # Banned terms (xem business-dictionary.md § Banned Terms) MUST NOT appear: 0 match khi grep.
90
+ #
91
+ # Terms dùng trong feature này:
92
+ # - <Term 1> (xem dictionary line {N})
93
+ # - <Term 2> (xem dictionary line {M})
94
+ # - ...
95
+
96
+ Feature: <Tên tính năng bằng tiếng Việt>
97
+ Với vai trò là <vai trò>
98
+ Tôi muốn <hành động>
99
+ Để <lợi ích nghiệp vụ>
100
+
101
+ # --- DATASET REFERENCE CONVENTION ---
102
+ # Ưu tiên dùng ALIAS (tiếng Việt) thay vì ID kỹ thuật, để BDD dễ đọc.
103
+ # Backtick ID chỉ dùng khi cần precision (vd: assertion về mã đơn).
104
+ #
105
+ # Ví dụ:
106
+ # ✅ Given đơn hàng draft "Đơn COD giao hàng — 2× áo + 1× quần, total 650K"
107
+ # ✅ Then đơn được gán mã `ZMA{id}` nhận từ Retail
108
+ # ❌ Given đơn hàng draft là `ORD_COD_DRAFT_001` ← khó đọc, hạn chế
109
+
110
+ Background:
111
+ Given <điều kiện tiên quyết chung — dùng alias từ dataset>
112
+ # Ví dụ: Given consumer "Khách mới đã cấp quyền Zalo" ở màn "Xác nhận đơn hàng"
113
+ # của gian hàng "Cửa hàng Thời Trang (đang kích hoạt)"
114
+
115
+ # ============================================================
116
+ # § NHÓM GROUPING CONVENTION (C.5 — bắt buộc cho mọi feature ≥3 SCs)
117
+ # ============================================================
118
+ # Mục đích: organize scenarios theo CHỦ ĐỀ NGHIỆP VỤ để dễ navigate + scope-awareness, KHÔNG
119
+ # theo phân loại happy/negative/edge (deprecated section markers HAPPY-PATH / NEGATIVE-CASE / EDGE-CASE).
120
+ #
121
+ # Quy tắc:
122
+ # 1. **Gom theo chủ đề business** — mỗi NHÓM = 1 business theme (flow / state / behavior subset).
123
+ # ✅ NHÓM 1: Khởi tạo gian hàng thành công với dữ liệu mặc định (BR1, BR2)
124
+ # ✅ NHÓM 2: Resume khi onboarding bị gián đoạn (BR1 resume)
125
+ # ✅ NHÓM 3: Xử lý lỗi khởi tạo (BR3)
126
+ # ❌ NHÓM 1: HAPPY-PATH ← chia theo loại path, không phải chủ đề
127
+ # ❌ NHÓM 1: COD scenarios ← UI feature, không phải business theme
128
+ #
129
+ # 2. **Mỗi NHÓM có thể chứa cả @happy + @edge + @negative SCs cùng chủ đề** — KHÔNG tách happy/edge ra 2 NHÓM riêng.
130
+ # Ví dụ: NHÓM "Xử lý lỗi khi khởi tạo" chứa SC happy retry + SC edge X close + SC negative no retry.
131
+ # Tag taxonomy (@happy/@edge/@cross-system per B.2.3) áp dụng ở SC level — KHÔNG ở NHÓM level.
132
+ #
133
+ # 3. **Format NHÓM header** (3 dòng comment box):
134
+ # # ==========================================================
135
+ # # NHÓM N: <Chủ đề> (<BR refs nếu áp dụng>)
136
+ # # ==========================================================
137
+ # Indent 2 spaces (cùng level với Background + Scenario).
138
+ #
139
+ # 4. **Đánh số NHÓM tuần tự** từ 1 → N. Không skip số. Reorder NHÓM được — KHÔNG ảnh hưởng SC IDs.
140
+ #
141
+ # 5. **SC trong NHÓM KHÔNG cần theo thứ tự ID** — VD NHÓM 2 có thể chứa SC8, SC4, SC11 nếu cùng chủ đề.
142
+ # SC IDs tuần tự theo lifecycle (skill §3.4), KHÔNG theo NHÓM ordering.
143
+ #
144
+ # 6. **Khi nào skip NHÓM**: feature có <3 SCs → có thể bỏ NHÓM headers (không value to organize so few).
145
+ # Đơn giản đặt SCs nối tiếp sau Background. Feature ≥3 SCs → BẮT BUỘC NHÓM.
146
+ #
147
+ # Pattern thường gặp (gợi ý theme — tuỳ chỉnh per UC):
148
+ # - "Khởi tạo / Lưu thành công — các tổ hợp data hợp lệ" (gom happy + alternative)
149
+ # - "Validation / Chặn lưu khi không hợp lệ" (gom negative + edge validation)
150
+ # - "Xử lý lỗi — API fail / system error" (gom negative + recovery)
151
+ # - "Hủy thay đổi / Đóng modal không lưu" (gom edge UX)
152
+ # - "Hành vi popup / dialog — multi-select / persist / boundary" (gom edge UX behavior)
153
+ # - "Hiệu ứng cross-system / Consumer view" (gom @cross-system SCs)
154
+ # - "Idempotency & Concurrency" (gom edge concurrency)
155
+ # - "State transition / Recovery completion" (gom @cross-UC behavior chains)
156
+ #
157
+ # Ví dụ NHÓM structure cho UC có 9 SCs (LOYAL-32-UC1 reference):
158
+ # NHÓM 1: Lưu cấu hình thành công — các tổ hợp PTTT hợp lệ (BR1, BR2) → SC1, SC2, SC3, SC4
159
+ # NHÓM 2: Chặn lưu khi cấu hình không hợp lệ (BR1, BR2) + lỗi hệ thống → SC5, SC6, SC7
160
+ # NHÓM 3: Hủy thay đổi — đóng Modal không lưu → SC8
161
+ # NHÓM 4: Initial State — Modal phản ánh cấu hình hiện tại → SC10
162
+
163
+ # ==========================================================
164
+ # NHÓM 1: <Chủ đề business 1> (<BR refs nếu cần>)
165
+ # ==========================================================
166
+
167
+ # Side-effects: <liệt kê NGẮN GỌN các hậu quả Then phải verify — 1 dòng>
168
+ # @trace.scenario: {TICKET_ID}-UC{N}-SC1
169
+ # @trace.sc_version: 1.0
170
+ # @trace.business_rules: {TICKET_ID}-UC{N}-BR{M}
171
+ @happy
172
+
173
+ Scenario: <Mô tả luồng chính — dùng động từ CHÍNH XÁC (tạo/nhận/gán/đồng bộ)>
174
+ Given <state đầu vào — dùng alias từ dataset, vd: "Đơn COD giao hàng — 2× áo + 1× quần">
175
+ When <hành động duy nhất>
176
+ Then <kết quả chính — dùng backtick ID khi cần precision, vd: mã `ZMA{id}`>
177
+ And <side-effect 1 đã khai báo ở header>
178
+ And <side-effect 2 đã khai báo ở header>
179
+ # ... đủ với danh sách Side-effects ở trên (Rule R2)
180
+
181
+ # Side-effects: <...>
182
+ # @trace.scenario: {TICKET_ID}-UC{N}-SC2
183
+ # @trace.sc_version: 1.0
184
+ # @trace.business_rules: {TICKET_ID}-UC{N}-BR{M}
185
+ @happy @alternative
186
+
187
+ Scenario: <Cùng chủ đề NHÓM 1 nhưng path khác — vd enum value khác (Rule R4 enum symmetry)>
188
+ Given <state đầu vào>
189
+ When <hành động>
190
+ Then <kết quả>
191
+
192
+ # ==========================================================
193
+ # NHÓM 2: <Chủ đề business 2 — VD: Xử lý lỗi / Validation> (<BR refs>)
194
+ # ==========================================================
195
+
196
+ # Side-effects: <...>
197
+ # @trace.scenario: {TICKET_ID}-UC{N}-SC3
198
+ # @trace.sc_version: 1.0
199
+ # @trace.business_rules: {TICKET_ID}-UC{N}-BR{M}
200
+ @edge
201
+
202
+ Scenario: <Tình huống biên / lỗi cùng chủ đề NHÓM 2>
203
+ Given <state đầu vào>
204
+ When <hành động>
205
+ Then <xử lý lỗi mong đợi>
206
+
207
+ # ==========================================================
208
+ # NHÓM 3: <Chủ đề business 3 — VD: Cross-system / Hiệu ứng downstream> (<BR refs>)
209
+ # ==========================================================
210
+
211
+ # Side-effects: <...>
212
+ # @trace.scenario: {TICKET_ID}-UC{N}-SC4
213
+ # @trace.sc_version: 1.0
214
+ # @trace.business_rules: {TICKET_ID}-UC{N}-BR{M}
215
+ @happy @cross-system
216
+
217
+ Scenario: <Scenario span ≥2 service hoặc hiệu ứng đồng bộ cross-UC>
218
+ Given <state đầu vào>
219
+ When <hành động>
220
+ Then <kết quả tại service A>
221
+ And <kết quả đồng bộ sang service B>
222
+
223
+ # === TECHNICAL HINTS (optional, giúp AI gen code chính xác hơn) ===
224
+ # Dependencies: <UC/service phụ thuộc, vd: LOYAL-28 upstream>
225
+ # Entities: <Entity1, Entity2>
226
+ # Events: <EventName> (publish to <topic>)
227
+ # Cache: <cache invalidation notes>
228
+ # Validation: <validation rules>
229
+
230
+ # === PRD COVERAGE (C.1 + C.2 — wireframe action + AC/BR checklist) ===
231
+ # AC mapping:
232
+ # AC1 (...) → SC1, SC2
233
+ # AC2 (...) → SC3
234
+ # BR mapping (mỗi bullet trong BR PHẢI có ≥1 SC — C.2):
235
+ # BR1 (...) → SC1
236
+ # BR2 (...) → SC1, SC2
237
+ # Wireframe mapping (mọi component/action có ≥1 SC — C.1):
238
+ # Screen "<tên màn>":
239
+ # [x] Click "<button A>" → SC1
240
+ # [x] Click "<button B>" → SC2
241
+ # [ ] Click "<" back → MISSING ← BLOCK MERGE
242
+ # Display Logic Matrix mapping (nếu áp dụng — B.1.7):
243
+ # Case 1 (...) → SC{N}
244
+ # Case 2 (...) → SC{N}
245
+ # User Flow: <path name> → SC1, SC2, SC3
246
+
247
+ # === BUSINESS RULES ===
248
+ # {TICKET_ID}-UC{N}-BR1: <mô tả rule>
249
+ # {TICKET_ID}-UC{N}-BR2: <mô tả rule>
250
+
251
+ # === PRE-MERGE CHECKLIST (auto-verify) ===
252
+ # - [ ] Mọi SC có Side-effects + @trace.scenario + @trace.sc_version + @trace.ac + @trace.business_rules
253
+ # - [ ] Coverage Matrix có 0 dòng `[ ]` MISSING (C.1)
254
+ # - [ ] Mọi AC/BR (kèm từng bullet) map về ≥1 SC (C.2)
255
+ # - [ ] CI grep banned terms = 0 match (C.4) — xem business-dictionary.md § Banned Terms
256
+ # - [ ] Nếu là popup/modal: Popup/Modal Lifecycle khai báo trong BUSINESS DEFINITION (B.2.4)
257
+ # - [ ] Nếu display logic ≥2 dimension: Display Logic Matrix enumerated (B.1.7)
258
+ # - [ ] Feature ≥3 SCs có NHÓM grouping theo chủ đề business (C.5) — KHÔNG dùng section markers cũ HAPPY-PATH/NEGATIVE-CASE/EDGE-CASE
259
+ # - [ ] /review-context score ≥90 (project gate)
@@ -0,0 +1,145 @@
1
+ # Platform Guide — {{SERVICE_NAME}}
2
+
3
+ > This guide provides context that Claude uses when working in THIS service/repository.
4
+ > Keep it concise and factual. Update when the architecture or domain model changes.
5
+ > Reference: CLAUDE.md for project-wide standards. This file covers service-specific context.
6
+
7
+ ---
8
+
9
+ # §1. Service Overview
10
+
11
+ **Service name**: {{SERVICE_NAME}}
12
+ **Purpose**: {{ONE_SENTENCE_PURPOSE}}
13
+ **Bounded context**: {{BOUNDED_CONTEXT}} # e.g., "Owns all order lifecycle logic. Does NOT own payments or inventory."
14
+ **Team**: {{TEAM_NAME}}
15
+ **Repository**: {{REPO_URL}}
16
+
17
+ Primary responsibilities:
18
+ - {{RESPONSIBILITY_1}}
19
+ - {{RESPONSIBILITY_2}}
20
+ - {{RESPONSIBILITY_3}}
21
+
22
+ This service does NOT handle:
23
+ - {{OUT_OF_SCOPE_1}} # e.g., "Payment processing → see payment-service"
24
+ - {{OUT_OF_SCOPE_2}}
25
+
26
+ ---
27
+
28
+ # §2. Domain Model
29
+
30
+ Key entities and their relationships:
31
+
32
+ ```
33
+ {{ENTITY_1}} (aggregate root)
34
+ ├── {{CHILD_ENTITY_1}} (value object / child entity)
35
+ └── {{CHILD_ENTITY_2}}
36
+
37
+ {{ENTITY_2}}
38
+ └── references {{ENTITY_1}} by ID
39
+ ```
40
+
41
+ **{{ENTITY_1}}**:
42
+ - Key fields: {{KEY_FIELDS}}
43
+ - Status lifecycle: {{STATUS_1}} → {{STATUS_2}} → {{STATUS_3}}
44
+ - Business rules: {{KEY_RULE_1}}
45
+
46
+ **{{ENTITY_2}}**:
47
+ - Key fields: {{KEY_FIELDS}}
48
+ - Relationships: {{RELATIONSHIP_DESCRIPTION}}
49
+
50
+ ---
51
+
52
+ # §3. Common Patterns
53
+
54
+ Patterns specific to this service (supplement the project-wide standards in CLAUDE.md):
55
+
56
+ ## {{PATTERN_NAME_1}}
57
+ ```
58
+ // When to use: {{USE_CASE}}
59
+ // Example:
60
+ {{CODE_EXAMPLE}}
61
+ ```
62
+
63
+ ## {{PATTERN_NAME_2}}
64
+ ```
65
+ // When to use: {{USE_CASE}}
66
+ // Example:
67
+ {{CODE_EXAMPLE}}
68
+ ```
69
+
70
+ ---
71
+
72
+ # §4. Integration Points
73
+
74
+ ## Upstream Dependencies (this service calls these)
75
+
76
+ | Service / System | What we call | Protocol | Auth |
77
+ |------------------|--------------|----------|------|
78
+ | {{UPSTREAM_1}} | {{WHAT}} | REST/gRPC/Event | {{AUTH_METHOD}} |
79
+ | {{UPSTREAM_2}} | {{WHAT}} | REST/gRPC/Event | {{AUTH_METHOD}} |
80
+
81
+ ## Downstream Consumers (these services call us or consume our events)
82
+
83
+ | Consumer | What they use | Protocol |
84
+ |----------|---------------|----------|
85
+ | {{DOWNSTREAM_1}} | {{WHAT}} | REST/Event |
86
+ | {{DOWNSTREAM_2}} | {{WHAT}} | REST/Event |
87
+
88
+ ## Events Produced
89
+
90
+ | Event name | Trigger | Payload summary |
91
+ |------------|---------|-----------------|
92
+ | {{EVENT_1}} | {{WHEN}} | {{PAYLOAD_FIELDS}} |
93
+ | {{EVENT_2}} | {{WHEN}} | {{PAYLOAD_FIELDS}} |
94
+
95
+ ## Events Consumed
96
+
97
+ | Event name | From service | What we do with it |
98
+ |------------|-------------|-------------------|
99
+ | {{EVENT_1}} | {{SOURCE}} | {{HANDLER_ACTION}} |
100
+
101
+ ---
102
+
103
+ # §5. Known Constraints
104
+
105
+ ## Performance Constraints
106
+ - {{PERF_CONSTRAINT_1}} # e.g., "Order list endpoint must respond < 200ms for up to 1000 orders"
107
+ - {{PERF_CONSTRAINT_2}}
108
+
109
+ ## Business Rule Constraints
110
+ - {{BUSINESS_CONSTRAINT_1}} # e.g., "Cannot cancel an order after it has been shipped"
111
+ - {{BUSINESS_CONSTRAINT_2}}
112
+
113
+ ## External Dependencies
114
+ - {{EXTERNAL_DEP_1}} # e.g., "Requires inventory-service to be available for order creation"
115
+ - {{EXTERNAL_DEP_2}}
116
+
117
+ ## Known Technical Debt
118
+ - {{TECH_DEBT_1}} # e.g., "OrderItem.price is duplicated from catalog — sync via nightly job"
119
+
120
+ ---
121
+
122
+ # §6. Directory Structure
123
+
124
+ ```
125
+ {{SERVICE_ROOT}}/
126
+ ├── {{SOURCE_DIR}}/ # Main source code
127
+ │ ├── {{LAYER_1}}/ # e.g., controller/ or handler/
128
+ │ │ └── {{EXAMPLE_FILE}}
129
+ │ ├── {{LAYER_2}}/ # e.g., service/ or usecase/
130
+ │ │ └── {{EXAMPLE_FILE}}
131
+ │ ├── {{LAYER_3}}/ # e.g., repository/ or repo/
132
+ │ │ └── {{EXAMPLE_FILE}}
133
+ │ └── {{LAYER_4}}/ # e.g., model/ or domain/
134
+ │ └── {{EXAMPLE_FILE}}
135
+ ├── {{TEST_DIR}}/ # Tests mirroring src structure
136
+ ├── specs/ # BDD feature files
137
+ │ └── bdd/
138
+ │ └── {{DOMAIN}}/
139
+ │ └── {{UC-ID}}-{{slug}}.feature
140
+ └── {{CONFIG_FILE}} # e.g., application.yaml / appsettings.json
141
+ ```
142
+
143
+ **Key conventions for this repo:**
144
+ - {{CONVENTION_1}} # e.g., "All DTOs are in the api/ package, not mixed with domain models"
145
+ - {{CONVENTION_2}} # e.g., "Integration tests are in src/test/java/.../integration/ with @Tag(\"integration\")"