@relipa/ai-flow-kit 0.2.0-beta.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/custom/rules/java/spring-boot-rules.md +209 -0
  2. package/custom/rules/javascript/nestjs-examples.md +41 -0
  3. package/custom/rules/javascript/nestjs-rules.md +42 -0
  4. package/custom/rules/javascript/nodejs-express-examples.md +35 -0
  5. package/custom/rules/javascript/nodejs-express-rules.md +49 -0
  6. package/custom/rules/javascript/reactjs-examples.md +380 -0
  7. package/custom/rules/javascript/reactjs-rules.md +173 -0
  8. package/custom/rules/php/php-examples.md +161 -0
  9. package/custom/rules/php/php-rules.md +127 -0
  10. package/custom/rules/python/python-django-examples.md +34 -0
  11. package/custom/rules/python/python-django-rules.md +48 -0
  12. package/custom/rules/python/python-examples.md +32 -0
  13. package/custom/rules/python/python-fastapi-examples.md +30 -0
  14. package/custom/rules/python/python-fastapi-rules.md +35 -0
  15. package/custom/rules/python/python-ml-examples.md +187 -0
  16. package/custom/rules/python/python-ml-rules.md +121 -0
  17. package/custom/rules/python/python-rules.md +58 -0
  18. package/custom/skills/ba-skills/skill-ba-qna-template-v1.md +4 -4
  19. package/custom/skills/ba-skills/skill-ba-qna-v1.md +6 -0
  20. package/custom/skills/create-system-requirement/SKILL.md +52 -16
  21. package/custom/skills/create-system-requirement/system-requirement-template-v1.md +128 -0
  22. package/custom/skills/impact-analysis/SKILL.md +106 -106
  23. package/custom/skills/ingest-data/SKILL.md +53 -5
  24. package/custom/skills/report-customer/SKILL.md +99 -99
  25. package/custom/templates/nestjs.md +5 -72
  26. package/custom/templates/nodejs-express.md +5 -73
  27. package/custom/templates/php-plain.md +5 -261
  28. package/custom/templates/php.md +5 -261
  29. package/custom/templates/python-django.md +5 -71
  30. package/custom/templates/python-fastapi.md +5 -54
  31. package/custom/templates/python-ml.md +1 -269
  32. package/custom/templates/python.md +5 -79
  33. package/custom/templates/reactjs.md +5 -492
  34. package/custom/templates/shared/create-testcase-workflow.md +30 -2
  35. package/custom/templates/shared/gate-workflow.md +5 -3
  36. package/custom/templates/shared/ml-gate-workflow.md +1 -0
  37. package/custom/templates/spring-boot.md +5 -224
  38. package/docs/common/CHANGELOG.md +20 -10
  39. package/package.json +1 -1
  40. package/scripts/init.js +143 -40
  41. package/scripts/link-resolver.js +60 -24
  42. package/scripts/ticket-writer.js +72 -3
