ai-developer-skill-os 1.7.1 → 1.9.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 (56) hide show
  1. package/README.md +97 -128
  2. package/bin/install.js +133 -32
  3. package/docs/CHI_TIET_SKILLS.md +89 -81
  4. package/docs/HUONG_DAN_SU_DUNG.md +51 -73
  5. package/package.json +1 -1
  6. package/skills/{qk-accessibility-audit → _archive_old_skills/qk-accessibility-audit}/SKILL.md +1 -1
  7. package/skills/{qk-agent-orchestrator → _archive_old_skills/qk-agent-orchestrator}/SKILL.md +1 -1
  8. package/skills/{qk-bug-fix → _archive_old_skills/qk-bug-fix}/SKILL.md +1 -1
  9. package/skills/{qk-component-generator → _archive_old_skills/qk-component-generator}/SKILL.md +1 -1
  10. package/skills/{qk-database-engineer → _archive_old_skills/qk-database-engineer}/SKILL.md +1 -1
  11. package/skills/{qk-design-system → _archive_old_skills/qk-design-system}/SKILL.md +1 -1
  12. package/skills/{qk-form-builder → _archive_old_skills/qk-form-builder}/SKILL.md +1 -1
  13. package/skills/{qk-frontend-architecture → _archive_old_skills/qk-frontend-architecture}/SKILL.md +1 -1
  14. package/skills/{qk-frontend-debug → _archive_old_skills/qk-frontend-debug}/SKILL.md +1 -1
  15. package/skills/{qk-frontend-performance → _archive_old_skills/qk-frontend-performance}/SKILL.md +1 -1
  16. package/skills/{qk-git-engineer → _archive_old_skills/qk-git-engineer}/SKILL.md +1 -1
  17. package/skills/_archive_old_skills/qk-help/SKILL.md +67 -0
  18. package/skills/{qk-state-management → _archive_old_skills/qk-state-management}/SKILL.md +1 -1
  19. package/skills/{qk-table-crud-generator → _archive_old_skills/qk-table-crud-generator}/SKILL.md +1 -1
  20. package/skills/qk-access-policy/SKILL.md +127 -0
  21. package/skills/qk-ai-builder/SKILL.md +33 -0
  22. package/skills/qk-api-lifecycle/SKILL.md +420 -0
  23. package/skills/qk-bug-resolution/SKILL.md +371 -0
  24. package/skills/qk-context-loader/SKILL.md +206 -0
  25. package/skills/qk-data-lifecycle/SKILL.md +135 -0
  26. package/skills/qk-design-to-code/SKILL.md +33 -0
  27. package/skills/qk-docs/SKILL.md +335 -0
  28. package/skills/qk-documentation-system/SKILL.md +33 -0
  29. package/skills/qk-engineering-standard/SKILL.md +171 -0
  30. package/skills/qk-engineering-standard/rules/backend.md +122 -0
  31. package/skills/qk-engineering-standard/rules/database.md +3 -0
  32. package/skills/qk-engineering-standard/rules/frontend.md +152 -0
  33. package/skills/qk-engineering-standard/rules/security.md +3 -0
  34. package/skills/qk-engineering-standard/rules/testing.md +3 -0
  35. package/skills/qk-feature-delivery/SKILL.md +432 -0
  36. package/skills/qk-help/SKILL.md +95 -67
  37. package/skills/qk-orchestrator/SKILL.md +272 -0
  38. package/skills/qk-policy-engine/SKILL.md +33 -0
  39. package/skills/qk-production-release/SKILL.md +127 -0
  40. package/skills/qk-project-bootstrap/SKILL.md +33 -0
  41. package/skills/qk-project-health/SKILL.md +650 -0
  42. package/skills/qk-project-memory/SKILL.md +33 -0
  43. package/skills/qk-system-evolution/SKILL.md +315 -0
  44. package/skills/qk-ui-audit/SKILL.md +152 -0
  45. package/skills/qk-ui-system-builder/SKILL.md +444 -0
  46. package/skills/qk-validation-gate/SKILL.md +33 -0
  47. /package/skills/{qk-api-integration → _archive_old_skills/qk-api-integration}/SKILL.md +0 -0
  48. /package/skills/{qk-auth-security → _archive_old_skills/qk-auth-security}/SKILL.md +0 -0
  49. /package/skills/{qk-backend-architecture → _archive_old_skills/qk-backend-architecture}/SKILL.md +0 -0
  50. /package/skills/{qk-context-manager → _archive_old_skills/qk-context-manager}/SKILL.md +0 -0
  51. /package/skills/{qk-deployment → _archive_old_skills/qk-deployment}/SKILL.md +0 -0
  52. /package/skills/{qk-frontend-testing → _archive_old_skills/qk-frontend-testing}/SKILL.md +0 -0
  53. /package/skills/{qk-migration → _archive_old_skills/qk-migration}/SKILL.md +0 -0
  54. /package/skills/{qk-project-audit → _archive_old_skills/qk-project-audit}/SKILL.md +0 -0
  55. /package/skills/{qk-refactor → _archive_old_skills/qk-refactor}/SKILL.md +0 -0
  56. /package/skills/{qk-ui-builder → _archive_old_skills/qk-ui-builder}/SKILL.md +0 -0
