spec-lite 1.0.2 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # spec-lite
2
2
 
3
- Bộ skills spec-driven development cho Claude Code — phỏng vấn có cấu trúc để xây dựng PRD, domain knowledge, kiến trúc hệ thống và integration specs.
3
+ Bộ skills spec-driven development cho Claude Code — phỏng vấn có cấu trúc để xây dựng PRD, kiến trúc hệ thống, và integration specs. Domain knowledge và component/feature artifacts mọc dần qua cascade từ integrations.
4
4
 
5
5
  > **Lưu ý:** Hiện tại chỉ hoạt động với [Claude Code](https://claude.ai/code) (thư mục `.claude/`).
6
6
 
@@ -19,17 +19,17 @@ Các skill được gọi bằng slash command bên trong Claude Code.
19
19
  ### Thứ tự thực hiện
20
20
 
21
21
  ```
22
- /spec-prd → /spec-domain → /spec-sad
23
-
24
- (có requirement mới)
25
-
26
- /spec-new
27
-
28
- /spec-tech
29
-
30
- /plan
31
-
32
- /build
22
+ /spec-prd → /spec-sad
23
+
24
+ (có requirement mới)
25
+
26
+ /spec-new
27
+
28
+ /spec-tech
29
+
30
+ /plan
31
+
32
+ /build
33
33
  ```
34
34
 
35
35
  ---
@@ -37,17 +37,12 @@ Các skill được gọi bằng slash command bên trong Claude Code.
37
37
  ### Seed skills — chạy một lần khi bắt đầu dự án
38
38
 
39
39
  #### `/spec-prd`
40
- Tạo hoặc cập nhật `specs/main/prd.md` thông qua interview có cấu trúc.
40
+ Tạo hoặc cập nhật `specs/main/prd.md` thông qua interview có cấu trúc. Đồng thời scaffold `specs/main/domain.md` skeleton.
41
41
 
42
- Sections: Problem Statement · Target Users · Scope · Features · Non-Functional Requirements · Business Constraints
43
-
44
- #### `/spec-domain`
45
- Tạo hoặc cập nhật `specs/main/domain.md`. Yêu cầu `prd.md` phải có nội dung trước.
46
-
47
- Sections: Terminology · Entities · Business Rules · Domain Events
42
+ Sections: Problem Statement · Target Users · Scope · Features · Components · Non-Functional Requirements · Business Constraints
48
43
 
49
44
  #### `/spec-sad`
50
- Tạo hoặc cập nhật `specs/main/sad.md`. Yêu cầu `prd.md` và `domain.md` phải nội dung trước.
45
+ Tạo hoặc cập nhật `specs/main/sad.md`. Yêu cầu `prd.md` và `domain.md` đã tồn tại.
51
46
 
52
47
  Sections: Architectural Style · System Overview · Tech Stack · Cross-Cutting Concerns · Inter-Service Communication · Infrastructure Overview · Architectural Guardrails
53
48
 
@@ -70,16 +65,20 @@ Tạo `specs/integrations/{slug}/tech.md` sau khi `spec.md` được approve.
70
65
  #### `/plan`
71
66
  Tạo `plan.md` và `todo.md` từ `spec.md` + `tech.md`.
72
67
 
68
+ #### `/build`
69
+ Implement từng task trong `plan.md`/`todo.md` theo TDD incremental.
70
+
73
71
  ---
74
72
 
75
73
  ### Files được tạo ra
76
74
 
77
75
  | Command | Output |
78
76
  |---------|--------|
79
- | `/spec-prd` | `specs/main/prd.md` |
80
- | `/spec-domain` | `specs/main/domain.md` |
77
+ | `/spec-prd` | `specs/main/prd.md`, `specs/main/domain.md` (skeleton) |
81
78
  | `/spec-sad` | `specs/main/sad.md` |
82
79
  | `/spec-new` | `specs/integrations/{slug}/spec.md` |
83
80
  | `/spec-tech` | `specs/integrations/{slug}/tech.md` |
84
81
  | `/plan` | `specs/integrations/{slug}/plan.md`, `todo.md` |
85
82
  | `/build` | _(implements tasks từ `plan.md`/`todo.md`)_ |
83
+
84
+ Component (`crd.md`, `cdd.md`) và feature (`frd.md`, `fdd.md`) artifacts mọc dần qua **cascade proposals** từ integrations — không có skill chuyên biệt để tạo.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spec-lite",
3
- "version": "1.0.2",
3
+ "version": "1.1.1",
4
4
  "description": "Spec-driven development kit for Claude Code",
5
5
  "type": "module",
6
6
  "bin": {
@@ -66,10 +66,12 @@ Surface tóm tắt để planning-and-task-breakdown có đủ context:
66
66
  ```
67
67
  CONTEXT CHO PLANNING:
68
68
  - Integration: {title}
69
+ - Features: {từ spec.md frontmatter}
70
+ - Components: {từ spec.md frontmatter}
69
71
  - Yêu cầu chính: {tóm tắt từ spec.md — 2-4 bullet}
70
- - Acceptance Criteria: {số lượng}Feature-level: {AC-F-001, AC-F-002...} / Story-level: {AC-S-001, AC-S-002...}
72
+ - Acceptance Criteria: {tổng số AClist IDs theo nhóm Feature/Component như spec.md}
71
73
  - Thay đổi kỹ thuật: {modules, data model, interfaces từ tech.md}
72
- - Entities liên quan: {từ domain.md}
74
+ - Shared entities liên quan: {từ domain.md}
73
75
 
74
76
  ASSUMPTIONS:
75
77
  1. {assumption về ordering nếu có}
@@ -0,0 +1,266 @@
1
+ ---
2
+ name: spec-brownfield-component
3
+ description: Discover components từ code, generate crd.md + cdd.md cho từng component, điền Component Index vào prd.md. Phải chạy /spec-brownfield-init trước.
4
+ ---
5
+
6
+ # spec-brownfield-component
7
+
8
+ ## Overview
9
+
10
+ Tạo `specs/main/component/{C-XXX}-{component-name}/crd.md` và `cdd.md` cho các components trong brownfield project.
11
+
12
+ Skill này **tự discover** component boundaries từ code (không dựa vào init), sau đó scan sâu từng component để extract responsibilities, entities, public interface, business rules. Khi hoàn thành, **điền Component Index vào prd.md** và **đề xuất Shared Entities cascade vào domain.md**.
13
+
14
+ ## When to Use
15
+
16
+ - Sau khi `/spec-brownfield-init` đã chạy và `prd.md` tồn tại
17
+ - Cần generate component artifacts cho brownfield project
18
+
19
+ ## When NOT to Use
20
+
21
+ - `prd.md` chưa có → chạy `/spec-brownfield-init` trước
22
+ - Greenfield project → component artifacts mọc dần qua cascade từ integrations (`/spec-new`)
23
+
24
+ ---
25
+
26
+ ## Process
27
+
28
+ ### Bước 1: Load context và xác định path
29
+
30
+ **Path:** Nếu có ARGUMENT là path → dùng làm root. Nếu không → CWD.
31
+
32
+ **Load:**
33
+ - `specs/main/prd.md` — kiểm tra tồn tại; đọc problem statement và NFRs để hiểu business context
34
+ - `specs/main/domain.md` — đọc Glossary để reuse business terms
35
+
36
+ Nếu `prd.md` không tồn tại → dừng:
37
+ > `prd.md` chưa có nội dung. Hãy chạy `/spec-brownfield-init` trước.
38
+
39
+ **Attachments:**
40
+ > Bạn có tài liệu bổ sung nào không? (API docs, architecture diagrams, design docs)
41
+ > Nhập `không` để bỏ qua.
42
+
43
+ ---
44
+
45
+ ### Bước 2: Discover component boundaries
46
+
47
+ Scan directory structure để tìm component candidates. Thử các patterns sau theo thứ tự:
48
+
49
+ 1. `src/modules/*/` — modular structure (NestJS, v.v.)
50
+ 2. `src/*/` — flat module structure (nếu có `service` hoặc `controller` bên trong)
51
+ 3. `services/*/` — microservices
52
+ 4. `packages/*/` — monorepo packages
53
+ 5. `apps/*/` — monorepo apps
54
+
55
+ Với mỗi candidate directory, xác nhận đây là component bằng cách kiểm tra có ít nhất một trong: `*controller*`, `*service*`, `*repository*`, `*handler*`, `*module*` file bên trong.
56
+
57
+ Ghi lại cho mỗi component candidate:
58
+ - Directory path
59
+ - File count
60
+ - Patterns detected: controller / service / repository / event publisher / consumer
61
+
62
+ ---
63
+
64
+ ### Bước 3: Confirm component list
65
+
66
+ Trình bày kết quả discovery cho user confirm:
67
+
68
+ ```
69
+ Tôi phát hiện {N} components từ codebase:
70
+ [C-001] auth → src/modules/auth/ (15 files: controller+service+repo)
71
+ [C-002] user → src/modules/user/ (12 files: controller+service+repo)
72
+ [C-003] payment → src/modules/payment/ (8 files: service+repo)
73
+ [C-004] notification → src/modules/notification/ (6 files: service+event)
74
+
75
+ Điều chỉnh nếu cần:
76
+ - Đổi tên: "C-002 → profile" hoặc nhập tên khác
77
+ - Bỏ component: "bỏ C-004"
78
+ - Thêm component: "thêm reporting tại src/reporting/"
79
+ - Merge: "merge C-001 và C-002 thành auth-user"
80
+
81
+ Confirm danh sách? [y] hoặc nhập điều chỉnh:
82
+ ```
83
+
84
+ Sau khi confirm, assign C-XXX IDs theo thứ tự tăng dần.
85
+
86
+ ---
87
+
88
+ ### Bước 4: Scan sâu từng component
89
+
90
+ Với mỗi component, đọc code files bên trong để extract:
91
+
92
+ **4a. Responsibilities:**
93
+ - Public method names trong service files
94
+ - Class-level comments / JSDoc nếu có
95
+ - Export declarations
96
+
97
+ **4b. Owned Entities:**
98
+ - Entity / model files trong component directory
99
+ - Decorators: `@Entity()` (TypeORM), Prisma model blocks, `@Schema()` (Mongoose), SQLAlchemy models
100
+ - Migration files gắn với component
101
+
102
+ **4c. Public Interface:**
103
+ - Controller files: HTTP method + path mỗi endpoint
104
+ - Event publisher: `@EventPattern`, `eventEmitter.emit()`, message queue producers
105
+ - Exported service methods nếu là shared library
106
+
107
+ **4d. Dependencies:**
108
+ - Import statements referencing other component directories
109
+ - Injectable services từ other modules
110
+ - HTTP client calls đến other services
111
+
112
+ **4e. Business Rules:**
113
+ - Validation decorators (`@Min`, `@Max`, `@IsEmail`, custom validators)
114
+ - Guard conditions trong service (`if (!user.isActive) throw ...`)
115
+ - Domain events và điều kiện trigger
116
+ - Comments có từ khóa: "must", "should", "only", "never", "không được"
117
+
118
+ **4f. Internal design (cho cdd.md):**
119
+ - Module structure: list sub-modules / file groups
120
+ - ORM/storage usage: repository pattern, raw queries, cache decorators
121
+ - Internal service/repository interface contracts
122
+
123
+ ---
124
+
125
+ ### Bước 5: Identify cross-component entities
126
+
127
+ Trong quá trình scan, ghi nhận các entities được **import hoặc reference từ nhiều hơn 1 component** → đây là candidate Shared Entities cho `domain.md`.
128
+
129
+ Ví dụ: `Order` được dùng trong `payment/` và `inventory/` → candidate Shared Entity, cần xác định owner.
130
+
131
+ ---
132
+
133
+ ### Bước 6: Hỏi clarification — batch
134
+
135
+ Sau khi scan xong tất cả components, hỏi một lần — tối đa **5 câu tổng cộng**. Ưu tiên những điểm ảnh hưởng đến component boundaries hoặc entity ownership.
136
+
137
+ ```
138
+ Cần làm rõ {N} điểm:
139
+
140
+ [C-001 auth]
141
+ Q1. Method `validateToken` được call từ cả auth/ và user/ —
142
+ đây là public interface hay internal helper?
143
+ [public / internal / skip]
144
+
145
+ [cross-component]
146
+ Q2. Entity `Order` được dùng trong payment/ và inventory/ —
147
+ component nào sở hữu?
148
+ [payment / inventory / skip]
149
+
150
+ Trả lời hoặc "skip all" để đánh dấu NEEDS_CLARIFY hết:
151
+ ```
152
+
153
+ ---
154
+
155
+ ### Bước 7: Generate artifacts
156
+
157
+ Với mỗi component, generate 2 files dùng templates tương ứng:
158
+
159
+ **`crd.md`** — WHAT (dùng `.claude/templates/main/component/crd-template.md`):
160
+ - Role, Responsibilities, Owned Entities, Public Interface, Business Rules, Domain Events, Dependencies
161
+
162
+ **`cdd.md`** — HOW (dùng `.claude/templates/main/component/cdd-template.md`):
163
+ - Module structure, Internal data flow, Storage & persistence, Internal interfaces, Technical decisions
164
+
165
+ **Nguyên tắc:**
166
+ - Mọi phần không detect được → NEEDS_CLARIFY, không bịa
167
+ - Business rules detect được từ code → đánh dấu `(detected from code)`
168
+ - crd.md không chứa internal design; cdd.md không chứa public interface
169
+
170
+ ---
171
+
172
+ ### Bước 8: Cascade Proposals — domain.md
173
+
174
+ Nếu có Shared Entities được phát hiện ở Bước 5:
175
+
176
+ ```
177
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
178
+ SHARED ENTITIES DETECTED
179
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
180
+ Các entities sau được dùng bởi nhiều components.
181
+ Đề xuất thêm vào specs/main/domain.md (Shared Entities):
182
+
183
+ Entity: Order (Owner: C-003-payment)
184
+ Dùng bởi: C-003-payment, C-005-inventory
185
+ Fields detected: id, userId, items[], status, totalAmount
186
+
187
+ Entity: User (Owner: C-001-auth)
188
+ Dùng bởi: C-001-auth, C-002-user, C-004-notification
189
+ Fields detected: id, email, role, isActive
190
+
191
+ Apply cascade proposals vào domain.md? [y/n/edit]
192
+ ```
193
+
194
+ Nếu `y` → update `specs/main/domain.md` Shared Entities section.
195
+ Nếu `edit` → hỏi chỉnh sửa từng entity trước khi apply.
196
+
197
+ ---
198
+
199
+ ### Bước 9: Review và save artifacts
200
+
201
+ ```
202
+ Sẽ tạo {N} components ({2N} files):
203
+ ✓ specs/main/component/C-001-auth/crd.md (3 NEEDS_CLARIFY)
204
+ ✓ specs/main/component/C-001-auth/cdd.md (1 NEEDS_CLARIFY)
205
+ ✓ specs/main/component/C-002-user/crd.md (0 NEEDS_CLARIFY)
206
+ ✓ specs/main/component/C-002-user/cdd.md (2 NEEDS_CLARIFY)
207
+ ...
208
+
209
+ Ghi tất cả? [y] hoặc review từng file trước [r]:
210
+ ```
211
+
212
+ - `y` → ghi tất cả
213
+ - `r` → hiển thị lần lượt từng file, user confirm / skip / edit từng cái
214
+
215
+ ---
216
+
217
+ ### Bước 10: Điền Component Index vào prd.md
218
+
219
+ Sau khi artifacts đã được ghi, update `specs/main/prd.md` Component Index với danh sách đã confirm:
220
+
221
+ ```
222
+ Sẽ điền Component Index vào prd.md:
223
+ C-001 | auth | Xác thực và phân quyền người dùng | active
224
+ C-002 | user | Quản lý thông tin người dùng | active
225
+ C-003 | payment | Xử lý thanh toán và giao dịch | active
226
+ C-004 | notification | Gửi thông báo qua email/push | active
227
+
228
+ Apply? [y/n]
229
+ ```
230
+
231
+ ---
232
+
233
+ ### Bước 11: Summary
234
+
235
+ ```
236
+ ✓ Generated {N} components:
237
+ specs/main/component/C-001-auth/ (crd.md + cdd.md)
238
+ specs/main/component/C-002-user/ (crd.md + cdd.md)
239
+ ...
240
+
241
+ ✓ prd.md Component Index: {N} entries đã được điền
242
+
243
+ {nếu có} ✓ domain.md Shared Entities: {N} entities đã được cascade
244
+
245
+ NEEDS_CLARIFY summary — {total} items:
246
+ C-001-auth: {n} — [business rules, domain events, ...]
247
+ C-002-user: {n} — [entity ownership, ...]
248
+ ...
249
+
250
+ Bước tiếp theo:
251
+ /spec-brownfield-feature → discover features, generate frd.md + fdd.md, điền Feature Index
252
+ ```
253
+
254
+ ---
255
+
256
+ ## Verification
257
+
258
+ - [ ] Mỗi component có đủ crd.md + cdd.md
259
+ - [ ] crd.md không chứa internal design (đã ở cdd.md)
260
+ - [ ] cdd.md không chứa public interface (đã ở crd.md)
261
+ - [ ] Mọi entity trong crd.md có đúng 1 owner component (hoặc NEEDS_CLARIFY)
262
+ - [ ] Dependencies chỉ reference C-XXX IDs, không reference file paths
263
+ - [ ] Business rules detect được đánh dấu `(detected from code)`
264
+ - [ ] prd.md Component Index đã được update
265
+ - [ ] Shared Entities đã được cascade vào domain.md (nếu có)
266
+ - [ ] NEEDS_CLARIFY items được list đầy đủ trong summary
@@ -0,0 +1,239 @@
1
+ ---
2
+ name: spec-brownfield-feature
3
+ description: Discover features từ code, generate frd.md + fdd.md cho từng feature, điền Feature Index vào prd.md. Phải chạy /spec-brownfield-component trước vì fdd.md tham chiếu C-XXX từ Component Index.
4
+ ---
5
+
6
+ # spec-brownfield-feature
7
+
8
+ ## Overview
9
+
10
+ Tạo `specs/main/feature/{F-XXX}-{feature-name}/frd.md` và `fdd.md` cho các features trong brownfield project.
11
+
12
+ Skill này **tự discover** features từ routes, use cases, và test files, sau đó scan sâu để extract user stories, AC, và inter-component flows. Khi hoàn thành, **điền Feature Index vào prd.md**.
13
+
14
+ **Phải chạy sau `/spec-brownfield-component`** vì fdd.md mô tả inter-component interaction và cần tham chiếu C-XXX IDs từ Component Index đã được điền.
15
+
16
+ ## When to Use
17
+
18
+ - Sau khi `/spec-brownfield-component` đã chạy xong
19
+ - prd.md có Component Index (C-XXX IDs đã có)
20
+ - Cần generate feature artifacts cho brownfield project
21
+
22
+ ## When NOT to Use
23
+
24
+ - `/spec-brownfield-component` chưa chạy → chạy component skill trước
25
+ - Greenfield project → feature artifacts mọc dần qua cascade từ integrations (`/spec-new`)
26
+
27
+ ---
28
+
29
+ ## Process
30
+
31
+ ### Bước 1: Load context và xác định path
32
+
33
+ **Path:** Nếu có ARGUMENT là path → dùng làm root. Nếu không → CWD.
34
+
35
+ **Load:**
36
+ - `specs/main/prd.md` — kiểm tra Component Index đã được điền
37
+ - `specs/main/domain.md` — đọc Glossary và Shared Entities
38
+ - `specs/main/component/*/crd.md` — đọc Public Interface của từng component (để cross-reference trong fdd.md)
39
+
40
+ **Kiểm tra preconditions:**
41
+
42
+ Nếu `prd.md` không tồn tại → dừng:
43
+ > `prd.md` chưa có nội dung. Hãy chạy `/spec-brownfield-init` trước.
44
+
45
+ Nếu `prd.md` Component Index còn trống (không có C-XXX entries) → dừng:
46
+ > Component Index chưa có entries. Hãy chạy `/spec-brownfield-component` trước.
47
+ > fdd.md cần tham chiếu C-XXX để mô tả inter-component flows.
48
+
49
+ Nếu `specs/main/component/` không có crd.md nào → cảnh báo tương tự và dừng.
50
+
51
+ **Attachments:**
52
+ > Bạn có tài liệu bổ sung nào không? (user stories, test plans, wireframes, existing specs)
53
+ > Nhập `không` để bỏ qua.
54
+
55
+ ---
56
+
57
+ ### Bước 2: Discover feature boundaries
58
+
59
+ Scan codebase để tìm feature candidates. Tìm theo thứ tự ưu tiên:
60
+
61
+ 1. **Use case / interactor files**: `*UseCase.{ts,js}`, `*Interactor.{ts,js}`, `*Handler.{ts,js}`, thư mục `application/*/`
62
+ 2. **Route groups**: controller files grouped by path prefix (`/auth/*`, `/payment/*`, `/orders/*`)
63
+ 3. **Test describe blocks**: `describe('User Registration', ...)`, `describe('Checkout Flow', ...)`
64
+ 4. **Page / screen directories**: `pages/{feature}/`, `screens/{feature}/`, `views/{feature}/`
65
+
66
+ Với mỗi candidate, ghi lại:
67
+ - Entry point file(s)
68
+ - Route paths liên quan
69
+ - Test files có hay không
70
+ - Components được call (từ import statements) → map sang C-XXX IDs
71
+
72
+ ---
73
+
74
+ ### Bước 3: Confirm feature list
75
+
76
+ ```
77
+ Tôi phát hiện {N} features từ codebase:
78
+ [F-001] user-registration → RegisterUseCase + POST /auth/register (5 tests)
79
+ [F-002] authentication → POST /auth/login, /auth/refresh (3 tests)
80
+ [F-003] checkout-flow → CheckoutUseCase + /checkout/* (8 tests)
81
+ [F-004] order-history → GET /orders/* (no tests)
82
+
83
+ Điều chỉnh nếu cần:
84
+ - Đổi tên: "F-003 → place-order"
85
+ - Bỏ feature: "bỏ F-004"
86
+ - Thêm feature: "thêm password-reset"
87
+ - Merge: "merge F-001 và F-002 thành auth-flow"
88
+
89
+ Confirm danh sách? [y] hoặc nhập điều chỉnh:
90
+ ```
91
+
92
+ Sau khi confirm, assign F-XXX IDs theo thứ tự tăng dần.
93
+
94
+ ---
95
+
96
+ ### Bước 4: Scan sâu từng feature
97
+
98
+ **4a. User stories — infer từ:**
99
+ - Use case class names và public methods → action descriptions
100
+ - Route names + HTTP methods → "As a user, I want to POST /auth/register..."
101
+ - Test `describe` / `it` blocks → `it('should register a new user', ...)` → user story
102
+
103
+ Đánh dấu source: `(inferred from routes)` hoặc `(from tests)`.
104
+
105
+ **4b. Acceptance criteria — extract từ:**
106
+ - Test assertions: `expect(response.status).toBe(201)`, `expect(user.email).toBe(...)`
107
+ - Input validation rules từ DTO / request validators
108
+ - Expected error codes / messages từ error handling code
109
+
110
+ Nếu không có tests → AC section sẽ là NEEDS_CLARIFY.
111
+
112
+ **4c. Components consumed — extract từ:**
113
+ - Import statements trong feature's controllers / use cases → map sang C-XXX IDs (đã có từ Component Index)
114
+ - Cross-reference với crd.md Public Interface để confirm
115
+
116
+ **4d. Inter-component flow cho fdd.md — extract từ:**
117
+ - Call chain trong use case file: `authService → userRepo → notificationService`
118
+ - Event publications và subscriptions trong flow
119
+ - Transaction boundaries nếu explicit (`@Transaction`, `queryRunner`)
120
+ - Retry / timeout config nếu detect được
121
+
122
+ ---
123
+
124
+ ### Bước 5: Hỏi clarification — batch
125
+
126
+ Sau khi scan xong tất cả, hỏi một lần — tối đa **5 câu tổng cộng**:
127
+
128
+ ```
129
+ Cần làm rõ {N} điểm:
130
+
131
+ [F-001 user-registration]
132
+ Q1. Flow này chỉ register bằng email/password, hay còn OAuth nữa?
133
+ (Tôi detect email/password flow nhưng thấy OAuth client được import)
134
+ [email/password only / cả hai / skip]
135
+
136
+ [F-003 checkout-flow]
137
+ Q2. Sau khi place order, payment được xử lý sync hay async?
138
+ (Tôi thấy PaymentService được call nhưng không rõ transaction boundary)
139
+ [sync / async / skip]
140
+
141
+ Trả lời hoặc "skip all":
142
+ ```
143
+
144
+ ---
145
+
146
+ ### Bước 6: Generate artifacts
147
+
148
+ Với mỗi feature, generate 2 files dùng templates tương ứng:
149
+
150
+ **`frd.md`** — WHAT (dùng `.claude/templates/main/feature/frd-template.md`):
151
+ - Description và business goal (infer từ feature name + use case, NEEDS_CLARIFY nếu không rõ)
152
+ - User stories (đánh dấu source)
153
+ - Acceptance criteria (extract từ tests nếu có, NEEDS_CLARIFY nếu không)
154
+ - Scope: In scope từ detected routes/actions; Out of scope → NEEDS_CLARIFY
155
+ - Components consumed: list C-XXX từ Component Index
156
+ - Dependencies: feature-to-feature dependencies nếu detect được
157
+
158
+ **`fdd.md`** — HOW / inter-component (dùng `.claude/templates/main/feature/fdd-template.md`):
159
+ - Inter-component data flow: sequence diagram từ detected call chain (Mermaid hoặc ASCII)
160
+ - Orchestration: retry / timeout / fallback nếu detect được
161
+ - Cross-component invariants: transaction boundaries nếu detect được
162
+
163
+ **Nguyên tắc:**
164
+ - fdd.md là **file mỏng** — chỉ mô tả tương tác giữa components, không lặp nội dung từ crd.md / cdd.md
165
+ - Mọi phần không detect được → NEEDS_CLARIFY, không bịa
166
+
167
+ ---
168
+
169
+ ### Bước 7: Review và save artifacts
170
+
171
+ ```
172
+ Sẽ tạo {N} features ({2N} files):
173
+ ✓ specs/main/feature/F-001-user-registration/frd.md (4 NEEDS_CLARIFY)
174
+ ✓ specs/main/feature/F-001-user-registration/fdd.md (2 NEEDS_CLARIFY)
175
+ ✓ specs/main/feature/F-002-authentication/frd.md (1 NEEDS_CLARIFY)
176
+ ✓ specs/main/feature/F-002-authentication/fdd.md (0 NEEDS_CLARIFY)
177
+ ...
178
+
179
+ Ghi tất cả? [y] hoặc review từng file trước [r]:
180
+ ```
181
+
182
+ ---
183
+
184
+ ### Bước 8: Điền Feature Index vào prd.md
185
+
186
+ Sau khi artifacts đã được ghi, update `specs/main/prd.md` Feature Index:
187
+
188
+ ```
189
+ Sẽ điền Feature Index vào prd.md:
190
+ F-001 | user-registration | Đăng ký tài khoản mới qua email/password | Must | TODO
191
+ F-002 | authentication | Đăng nhập và refresh token | Must | TODO
192
+ F-003 | checkout-flow | Đặt hàng và thanh toán | Must | TODO
193
+ F-004 | order-history | Xem lịch sử đơn hàng | Should | TODO
194
+
195
+ Apply? [y/n]
196
+ ```
197
+
198
+ ---
199
+
200
+ ### Bước 9: Summary
201
+
202
+ ```
203
+ ✓ Generated {N} features:
204
+ specs/main/feature/F-001-user-registration/ (frd.md + fdd.md)
205
+ specs/main/feature/F-002-authentication/ (frd.md + fdd.md)
206
+ ...
207
+
208
+ ✓ prd.md Feature Index: {N} entries đã được điền
209
+
210
+ NEEDS_CLARIFY summary — {total} items:
211
+ F-001: {n} — [business goal, out of scope, AC, ...]
212
+ F-002: {n} — [...]
213
+ ...
214
+
215
+ Brownfield init hoàn tất! Main artifacts:
216
+ specs/main/
217
+ ├── prd.md (Component Index: {N} | Feature Index: {N})
218
+ ├── domain.md (Glossary: {N} terms | Shared Entities: {N})
219
+ ├── sad.md
220
+ ├── component/ ({N} components, mỗi cái có crd.md + cdd.md)
221
+ └── feature/ ({N} features, mỗi cái có frd.md + fdd.md)
222
+
223
+ Để bắt đầu implement, dùng /spec-new để tạo integration đầu tiên.
224
+ grep "NEEDS_CLARIFY" để tìm và fill in khi có thêm context.
225
+ ```
226
+
227
+ ---
228
+
229
+ ## Verification
230
+
231
+ - [ ] Chạy sau `/spec-brownfield-component` — Component Index đã có entries
232
+ - [ ] Mỗi feature có đủ frd.md + fdd.md
233
+ - [ ] frd.md có ít nhất 1 user story hoặc NEEDS_CLARIFY rõ ràng
234
+ - [ ] fdd.md chỉ mô tả inter-component interaction — không lặp nội dung từ crd.md / cdd.md
235
+ - [ ] Components consumed list reference đúng C-XXX IDs từ Component Index
236
+ - [ ] User stories và AC detect được đánh dấu source `(inferred)` hoặc `(from tests)`
237
+ - [ ] Feature không có tests → AC section có NEEDS_CLARIFY rõ ràng
238
+ - [ ] prd.md Feature Index đã được update
239
+ - [ ] NEEDS_CLARIFY items được list đầy đủ trong summary