@@ -133,17 +133,41 @@ Nếu người dùng yêu cầu sửa (thêm/bớt ý, đổi log đích, sửa
133
133
  - **Chỉ là tham khảo** → hiển thị: `ℹ️ Nội dung này không phát sinh task — chỉ lưu làm tài liệu tham khảo. Gate 3 kết thúc.` rồi chạy `ak gate 3 skip --ticket [ticket-id] --reason "<1 câu lý do>"` (không cần `ak gate 3 start` trước) và dừng, không hỏi thêm. Việc này đóng gate đúng cách — dashboard (ai-flow-ex) hiển thị "⏭ Gate 3 skipped — \<lý do\>" thay vì để task treo mãi ở trạng thái "sẵn sàng chạy Gate 3".
134
134
  - **Có hành động cụ thể** → tiếp tục Bước 3. Khi không chắc (ví dụ nội dung vừa có FYI vừa có 1 ý cần sửa code) — nghiêng về đề xuất task cho phần cần hành động, bỏ qua phần FYI, không tự bịa task cho phần không rõ.
135
135
 
136
+ **Riêng khi nguồn là `Confirmations-Log`** (khách hàng CHỐT chính thức 1 thay đổi requirement) — đây là trường hợp dễ đề xuất thiếu task nhất nếu chỉ dựa vào Action items viết sẵn trong nội dung (vd chỉ thấy 1 bug fix được nêu tên, bỏ sót toàn bộ phần spec/testcase phát sinh từ chính rule vừa chốt). Trước khi sang Bước 3, tự chạy qua đủ checklist tối thiểu sau — không hiển thị checklist này cho PM, chỉ dùng để tự rà soát không bỏ sót:
137
+
138
+ 1. **UC Spec** — functionId này đã có UC Spec chưa, và rule vừa chốt đã phản ánh trong Spec chưa? Chưa → task `spec`.
139
+ 2. **System Requirement** — chỉ cần nếu có task `coding` theo sau (Gate 1 coding sẽ tự chặn nếu System Requirement thiếu/lệch version, xem `CLAUDE.md` pre-check) → task `system-requirement`.
140
+ 3. **Impact analysis** — thay đổi có đủ phức tạp/rủi ro (ảnh hưởng nhiều module/feature khác, hoặc PM cần thấy effort/scope trước khi giao việc) để cần 1 tài liệu đánh giá riêng, tách khỏi Gate 1 coding không? Cần → task `impact-analysis`.
141
+ 4. **Coding** — có thay đổi hành vi hệ thống cần code không? Cần → task `coding` (tách thành nhiều task nhỏ nếu phạm vi lớn, mỗi task 1 title riêng).
142
+ 5. **Data migration/backfill** — rule mới có áp dụng hồi tố lên dữ liệu đã tồn tại không (khác với chỉ áp dụng từ nay về sau)? Có → thêm 1 task `coding` **riêng** cho việc migration/backfill, không gộp chung với task coding chính (2 rủi ro/effort khác nhau, cần review riêng).
143
+ 6. **Create/Update testcase** — cần → task `test`.
144
+ 7. **Execute test** — cần → task `execute-test`.
145
+
146
+ Không phải mục nào cũng luôn có (case rule chỉ áp dụng tương lai thì mục 5 = không cần) — nhưng phải đi qua đủ 7 mục và có lý do trước khi kết luận không cần, không bỏ qua mục nào chỉ vì nội dung entry không viết thành Action item rõ ràng.
147
+
136
148
  ### 5.3 Bước 3 — Đề xuất danh sách task
137
149
 
138
150
  Mỗi task gồm:
139
151
 
140
152
  | Trường | Ghi chú |
141
153
  |---|---|
142
- | `type` | `spec` (tạo/update UC Spec) · `coding` · `test` · `other` (update tài liệu không thuộc BA/QA/Dev, vd Rules) |
154
+ | `type` | `spec` (tạo/update UC Spec) · `system-requirement` (tạo/update System Requirement) · `impact-analysis` (đánh giá phạm vi ảnh hưởng, tách riêng khỏi Gate 1 coding) · `coding` (bao gồm cả migration/backfill, tách task riêng nếu cần) · `test` (tạo/update testcase) · `execute-test` (thực thi testcase có sẵn) · `other` (update tài liệu không thuộc BA/QA/Dev, vd Rules) |
143
155
  | `title` | Ngắn, hành động rõ (vd "Cập nhật flow OTP theo feedback khách — tăng thời hạn 30s → 90s") |
144
- | `track` | BA / Dev / QA — để PM biết ai sẽ nhận task này |
156
+ | `track` | BA / Dev / QA / Analyst — để PM biết ai sẽ nhận task này |
145
157
  | `description` | Theo đúng template mục 6.1 `PM Workflow_v1.0.md`: |
146
158
 
159
+ Mỗi `type` map thẳng vào 1 task type có sẵn khi người nhận chạy `ak use TICKET-XXX` (không cần Gate workflow mới — xem `scripts/use.js` cho danh sách đầy đủ):
160
+
161
+ | `type` task | Task type chọn ở `ak use` |
162
+ |---|---|
163
+ | `spec` | 📋 Create Spec |
164
+ | `system-requirement` | 📐 Create System Requirement |
165
+ | `impact-analysis` | 📊 Impact Analysis |
166
+ | `coding` | 🐛 Bug Fix / ✨ Feature / 🔄 Refactor (tuỳ nội dung task) |
167
+ | `test` | ✅ Create TestCase |
168
+ | `execute-test` | ▶️ Execute Test |
169
+ | `other` | Không map task type nào — tuỳ nội dung, người nhận tự xử lý ngoài Gate workflow |
170
+
147
171
  ```text
148
172
  ## Nội dung task
149
173
  [Mô tả task do AI đề xuất]
@@ -190,33 +214,57 @@ Check LOCAL trước, chỉ hỏi khi thật sự chưa biết (Vấn đề 5.1)
190
214
  2. Đã có → dùng luôn, hiển thị rõ cho PM biết đang dùng project nào + nguồn (đã lưu từ lần trước).
191
215
  3. Chưa có → hiển thị danh sách project vừa fetch được, PM chọn 1 → lưu lại bằng `ak backlog-set-default-project <id> <key>` hoặc `ak jira-set-default-project <key>` — để lần sau không hỏi lại.
192
216
 
217
+ ### 5.6b Bước 6b — Ticket cha (chỉ hỏi khi danh sách có ≥ 2 task)
218
+
219
+ Nếu danh sách chỉ có 1 task, không có gì để gộp — coi `parentTicket.mode = "none"` và bỏ qua bước này.
220
+
221
+ Nếu ≥ 2 task, hỏi đúng 1 câu:
222
+
223
+ ```text
224
+ Gộp N task này dưới 1 ticket cha?
225
+ 1. Tạo mới ticket cha
226
+ 2. Dùng ticket cha có sẵn — cho biết ticket ID
227
+ 3. Không cần ticket cha
228
+ ```
229
+
230
+ - **(1)** → hỏi PM 1 tiêu đề ngắn cho ticket cha (gợi ý: dùng lại "Tổng quan nội dung thay đổi" đã soạn cho task `spec` ở Bước 3, nếu có; không có thì tự tóm tắt 1 câu). `parentTicket = { "mode": "create", "title": "...", "description": "..." }`.
231
+ - **(2)** → PM nhập ticket ID có sẵn. `parentTicket = { "mode": "existing", "existingId": "<ID do PM nhập>" }`. Việc xác minh ticket đó có tồn tại thật diễn ra ở Bước 7 (khi gọi `ak tasks create-tickets`) — không tự coi là đúng trước khi có kết quả lệnh.
232
+ - **(3)** → `parentTicket = { "mode": "none" }`.
233
+
234
+ ⚠️ **Chưa xác minh trên instance thật:** liên kết cha-con cần Backlog project đã bật tính năng phân cấp issue (Subtasking), hoặc Jira project hỗ trợ field `parent` trực tiếp (rõ nhất với project dạng team-managed; company-managed có thể cần issue type `Subtask` riêng — chưa test). Nếu Bước 7 báo lỗi `parent-create-failed`/`parent-not-found`, hoặc 1 task con lỗi do gán parent thất bại — hiển thị nguyên lỗi cho PM, hỏi PM muốn: thử lại với ticket cha khác, tiếp tục tạo các ticket con không gắn parent (`mode: "none"`), hay dừng lại để PM xử lý cấu hình Backlog/Jira trước.
235
+
193
236
  ### 5.7 Bước 7 — Tạo ticket
194
237
 
195
238
  1. Ghi danh sách task đã duyệt ra 1 file JSON tạm (vd `.aiflow/tmp/tasks-[ticketId].json`), đúng shape mà `ak tasks create-tickets` đọc (xem `scripts/ticket-writer.js`):
196
239
  ```json
197
240
  {
198
241
  "target": "backlog",
242
+ "parentTicket": { "mode": "create", "title": "...", "description": "..." },
199
243
  "tasks": [
200
244
  { "type": "coding", "title": "...", "description": "..." }
201
245
  ]
202
246
  }
203
247
  ```
248
+ `parentTicket` lấy nguyên từ kết quả Bước 6b (bỏ field này hoặc `{"mode": "none"}` nếu không gộp ticket cha).
204
249
  2. Chạy `ak tasks create-tickets <file> --json`.
205
250
  3. Đọc kết quả JSON trả về:
206
251
  - `{"error":"missing-write-credentials", "field": "...", "message": "..."}` → **đây không phải lỗi hệ thống** — hiển thị đúng `message` cho PM, hỏi PM nhập giá trị key ngay trong hội thoại (dùng luôn khung chat làm nơi PM "nhập & submit"), nhận giá trị → chạy `ak credentials set <field> "<giá trị PM vừa nhập>"` → chạy lại bước 2 (retry đúng 1 lần; nếu vẫn lỗi, báo PM key có thể sai/chưa đủ quyền, không tự thử lại vô hạn).
207
252
  - `{"error":"missing-project", ...}` → quay lại Bước 6 (chưa xác định được project).
208
- - Thành công (`ok: true`)mỗi task `ticketId` + `url` riêng; task nào `ok: false` (lỗi phía Backlog/Jira, vd thiếu field) báo cho PM, các task khác đã tạo vẫn giữ nguyên (không rollback).
253
+ - `{"error":"parent-not-found", "message": "..."}` → ticket cha PM cung cấp Bước 6b (2) không tồn tại/không đọc được báo PM, quay lại Bước 6b để nhập ID khác hoặc chọn phương án khác.
254
+ - `{"error":"parent-create-failed", "message": "..."}` → tạo ticket cha thất bại (thường do project chưa hỗ trợ phân cấp issue) — hiển thị nguyên lỗi, hỏi PM có muốn tạo lại không gắn ticket cha (`mode: "none"`) hay dừng lại.
255
+ - Thành công (`ok: true`) → mỗi task có `ticketId` + `url` riêng, có thêm `parent` (ticket cha vừa tạo/dùng, nếu có); task nào `ok: false` (lỗi phía Backlog/Jira, vd thiếu field) → báo rõ cho PM, các task khác đã tạo vẫn giữ nguyên (không rollback).
209
256
 
210
257
  ### 5.8 Bước 8 — Ghi ngược liên kết + đóng Gate
211
258
 
212
- 1. Append vào cuối đúng entry gốc (Meetings-Log/QnA-Log/Confirmations-Log) 1 dòng:
259
+ 1. Append vào cuối đúng entry gốc (Meetings-Log/QnA-Log/Confirmations-Log) 1 dòng, kèm ticket cha nếu có:
213
260
  ```text
214
- → Tasks created: TICKET-101 (coding), TICKET-102 (test)
261
+ → Tasks created: TICKET-100 (parent), TICKET-101 (coding), TICKET-102 (test)
215
262
  ```
216
263
  Việc sửa file này đi qua đúng branch đang dùng ở Gate 2 (không tạo MR riêng — gộp vào cùng thay đổi, hoặc nếu MR đã mở/merge thì tạo 1 commit nhỏ tiếp theo trên cùng branch/1 MR mới tuỳ trạng thái branch lúc đó).
217
264
  2. Hiển thị tổng kết:
218
265
  ```text
219
266
  ✅ GATE 3 DONE — Đã tạo N/N ticket trên [Backlog/Jira]:
267
+ - Ticket cha: TICKET-100 — <url> (bỏ dòng này nếu không gộp ticket cha)
220
268
  - TICKET-101 (coding) — <url>
221
269
  - TICKET-102 (test) — <url>
222
270
  → Dev/QA chạy `ak use TICKET-XXX` trên từng ticket để bắt đầu Gate tương ứng (Coding/QA workflow hiện có).
@@ -1,99 +1,99 @@
1
- ---
2
- name: report-customer
3
- description: Write an incident report for customers or customer service after a production bug fix. Non-technical, easy-to-understand language.
4
- keywords: report, incident, customer, customer service, CS
5
- ---
6
-
7
- # Report Customer (Incident Report)
8
-
9
- ## When to use
10
-
11
- - After fixing a bug that affects users/customers
12
- - Customer Service needs a report explaining the cause to customers
13
- - Need to document the incident for future reference
14
-
15
- ---
16
-
17
- ## Process
18
-
19
- ### Step 1: Gather information
20
-
21
- Collect from `investigate-bug` results or developer descriptions:
22
- - Ticket ID and title
23
- - Discovery time / impact duration
24
- - Number of affected users / orders
25
- - Identified root cause
26
- - Deployment status
27
-
28
- ### Step 2: Write the report
29
-
30
- Fill in the structure below. **Use simple language, avoiding technical jargon.**
31
-
32
- ---
33
-
34
- ## Standard Structure
35
-
36
- Output language: auto-detect from the ticket/task input — see `custom/rules/output-language.md`
37
- (Vietnamese ticket → Vietnamese report; otherwise English). CS can request a specific language
38
- explicitly, which overrides auto-detect. Structure below is shown in English.
39
-
40
- ```markdown
41
- ## 📋 Incident Verification Report
42
-
43
- **Ticket ID:** [ID]
44
- **Assigned to:** [Dev Name]
45
- **Resolution Date:** [YYYY-MM-DD]
46
- **Status:** ✅ Resolved / 🔄 In Progress
47
-
48
- ---
49
-
50
- ### 1. Summary
51
-
52
- [1–2 sentences describing the issue in non-technical language.
53
- Example: "Between 14:00–15:30 on [Date], some
54
- users were unable to complete order payments."]
55
-
56
- ---
57
-
58
- ### 2. Root Cause
59
-
60
- [Simple explanation, no code references.
61
- Example: "Due to a system update failing to correctly handle
62
- slow connections with the payment gateway."]
63
-
64
- ---
65
-
66
- ### 3. Resolution
67
-
68
- [Steps taken by the technical team.
69
- Example: "Updated the timeout handling mechanism and deployed
70
- the fix at 16:00 on [Date]."]
71
-
72
- ---
73
-
74
- ### 4. Data Impact
75
-
76
- - Was existing data affected? [Yes / No]
77
- - Data recovery status: [Update script run / Not necessary]
78
-
79
- ---
80
-
81
- ### 5. Expected Behavior
82
-
83
- [Actions the customer should take to verify normal operation.
84
- Example: "Customers can now attempt payment normally.
85
- If problems persist, please contact our support hotline..."]
86
- ```
87
-
88
- ---
89
-
90
- ## Writing Rules
91
-
92
- - ✅ Simple language, avoid technical jargon
93
- - ✅ Honest about scope and duration of impact
94
- - ✅ Focus on **user impact**, not code details
95
- - ✅ Always include instructions for the customer to verify the fix
96
- - ❌ Do not blame third parties unless certain
97
- - ❌ Do not commit to specific deadlines unless certain
98
-
99
- Present clearly and professionally, in the language determined above.
1
+ ---
2
+ name: report-customer
3
+ description: Write an incident report for customers or customer service after a production bug fix. Non-technical, easy-to-understand language.
4
+ keywords: report, incident, customer, customer service, CS
5
+ ---
6
+
7
+ # Report Customer (Incident Report)
8
+
9
+ ## When to use
10
+
11
+ - After fixing a bug that affects users/customers
12
+ - Customer Service needs a report explaining the cause to customers
13
+ - Need to document the incident for future reference
14
+
15
+ ---
16
+
17
+ ## Process
18
+
19
+ ### Step 1: Gather information
20
+
21
+ Collect from `investigate-bug` results or developer descriptions:
22
+ - Ticket ID and title
23
+ - Discovery time / impact duration
24
+ - Number of affected users / orders
25
+ - Identified root cause
26
+ - Deployment status
27
+
28
+ ### Step 2: Write the report
29
+
30
+ Fill in the structure below. **Use simple language, avoiding technical jargon.**
31
+
32
+ ---
33
+
34
+ ## Standard Structure
35
+
36
+ Output language: auto-detect from the ticket/task input — see `custom/rules/output-language.md`
37
+ (Vietnamese ticket → Vietnamese report; otherwise English). CS can request a specific language
38
+ explicitly, which overrides auto-detect. Structure below is shown in English.
39
+
40
+ ```markdown
41
+ ## 📋 Incident Verification Report
42
+
43
+ **Ticket ID:** [ID]
44
+ **Assigned to:** [Dev Name]
45
+ **Resolution Date:** [YYYY-MM-DD]
46
+ **Status:** ✅ Resolved / 🔄 In Progress
47
+
48
+ ---
49
+
50
+ ### 1. Summary
51
+
52
+ [1–2 sentences describing the issue in non-technical language.
53
+ Example: "Between 14:00–15:30 on [Date], some
54
+ users were unable to complete order payments."]
55
+
56
+ ---
57
+
58
+ ### 2. Root Cause
59
+
60
+ [Simple explanation, no code references.
61
+ Example: "Due to a system update failing to correctly handle
62
+ slow connections with the payment gateway."]
63
+
64
+ ---
65
+
66
+ ### 3. Resolution
67
+
68
+ [Steps taken by the technical team.
69
+ Example: "Updated the timeout handling mechanism and deployed
70
+ the fix at 16:00 on [Date]."]
71
+
72
+ ---
73
+
74
+ ### 4. Data Impact
75
+
76
+ - Was existing data affected? [Yes / No]
77
+ - Data recovery status: [Update script run / Not necessary]
78
+
79
+ ---
80
+
81
+ ### 5. Expected Behavior
82
+
83
+ [Actions the customer should take to verify normal operation.
84
+ Example: "Customers can now attempt payment normally.
85
+ If problems persist, please contact our support hotline..."]
86
+ ```
87
+
88
+ ---
89
+
90
+ ## Writing Rules
91
+
92
+ - ✅ Simple language, avoid technical jargon
93
+ - ✅ Honest about scope and duration of impact
94
+ - ✅ Focus on **user impact**, not code details
95
+ - ✅ Always include instructions for the customer to verify the fix
96
+ - ❌ Do not blame third parties unless certain
97
+ - ❌ Do not commit to specific deadlines unless certain
98
+
99
+ Present clearly and professionally, in the language determined above.
@@ -1,72 +1,5 @@
1
- # NestJS AI System Prompt
2
-
3
- You are an expert NestJS developer. Follow these modular architecture rules and best practices.
4
-
5
- ---
6
-
7
- ## Project Architecture
8
-
9
- NestJS follows a strict **Module-based** architecture. Every feature should be contained in its own module.
10
-
11
- ```
12
- src/
13
- ├── app.module.ts
14
- ├── main.ts
15
- └── features/
16
- └── [feature-name]/
17
- ├── [feature].module.ts
18
- ├── [feature].controller.ts
19
- ├── [feature].service.ts
20
- ├── [feature].entity.ts (if using TypeORM)
21
- └── dto/
22
- ├── create-[feature].dto.ts
23
- └── update-[feature].dto.ts
24
- ```
25
-
26
- ---
27
-
28
- ## NestJS Rules
29
-
30
- - Use **Constructor Injection** for all dependencies.
31
- - Always use **DTOs** (Data Transfer Objects) with `class-validator` for input validation.
32
- - Annotate controllers with `@Controller()`.
33
- - Use `@Injectable()` for services.
34
- - Leverage **Pipes** for data transformation and validation.
35
- - Leverage **Interceptors** for logging and response mapping.
36
-
37
- ```typescript
38
- // ✅ Good: DTO with validation
39
- export class CreateUserDto {
40
- @IsEmail()
41
- email: string;
42
-
43
- @IsString()
44
- @MinLength(8)
45
- password: string;
46
- }
47
- ```
48
-
49
- ---
50
-
51
- ## Testing Rules
52
-
53
- - Use the built-in **Jest** testing suite.
54
- - Use `Test.createTestingModule` to create isolated environments for unit tests.
55
-
56
- ```typescript
57
- describe('UsersService', () => {
58
- let service: UsersService;
59
-
60
- beforeEach(async () => {
61
- const module: TestingModule = await Test.createTestingModule({
62
- providers: [UsersService],
63
- }).compile();
64
-
65
- service = module.get<UsersService>(UsersService);
66
- });
67
-
68
- it('should be defined', () => {
69
- expect(service).toBeDefined();
70
- });
71
- });
72
- ```
1
+ # NestJS AI System Prompt
2
+
3
+ You are an expert NestJS developer. Follow these modular architecture rules and best practices.
4
+
5
+ > **Rules & code examples:** Read `.rules/javascript/nestjs-rules.md` (architecture, module rules, testing) and `.rules/javascript/nestjs-examples.md` (code samples per rule area) **in full** before writing or modifying any NestJS code in this project.
@@ -1,73 +1,5 @@
1
- # Node.js Express AI System Prompt
2
-
3
- You are an expert Node.js developer specialized in the Express.js framework. Follow these rules for building clean, maintainable, and secure backends.
4
-
5
- ---
6
-
7
- ## Project Structure
8
-
9
- Follow the **Controller-Service-Repository** pattern:
10
-
11
- ```
12
- src/
13
- ├── controllers/ # Route handlers — parse input, call service, return response
14
- ├── services/ # Business logic — core logic, database transactions
15
- ├── repositories/ # Data access — database queries, ORM interactions
16
- ├── models/ # Database models (Sequelize/Prisma/Mongoose)
17
- ├── middleware/ # Custom Express middleware (auth, logging)
18
- ├── routes/ # Route definitions
19
- ├── dtos/ # Input/Output Data Transfer Objects (if using TS)
20
- ├── utils/ # Stateless helper functions
21
- └── config/ # App configuration
22
- ```
23
-
24
- ---
25
-
26
- ## Express Rules
27
-
28
- - Use **Async/Await** for all asynchronous operations — avoid callbacks or manual promise chains.
29
- - Always use a global error handler middleware. Never use `try/catch` in controllers if you use an async-wrapper middleware.
30
- - Validate all incoming data using `Joi`, `Zod`, or `express-validator`.
31
- - Keep controllers thin; they should only handle request parsing and response formatting.
32
-
33
- ```javascript
34
- // ✅ Good: Controller calls service
35
- export const createUser = async (req, res, next) => {
36
- const userData = req.body;
37
- const user = await userService.create(userData);
38
- res.status(201).json(user);
39
- };
40
- ```
41
-
42
- ---
43
-
44
- ## Security Rules
45
-
46
- - Never expose stack traces in production.
47
- - Use `helmet` to set secure HTTP headers.
48
- - Sanitize input to prevent NoSQL/SQL injection.
49
- - Use `argon2` or `bcrypt` for password hashing.
50
- - Standardize on JWT for authentication.
51
-
52
- ---
53
-
54
- ## Testing Rules
55
-
56
- - Use **Jest** and **Supertest** for testing.
57
- - Test every API endpoint with integration tests.
58
- - Mock external services (Email, Payment Gateways).
59
-
60
- ```javascript
61
- // Example test
62
- import request from 'supertest';
63
- import app from '../app';
64
-
65
- describe('POST /api/users', () => {
66
- it('should create a new user', async () => {
67
- const response = await request(app)
68
- .post('/api/users')
69
- .send({ email: 'test@example.com', password: 'password123' });
70
- expect(response.status).toBe(201);
71
- });
72
- });
73
- ```
1
+ # Node.js Express AI System Prompt
2
+
3
+ You are an expert Node.js developer specialized in the Express.js framework. Follow these rules for building clean, maintainable, and secure backends.
4
+
5
+ > **Rules & code examples:** Read `.rules/javascript/nodejs-express-rules.md` (structure, framework rules, security, testing) and `.rules/javascript/nodejs-express-examples.md` (code samples per rule area) **in full** before writing or modifying any Express code in this project.