@@ -0,0 +1,67 @@
1
+ ---
2
+ name: qk-help
3
+ description: >-
4
+ Tra cứu danh sách toàn bộ kỹ năng (skills) hiện có và đọc các mẹo (pro-tips) kết hợp kỹ năng để tăng tốc độ code.
5
+ version: 1.0.0
6
+ category: engineering
7
+ tags: [help, list, tips, guide, manual]
8
+ platforms: [antigravity, claude-code, kilo-code, cursor, windsurf]
9
+ ---
10
+
11
+ # 📚 Cẩm nang AI Developer Skill OS
12
+
13
+ > **Nhiệm vụ của bạn (AI):** Khi người dùng gọi lệnh `./qk-help`, hãy xuất ra màn hình (bằng tiếng Việt) danh sách các kỹ năng phân theo nhóm và các Mẹo sử dụng (Pro-tips) dưới đây một cách sinh động, dễ đọc (dùng markdown, in đậm, emoji). Không cần phân tích code, chỉ đóng vai trò là "Sách hướng dẫn sử dụng".
14
+
15
+ ---
16
+
17
+ ## 🎯 1. Danh sách Kỹ năng (Skills Directory)
18
+
19
+ Dưới đây là các kỹ năng chính bạn có thể gọi bằng cách gõ `./qk-[tên-kỹ-năng]`:
20
+
21
+ ### 🎨 Frontend (Giao diện)
22
+ - **`qk-ui-builder`**: Xây dựng UI, Layout, Component, Modal phức tạp.
23
+ - **`qk-table-crud-generator`**: Chuyên vẽ bảng danh sách (Table), phân trang, lọc và form Thêm/Sửa/Xóa.
24
+ - **`qk-form-builder`**: Chuyên làm Form nhập liệu, validate (Zod/Yup).
25
+ - **`qk-component-generator`**: Tạo Component độc lập, tái sử dụng (Button, Input, Card).
26
+ - **`qk-state-management`**: Xử lý Redux, Zustand, React Query.
27
+ - **`qk-frontend-debug`**: Bắt bệnh vỡ layout, infinite re-render, lỗi Hydration.
28
+ - **`qk-frontend-performance`**: Tối ưu tốc độ, chống re-render thừa.
29
+ - **`qk-frontend-architecture`**: Tư vấn kiến trúc thư mục Frontend.
30
+ - **`qk-frontend-testing`**: Viết Unit Test / E2E Test cho Frontend.
31
+ - **`qk-accessibility-audit`**: Sửa lỗi a11y, hỗ trợ Screen reader.
32
+
33
+ ### ⚙️ Engineering & Integration (Tích hợp)
34
+ - **`qk-api-integration`**: [Cực mạnh] Bóc tách tài liệu API (Curl, Postman) -> Gen Type, Service, Hook -> (Tùy chọn) Ốp thẳng vào UI.
35
+ - **`qk-refactor`**: Tối ưu, dọn dẹp mã nguồn sạch sẽ.
36
+ - **`qk-bug-fix`**: Chẩn đoán lỗi sâu và sửa an toàn.
37
+ - **`qk-project-audit`**: Quét toàn bộ dự án tìm nợ kỹ thuật.
38
+ - **`qk-git-engineer`**: Viết Commit / PR chuẩn Conventional.
39
+ - **`qk-migration`**: Nâng cấp version framework / thư viện.
40
+ - **`qk-agent-orchestrator`**: Kiến trúc sư, lên plan phân rã task lớn.
41
+ - **`qk-context-manager`**: Tóm tắt kiến trúc dự án.
42
+
43
+ ### 🗄️ Backend (Máy chủ)
44
+ - **`qk-database-engineer`**: Thiết kế Schema, ORM (Prisma/Drizzle), Migration.
45
+ - **`qk-backend-architecture`**: Setup kiến trúc Backend (Node/Nest/Python).
46
+ - **`qk-auth-security`**: Phân quyền RBAC, JWT, OAuth.
47
+ - **`qk-deployment`**: Viết Dockerfile, CI/CD Pipeline.
48
+
49
+ ---
50
+
51
+ ## 💡 2. Mẹo sử dụng Nâng cao (Pro-Tips)
52
+
53
+ ### Mẹo 1: Kết hợp Kỹ năng (Skill Chaining) 🔗
54
+ Đừng bắt AI làm từ A-Z bằng 1 câu prompt. Hãy gọi liên hoàn:
55
+ > *"Hãy dùng `./qk-api-integration` để bóc tách API này thành hook React Query. Sau đó dùng `./qk-table-crud-generator` vẽ cái Bảng hiển thị danh sách tích hợp hook đó."*
56
+
57
+ ### Mẹo 2: Chế độ "Một phát ăn ngay" (End-to-End) 🚀
58
+ Nếu bạn đã có sẵn 1 màn hình UI (chỉ thiếu data), hãy ép `qk-api-integration` làm End-to-End:
59
+ > *"./qk-api-integration Dưới đây là API Get Profile. Hãy khai báo Type, viết Hook và TÍCH HỢP THẲNG LUÔN vào file \`Profile.tsx\` đang mở."*
60
+
61
+ ### Mẹo 3: Truyền tham số ép buộc (Arguments) 🎯
62
+ Bạn có thể ép AI dùng công nghệ bạn muốn bằng cách thêm \`--tham_số\`:
63
+ > *"./qk-ui-builder --fw=react --css=tailwind Hãy vẽ màn hình Đăng nhập."*
64
+
65
+ ### Mẹo 4: Nhờ "Kiến trúc sư" phân việc 🧠
66
+ Nếu bạn có một tính năng quá lớn (ví dụ: Làm tính năng Giỏ Hàng), đừng tự chia việc, hãy gọi:
67
+ > *"./qk-agent-orchestrator Tôi muốn làm tính năng Giỏ hàng. Hãy phân tích và lên kế hoạch gọi các skill \`qk-\` nào cho phù hợp."*
@@ -1,5 +1,5 @@
1
1
  ---
2
- name: qk-state-management
2
+ name: qk-state-management
3
3
  description: >-
4
4
  Xác định và triển khai chiến lược quản lý state phù hợp (Zustand, Redux, React Query, Local State).
5
5
  version: 1.0.0
@@ -1,5 +1,5 @@
1
1
  ---
2
- name: qk-table-crud-generator
2
+ name: qk-table-crud-generator
3
3
  description: >-
4
4
  Tạo các bảng dữ liệu admin với đầy đủ tính năng phân trang, sắp xếp, lọc và thao tác thêm/sửa/xóa (CRUD).
5
5
  version: 1.0.0
@@ -0,0 +1,127 @@
1
+ ---
2
+ name: qk-access-policy
3
+ purpose: Quản lý chính sách bảo mật, phân quyền RBAC và ranh giới truy cập.
4
+ mode_supported: [enterprise]
5
+ input: [Access rules]
6
+ output: [Access policies]
7
+ workflow: [1. Rà soát Roles -> 2. Kiểm tra Permissions -> 3. Cập nhật rule]
8
+ allowed_tools: [read_file, write_to_file]
9
+ handoff_to: [qk-engineering-standard]
10
+ ---
11
+
12
+ # 🛠️ qk-access-policy - Quy Trình Vận Hành Chuẩn (SOP)
13
+
14
+ > **Mô tả:** Quản lý chính sách bảo mật, phân quyền RBAC và ranh giới truy cập.
15
+
16
+ ## 🎯 1. Mục Tiêu (Goal)
17
+ - Hoàn thành thành công tác vụ được giao liên quan đến nhiệm vụ của skill.
18
+ - Đảm bảo chất lượng mã nguồn và tính nhất quán của hệ thống.
19
+
20
+ ## 🔄 2. Chuỗi Hành Động (Chain of Thought / SOP)
21
+ *(Bắt buộc AI phải suy nghĩ và làm theo đúng thứ tự)*
22
+ 1. **Phân tích (Analyze):** Thu thập ngữ cảnh và hiểu rõ yêu cầu đầu vào.
23
+ 2. **Lên kế hoạch (Plan):** Xác định các bước cần thay đổi/tạo mới dựa trên bộ luật (rules).
24
+ 3. **Thực thi (Execute):** Tiến hành sửa đổi mã nguồn hoặc tạo tài liệu.
25
+ 4. **Xác thực (Verify):** Đảm bảo đầu ra đáp ứng đúng yêu cầu và không vi phạm quy định.
26
+
27
+ ## 🛡️ 3. Ràng Buộc & Quy Tắc (Constraints)
28
+ - CẤM bỏ qua việc kiểm tra `qk-engineering-standard` trước khi viết code.
29
+ - Mọi quyết định kỹ thuật phải dựa trên nội dung tại phần Deep Knowledge (nếu có).
30
+
31
+ ## 🤝 4. Giao Thức Bàn Giao (Handoff Protocol)
32
+ - Đích đến: `qk-engineering-standard`
33
+ - Nội dung bàn giao: Chuyển toàn bộ ngữ cảnh và kết quả đã thực thi cho bước tiếp theo.
34
+
35
+ ## 📚 5. Kiến Thức Chuyên Sâu (Deep Knowledge)
36
+
37
+ *(Nền tảng kiến thức và quy tắc chi tiết kế thừa từ kỹ sư)*
38
+
39
+ ---
40
+
41
+
42
+
43
+ # Auth & Security Engineer
44
+
45
+ > **Language rule:**
46
+ > Use English for: code, identifiers, file names, architecture terms, technical decisions.
47
+ > Use the user's language for: explanations, questions, summaries, and feedback.
48
+ > The user may write in any language — detect and match it automatically.
49
+
50
+ ---
51
+
52
+ ## Trigger
53
+
54
+ Activate this skill when:
55
+ - User asks to "add login", "protect this route", or "implement OAuth"
56
+ - Defining user roles and permissions (Admin vs User)
57
+ - Project audit flags security vulnerabilities (P0/P1)
58
+ - Handling sensitive data (passwords, PII, API keys)
59
+
60
+ ---
61
+
62
+ ## Scope
63
+
64
+ - ✅ **Authentication:** JWT, Session Cookies, OAuth2 (Google, GitHub, etc.), Magic Links.
65
+ - ✅ **Authorization:** Role-Based Access Control (RBAC), Middleware guards.
66
+ - ✅ **Data Protection:** Hashing passwords (bcrypt, Argon2), encrypting sensitive fields.
67
+ - ✅ **Vulnerability Prevention:** CSRF protection, Rate Limiting, CORS config, input sanitization (SQLi/XSS).
68
+
69
+ ---
70
+
71
+ ## Non-goals
72
+
73
+ - ❌ Do NOT store passwords in plain text. Ever.
74
+ - ❌ Do NOT hardcode secrets or private keys in the code (use `.env`).
75
+ - ❌ Do NOT store JWTs in `localStorage` if cookies (`httpOnly`) are an option, unless explicitly requested.
76
+
77
+ ---
78
+
79
+ ## Workflow
80
+
81
+ ### Phase 1 — Strategy Selection
82
+
83
+ Determine the auth mechanism:
84
+ 1. **Stateless (JWT):** Good for mobile/SPAs, distributed systems.
85
+ 2. **Stateful (Sessions):** Good for traditional web apps, easier revocation.
86
+ 3. **Third-party (OAuth / Auth0 / NextAuth / Supabase):** Offload auth complexity.
87
+
88
+ ### Phase 2 — Implementation
89
+
90
+ **For JWT + Cookies (Recommended Web Pattern):**
91
+ 1. Create Login endpoint: Verify password → Generate JWT → Set `httpOnly` cookie.
92
+ 2. Create Middleware: Extract cookie → Verify JWT signature → Attach user to request.
93
+ 3. Create Logout endpoint: Clear the cookie.
94
+
95
+ **For Authorization:**
96
+ 1. Define roles (e.g., `enum Role { ADMIN, USER }`).
97
+ 2. Create Role Middleware: Check `req.user.role`.
98
+
99
+ ### Phase 3 — Security Audit
100
+
101
+ Verify:
102
+ - Passwords are hashed with a salt (e.g., `bcrypt.hash(password, 10)`).
103
+ - Cookies are `httpOnly`, `Secure` (in prod), and `SameSite`.
104
+ - CORS is configured to only allow trusted origins.
105
+
106
+ ---
107
+
108
+ ## Output Format
109
+
110
+ ```
111
+ 🛡️ Auth & Security Report
112
+ ─────────────────────────────────────────────────
113
+ Mechanism: [JWT in httpOnly Cookie / OAuth / Session]
114
+ Roles: [Admin, User]
115
+
116
+ Components Implemented:
117
+ ✅ Login/Logout handlers
118
+ ✅ Auth Middleware (Guard)
119
+ ✅ Password hashing (bcrypt)
120
+
121
+ Security measures enforced:
122
+ • `httpOnly`, `Secure`, `SameSite=Strict` on cookies
123
+ • CORS restricted to frontend origin
124
+
125
+ 🔗 Next Steps:
126
+ Remember to add `JWT_SECRET` to your production environment variables.
127
+ ```
@@ -0,0 +1,33 @@
1
+ ---
2
+ name: qk-ai-builder
3
+ purpose: Thiết kế hệ thống AI App (RAG, Agent, Prompt, Logic AI).
4
+ mode_supported: [enterprise]
5
+ input: [AI Requirement]
6
+ output: [AI Architecture, Agents]
7
+ workflow: [1. Architecture -> 2. Agent -> 3. Memory -> 4. Evaluation -> 5. Monitoring]
8
+ allowed_tools: [write_to_file]
9
+ handoff_to: [qk-validation-gate]
10
+ ---
11
+
12
+ # 🛠️ qk-ai-builder - Quy Trình Vận Hành Chuẩn (SOP)
13
+
14
+ > **Mô tả:** Thiết kế hệ thống AI App (RAG, Agent, Prompt, Logic AI).
15
+
16
+ ## 🎯 1. Mục Tiêu (Goal)
17
+ - Hoàn thành thành công tác vụ được giao liên quan đến nhiệm vụ của skill.
18
+ - Đảm bảo chất lượng mã nguồn và tính nhất quán của hệ thống.
19
+
20
+ ## 🔄 2. Chuỗi Hành Động (Chain of Thought / SOP)
21
+ *(Bắt buộc AI phải suy nghĩ và làm theo đúng thứ tự)*
22
+ 1. **Phân tích (Analyze):** Thu thập ngữ cảnh và hiểu rõ yêu cầu đầu vào.
23
+ 2. **Lên kế hoạch (Plan):** Xác định các bước cần thay đổi/tạo mới dựa trên bộ luật (rules).
24
+ 3. **Thực thi (Execute):** Tiến hành sửa đổi mã nguồn hoặc tạo tài liệu.
25
+ 4. **Xác thực (Verify):** Đảm bảo đầu ra đáp ứng đúng yêu cầu và không vi phạm quy định.
26
+
27
+ ## 🛡️ 3. Ràng Buộc & Quy Tắc (Constraints)
28
+ - CẤM bỏ qua việc kiểm tra `qk-engineering-standard` trước khi viết code.
29
+ - Mọi quyết định kỹ thuật phải dựa trên nội dung tại phần Deep Knowledge (nếu có).
30
+
31
+ ## 🤝 4. Giao Thức Bàn Giao (Handoff Protocol)
32
+ - Đích đến: `qk-validation-gate`
33
+ - Nội dung bàn giao: Chuyển toàn bộ ngữ cảnh và kết quả đã thực thi cho bước tiếp theo.
@@ -0,0 +1,420 @@
1
+ ---
2
+ name: qk-api-lifecycle
3
+ purpose: Thiết kế Spec, Code Service, Types, Test, Docs cho API.
4
+ mode_supported: [standard]
5
+ input: [API requirement]
6
+ output: [API Service, Routes, Docs]
7
+ workflow: [1. Spec -> 2. Type -> 3. Service -> 4. Test -> 5. Docs]
8
+ allowed_tools: [write_to_file, run_command]
9
+ handoff_to: [qk-validation-gate]
10
+ ---
11
+
12
+ # 🛠️ qk-api-lifecycle - Quy Trình Vận Hành Chuẩn (SOP)
13
+
14
+ > **Mô tả:** Thiết kế Spec, Code Service, Types, Test, Docs cho API.
15
+
16
+ ## 🎯 1. Mục Tiêu (Goal)
17
+ - Hoàn thành thành công tác vụ được giao liên quan đến nhiệm vụ của skill.
18
+ - Đảm bảo chất lượng mã nguồn và tính nhất quán của hệ thống.
19
+
20
+ ## 🔄 2. Chuỗi Hành Động (Chain of Thought / SOP)
21
+ *(Bắt buộc AI phải suy nghĩ và làm theo đúng thứ tự)*
22
+ 1. **Phân tích (Analyze):** Thu thập ngữ cảnh và hiểu rõ yêu cầu đầu vào.
23
+ 2. **Lên kế hoạch (Plan):** Xác định các bước cần thay đổi/tạo mới dựa trên bộ luật (rules).
24
+ 3. **Thực thi (Execute):** Tiến hành sửa đổi mã nguồn hoặc tạo tài liệu.
25
+ 4. **Xác thực (Verify):** Đảm bảo đầu ra đáp ứng đúng yêu cầu và không vi phạm quy định.
26
+
27
+ ## 🛡️ 3. Ràng Buộc & Quy Tắc (Constraints)
28
+ - CẤM bỏ qua việc kiểm tra `qk-engineering-standard` trước khi viết code.
29
+ - Mọi quyết định kỹ thuật phải dựa trên nội dung tại phần Deep Knowledge (nếu có).
30
+
31
+ ## 🤝 4. Giao Thức Bàn Giao (Handoff Protocol)
32
+ - Đích đến: `qk-validation-gate`
33
+ - Nội dung bàn giao: Chuyển toàn bộ ngữ cảnh và kết quả đã thực thi cho bước tiếp theo.
34
+
35
+ ## 📚 5. Kiến Thức Chuyên Sâu (Deep Knowledge)
36
+
37
+ *(Nền tảng kiến thức và quy tắc chi tiết kế thừa từ kỹ sư)*
38
+
39
+ ---
40
+
41
+
42
+
43
+ # API Integration Engineer
44
+
45
+ > **Language rule:**
46
+ > Use English for: code, identifiers, file names, architecture terms, technical decisions.
47
+ > Use the user's language for: explanations, questions, summaries, and feedback.
48
+ > The user may write in any language — detect and match it automatically.
49
+
50
+ ---
51
+
52
+ ## Trigger
53
+
54
+ Activate this skill when the user provides any of:
55
+ - `curl` command
56
+ - Swagger 2.0 / OpenAPI 3.0 (YAML or JSON)
57
+ - Postman collection or HAR file
58
+ - API documentation (endpoint, method, request/response)
59
+ - Code snippet to reverse-engineer (fetch/axios/custom client)
60
+ - Backend controller or route handler to mirror on the frontend
61
+
62
+ ---
63
+
64
+ ## Scope
65
+
66
+ - ✅ Parse and understand any API input format
67
+ - ✅ Extract the full API contract (request + response + errors)
68
+ - ✅ Detect existing project patterns (HTTP client, state layer, conventions)
69
+ - ✅ Generate typed service/client, hooks/queries, and TypeScript types
70
+ - ✅ Follow and extend existing architecture — never duplicate it
71
+ - ✅ Handle special cases: file upload, file download, pagination, auth, WebSocket
72
+
73
+ ---
74
+
75
+ ## Non-goals
76
+
77
+ - ❌ Do NOT create a new HTTP client if one already exists
78
+ - ❌ Do NOT introduce a new state system if one is already in use
79
+ - ❌ Do NOT hardcode URLs, tokens, or secrets
80
+ - ❌ Do NOT use `any` when types can be inferred
81
+ - ❌ Do NOT overwrite existing files without explicit user approval
82
+
83
+ ---
84
+
85
+ ## Severity Levels
86
+
87
+ | Level | Meaning |
88
+ |-------|---------|
89
+ | P0 | Conflict with existing endpoint or type — must resolve before generating |
90
+ | P1 | Missing critical info (auth, response schema) — ask before proceeding |
91
+ | P2 | Naming or structure inconsistency — warn and apply best guess |
92
+ | P3 | Missing optional fields — document assumption and proceed |
93
+
94
+ ---
95
+
96
+ ## Workflow
97
+
98
+ ### Phase 1 — Input Validation
99
+
100
+ Before parsing, verify:
101
+ - URL is valid and method is correct (GET/POST/PUT/PATCH/DELETE)
102
+ - Auth format is identifiable (Bearer, API Key, OAuth2, Basic, Cookie)
103
+ - Request info is present (path params, query params, body)
104
+ - Response structure is clear (JSON, binary, stream, paginated)
105
+ - Error cases are documented
106
+
107
+ If critical info is missing → **stop and ask**. Do not guess.
108
+
109
+ ```json
110
+ {
111
+ "validation": {
112
+ "status": "VALID | INVALID | INCOMPLETE",
113
+ "confidence": 0.95,
114
+ "errors": [],
115
+ "warnings": [],
116
+ "input_type": "curl | openapi | postman | docs | code"
117
+ }
118
+ }
119
+ ```
120
+
121
+ ---
122
+
123
+ ### Phase 2 — API Contract Extraction
124
+
125
+ Extract the full contract:
126
+
127
+ ```
128
+ metadata:
129
+ name, domain, endpoint, method, version, description
130
+
131
+ request:
132
+ pathParams: { name, type, required }
133
+ queryParams: { name, type, required, default }
134
+ headers: { name, value, required }
135
+ body: { contentType, schema { field, type, required, nullable } }
136
+ auth: { type, location, name }
137
+
138
+ response:
139
+ success: { statusCode, contentType, schema, pagination? }
140
+ errors: [ { statusCode, message, businessCode? } ]
141
+
142
+ special:
143
+ rateLimit, timeout, retryable, streaming
144
+ ```
145
+
146
+ Map each field: `type`, `required`, `nullable`, `enum`, `example`.
147
+
148
+ ---
149
+
150
+ ### Phase 3 — Project Profile Detection
151
+
152
+ 1. Check for `.api-config.json` at project root → use if present
153
+ 2. Otherwise infer from:
154
+ - Framework: `package.json`, config files, imports
155
+ - HTTP client: existing axios instance, fetch wrapper, custom client
156
+ - State management: React Query, Redux, Zustand, Pinia, Apollo, Vuex
157
+ - Type system: `tsconfig.json`, JSDoc, plain JS
158
+ - Folder conventions: `services/`, `hooks/`, `api/`, `types/`, `adapters/`
159
+ - Naming: camelCase, PascalCase, snake_case, file patterns
160
+ 3. Read 1-2 existing API files to capture exact patterns for imports, typing, error handling, naming
161
+
162
+ If project context is ambiguous → use conservative defaults and document all assumptions.
163
+
164
+ ---
165
+
166
+ ### Phase 4 — Conflict Detection
167
+
168
+ Before generating code, check for:
169
+
170
+ | Conflict | Action |
171
+ |----------|--------|
172
+ | `ENDPOINT_DUPLICATE` — endpoint already exists | Reuse if same, warn if different |
173
+ | `FUNCTION_DUPLICATE` — function name conflicts | Warn, propose new name |
174
+ | `TYPE_DUPLICATE` — type already defined | Extend or reuse existing |
175
+ | `LOGIC_OVERLAP` — logic exists in another service | Consolidate, don't duplicate |
176
+ | `IMPORT_CONFLICT` — import path conflicts | Resolve before generating |
177
+
178
+ **P0 conflict → stop, report, wait for user decision before proceeding.**
179
+
180
+ ---
181
+
182
+ ### Phase 5 — Code Generation
183
+
184
+ Generate the minimum necessary set for the task:
185
+
186
+ #### TypeScript Types
187
+ ```typescript
188
+ // Request types
189
+ export interface CreateUserRequest {
190
+ name: string;
191
+ email: string;
192
+ role?: UserRole;
193
+ }
194
+
195
+ // Response types
196
+ export interface CreateUserResponse {
197
+ id: string;
198
+ name: string;
199
+ email: string;
200
+ createdAt: string;
201
+ }
202
+
203
+ // Error types
204
+ export interface ApiError {
205
+ code: string;
206
+ message: string;
207
+ details?: Record<string, unknown>;
208
+ }
209
+ ```
210
+
211
+ #### Service / API Layer
212
+ ```typescript
213
+ // Thin layer: HTTP + mapping only. No UI, no business logic.
214
+ export const createUser = async (
215
+ data: CreateUserRequest
216
+ ): Promise<CreateUserResponse> => {
217
+ const response = await apiClient.post<CreateUserResponse>('/users', data);
218
+ return response.data;
219
+ };
220
+ ```
221
+
222
+ #### Hook / Query (if project uses React Query)
223
+ ```typescript
224
+ export const useCreateUser = () => {
225
+ return useMutation<CreateUserResponse, ApiError, CreateUserRequest>({
226
+ mutationFn: createUser,
227
+ onSuccess: () => {
228
+ queryClient.invalidateQueries({ queryKey: ['users'] });
229
+ },
230
+ });
231
+ };
232
+ ```
233
+
234
+ **If project uses Redux** → follow existing slice/thunk pattern.
235
+ **If project uses Zustand** → follow existing store pattern.
236
+ **If project uses Pinia/Vuex** → follow existing composable/action pattern.
237
+
238
+ Do NOT mix patterns.
239
+
240
+ ---
241
+
242
+ ### Phase 6 — Special Case Handling
243
+
244
+ #### File Upload (`multipart/form-data`)
245
+ ```typescript
246
+ // Always use FormData — never send File object in JSON
247
+ const formData = new FormData();
248
+ formData.append('file', file);
249
+ formData.append('name', name);
250
+ await apiClient.post('/upload', formData, {
251
+ headers: { 'Content-Type': 'multipart/form-data' },
252
+ });
253
+ ```
254
+
255
+ #### File Download (binary response)
256
+ ```typescript
257
+ const response = await apiClient.get('/export', { responseType: 'blob' });
258
+ const url = URL.createObjectURL(response.data);
259
+ const a = document.createElement('a');
260
+ a.href = url;
261
+ a.download = filename;
262
+ a.click();
263
+ URL.revokeObjectURL(url);
264
+ ```
265
+
266
+ #### Pagination
267
+ ```typescript
268
+ interface PaginatedResponse<T> {
269
+ items: T[];
270
+ total: number;
271
+ page: number;
272
+ limit: number;
273
+ }
274
+ // Implement consistently with existing project pagination pattern
275
+ ```
276
+
277
+ #### Authentication
278
+ - Follow existing auth mechanism (interceptor, header injection, cookie)
279
+ - Never hardcode tokens or credentials
280
+ - Refresh token logic belongs in the existing interceptor
281
+
282
+ ---
283
+
284
+ ### Phase 7 — Quality Validation
285
+
286
+ Before marking as ready:
287
+
288
+ - [ ] TypeScript strict — compiles clean, no `any` without justification
289
+ - [ ] All functions/params have explicit types and return types
290
+ - [ ] No unused imports, no debug code
291
+ - [ ] Error handling complete (try/catch, `.catch`, fallback)
292
+ - [ ] No hardcoded URLs, tokens, or secrets — use env vars
293
+ - [ ] Naming matches project conventions
294
+ - [ ] Reuses existing HTTP client, interceptors, and query client
295
+ - [ ] JSDoc added for public API if project convention requires it
296
+ - [ ] React: dependency arrays correct, cleanup present, no race conditions
297
+
298
+ ---
299
+
300
+ ### Phase 8 — End-to-End UI Integration (Optional / On-Demand)
301
+
302
+ If the user explicitly requests to integrate the API directly into the UI (End-to-End):
303
+ 1. **Find Target Component:** Identify the UI component where the API should be called.
304
+ 2. **Wire State:** Inject the generated Hook/Query/Service into the component.
305
+ 3. **Handle States:** Implement Loading (spinners, skeletons), Error (toast, alert), and Success (redirect, form reset, table refetch) states in the UI.
306
+ 4. **Data Binding:** Bind the API response data to the UI elements (Table rows, Dropdowns, etc.) and bind UI inputs to the API request payload.
307
+
308
+ ---
309
+
310
+ ## Decision Tree
311
+
312
+ ```
313
+ Is required info complete?
314
+ ├── No → Ask for missing info (auth, response schema, base URL)
315
+ └── Yes → Check for conflicts
316
+ ├── P0 conflict → Stop, report, wait for user decision
317
+ └── No P0 → Generate code following project patterns
318
+ ```
319
+
320
+ ```
321
+ Does project have existing HTTP client?
322
+ ├── Yes → Extend it
323
+ └── No → Create minimal axios/fetch wrapper following project style
324
+ ```
325
+
326
+ ```
327
+ Does project use state management?
328
+ ├── React Query → useMutation / useQuery pattern
329
+ ├── Redux → slice + thunk / RTK Query
330
+ ├── Zustand → store action
331
+ ├── Pinia → action in store
332
+ └── None → Service function only
333
+ ```
334
+
335
+ ---
336
+
337
+ ## Output Format
338
+
339
+ ```
340
+ 📋 API Contract
341
+ ─────────────────────────────────────────────────
342
+ Name: [API name]
343
+ Endpoint: [METHOD /path]
344
+ Auth: [type]
345
+ Input: [brief description]
346
+ Output: [brief description]
347
+
348
+ 🔍 Project Pattern Detected
349
+ ─────────────────────────────────────────────────
350
+ HTTP client: [axios instance at src/lib/axios.ts]
351
+ State: [React Query]
352
+ Types path: [src/types/]
353
+ Service path: [src/services/]
354
+ Hook path: [src/hooks/]
355
+
356
+ ⚠️ Assumptions
357
+ ─────────────────────────────────────────────────
358
+ • [Assumption 1]
359
+ • [Assumption 2]
360
+
361
+ 📁 Files Generated
362
+ ─────────────────────────────────────────────────
363
+ [NEW] src/types/user.types.ts
364
+ [NEW] src/services/user.service.ts
365
+ [NEW] src/hooks/useCreateUser.ts
366
+ [EXTEND] src/services/index.ts
367
+
368
+ 🔗 Next steps:
369
+ → Import hook in your component
370
+ → Add env var: VITE_API_BASE_URL
371
+ → Test with: [example usage snippet]
372
+ ```
373
+
374
+ ---
375
+
376
+ ## Validation Checklist
377
+
378
+ - [ ] All 7 phases completed
379
+ - [ ] Input validated — no missing critical fields
380
+ - [ ] Conflicts checked — none unresolved
381
+ - [ ] Types generated and strict
382
+ - [ ] Existing HTTP client reused
383
+ - [ ] Existing state pattern followed
384
+ - [ ] Special cases handled if applicable (upload, download, pagination, auth)
385
+ - [ ] No hardcoded secrets
386
+ - [ ] Output format produced with files listed
387
+
388
+ ---
389
+
390
+ ## Project Config Reference (`.api-config.json`)
391
+
392
+ ```json
393
+ {
394
+ "framework": "React",
395
+ "httpClient": "axios",
396
+ "stateManagement": "react-query",
397
+ "typing": "typescript",
398
+ "conventions": {
399
+ "servicePath": "src/services/",
400
+ "typePath": "src/types/",
401
+ "hookPath": "src/hooks/",
402
+ "naming": "camelCase",
403
+ "fileNaming": "{name}.service.ts",
404
+ "typeFileNaming": "{Name}.types.ts",
405
+ "hookFileNaming": "use{Name}.ts"
406
+ },
407
+ "httpConfig": {
408
+ "baseURL": "process.env.VITE_API_URL",
409
+ "interceptor": "src/lib/axios.ts",
410
+ "authHeader": "Authorization",
411
+ "timeout": 30000
412
+ }
413
+ }
414
+ ```
415
+
416
+ ---
417
+
418
+ ## Examples
419
+
420
+ See `examples/` folder.