agent-workflow-kit-cli 1.3.2 → 1.3.4

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 (51) hide show
  1. package/dist/cli/commands/add.js +3 -1
  2. package/dist/cli/commands/doctor.js +145 -47
  3. package/dist/cli/commands/init.js +6 -0
  4. package/dist/core/analyzer.js +70 -0
  5. package/dist/core/detector.js +22 -0
  6. package/package.json +1 -1
  7. package/templates/common/AGENTS.md.hbs +4 -0
  8. package/templates/common/GLOBAL_RULES.md +101 -0
  9. package/templates/devops/AGENTS.md.hbs +32 -0
  10. package/templates/devops/skills/devops/SKILL.md +477 -0
  11. package/templates/diagram/AGENTS.md.hbs +30 -0
  12. package/templates/diagram/skills/drawio-diagram/SKILL.md +427 -0
  13. package/templates/dotnet/AGENTS.md.hbs +38 -34
  14. package/templates/dotnet/rules/api-structure.md +15 -15
  15. package/templates/dotnet/rules/csharp-style.md +17 -17
  16. package/templates/dotnet/rules/dependency-injection.md +12 -12
  17. package/templates/dotnet/rules/error-handling-validation.md +15 -15
  18. package/templates/dotnet/skills/dotnet-controller/SKILL.md +16 -16
  19. package/templates/express/AGENTS.md.hbs +37 -33
  20. package/templates/express/rules/error-handling.md +18 -18
  21. package/templates/express/rules/express-style.md +19 -19
  22. package/templates/express/rules/router-controller.md +16 -16
  23. package/templates/express/skills/express-endpoint/SKILL.md +14 -14
  24. package/templates/fastapi/AGENTS.md.hbs +25 -3
  25. package/templates/fastapi/rules/api-testing.md +24 -0
  26. package/templates/fastapi/rules/database-async.md +26 -0
  27. package/templates/golang/AGENTS.md.hbs +42 -0
  28. package/templates/golang/rules/concurrency.md +71 -0
  29. package/templates/golang/rules/error-handling.md +42 -0
  30. package/templates/golang/rules/golang-style.md +24 -0
  31. package/templates/golang/rules/project-layout.md +39 -0
  32. package/templates/golang/skills/golang-db/SKILL.md +27 -0
  33. package/templates/golang/skills/golang-feature/SKILL.md +42 -0
  34. package/templates/nestjs/AGENTS.md.hbs +33 -29
  35. package/templates/nestjs/rules/module-architecture.md +14 -14
  36. package/templates/nestjs/rules/nestjs-style.md +12 -12
  37. package/templates/nestjs/rules/validation-errors.md +15 -15
  38. package/templates/nestjs/skills/nestjs-module/SKILL.md +15 -15
  39. package/templates/next-js/AGENTS.md.hbs +39 -35
  40. package/templates/next-js/rules/data-fetching-mutations.md +17 -17
  41. package/templates/next-js/rules/next-style.md +17 -17
  42. package/templates/next-js/rules/seo-metadata.md +18 -18
  43. package/templates/next-js/rules/server-client-components.md +17 -17
  44. package/templates/next-js/skills/next-feature/SKILL.md +16 -16
  45. package/templates/rust/AGENTS.md.hbs +41 -0
  46. package/templates/rust/rules/error-handling.md +36 -0
  47. package/templates/rust/rules/memory-concurrency.md +47 -0
  48. package/templates/rust/rules/project-layout.md +49 -0
  49. package/templates/rust/rules/rust-style.md +26 -0
  50. package/templates/rust/skills/rust-db/SKILL.md +27 -0
  51. package/templates/rust/skills/rust-feature/SKILL.md +34 -0
@@ -1,39 +1,39 @@
1
- # Xác Thực Dữ Liệu & Quản Lỗi Tập Trung
1
+ # Data Validation & Unified Exception Handling
2
2
 
3
- Tài liệu này quy định việc sử dụng Class Validator, thiết lập ValidationPipe toàn cục xử lỗi tập trung qua Exceptions Filters trong NestJS.
3
+ This document specifies conventions for using Class Validator, configuring the global ValidationPipe, and handling errors centrally via Exception Filters in NestJS.
4
4
 
5
5
  ---
6
6
 
7
- ## 🛡️ Kiểm Thử Dữ Liệu Đầu Vào (Validation & Transformation)
8
- - **Định hình DTO nghiêm ngặt:** Toàn bộ dữ liệu đầu vào của HTTP Request (`@Body()`, `@Query()`, `@Param()`) phải được đặc tả qua các lớp DTO sử dụng decorator từ `class-validator` (như `@IsString()`, `@IsEmail()`, `@IsInt()`).
9
- - **Kích hoạt ống lọc toàn cục (Global Validation Pipe):** Khai báo tại file `main.ts` để tự động lọc bỏ các thuộc tính không nằm trong danh sách trắng (whitelist) tự động ép kiểu dữ liệu (transform).
7
+ ## 🛡️ Input Validation & Transformation
8
+ - **Strict DTO Mapping:** All incoming HTTP request data (`@Body()`, `@Query()`, `@Param()`) must be mapped using DTO classes decorated with rules from `class-validator` (such as `@IsString()`, `@IsEmail()`, `@IsInt()`).
9
+ - **Global Validation Pipe:** Configure the global `ValidationPipe` inside `main.ts` to automatically strip properties not declared in the DTO (whitelist) and transform inputs into their corresponding types.
10
10
 
11
11
  ```typescript
12
- // Trong file main.ts
12
+ // Inside main.ts
13
13
  app.useGlobalPipes(
14
14
  new ValidationPipe({
15
- whitelist: true, // Tự động loại bỏ các thuộc tính không khai báo trong DTO
16
- forbidNonWhitelisted: true, // Ném lỗi 400 nếu client gửi thuộc tính thừa
17
- transform: true, // Tự động chuyển đổi kiểu dữ liệu (string sang number, object sang DTO class)
15
+ whitelist: true, // Auto-strips properties not declared in DTO
16
+ forbidNonWhitelisted: true, // Throws HTTP 400 if client sends extra fields
17
+ transform: true, // Auto-casts types (e.g. string to number, object to class instance)
18
18
  }),
19
19
  );
20
20
  ```
21
21
 
22
22
  ---
23
23
 
24
- ## 🚨 Quản Lý Ngoại Lệ Toàn Cục (Unified Exception Handling)
25
- - **Cấm trả về lỗi hệ thống thô:** Tuyệt đối không để lộ lỗi thô (chẳng hạn như lỗi từ DB, lỗi kết nối dịch vụ) ra ngoài client với mã lỗi 500.
26
- - **Sử dụng HttpExceptions tích hợp:** Bắt buộc phải bắt lỗi (try/catch) tầng Service ánh xạ sang các Http Exception tường minh của NestJS (`NotFoundException`, `BadRequestException`, `ForbiddenException`, v.v.).
24
+ ## 🚨 Unified Exception Handling
25
+ - **No Raw System Errors:** Never expose raw database or execution exceptions directly to clients with HTTP 500 errors.
26
+ - **Built-in HttpExceptions:** Implement try/catch blocks within Services and map failures to explicit NestJS HttpExceptions (e.g., `NotFoundException`, `BadRequestException`, `ForbiddenException`).
27
27
 
28
28
  ```typescript
29
29
  try {
30
30
  return await this.courseRepo.findOneOrFail(id);
31
31
  } catch (error) {
32
- throw new NotFoundException("Khóa học không tồn tại trên hệ thống.");
32
+ throw new NotFoundException("The requested course does not exist.");
33
33
  }
34
34
  ```
35
35
 
36
- - **Tập trung hóa bằng Exception Filter:** Xây dựng một Filter toàn cục để cấu trúc lại định dạng JSON trả về cho Client một cách đồng nhất. Phản hồi lỗi hệ thống mong muốn phải có cấu trúc:
36
+ - **Global Exception Filter:** Implement a global Exception Filter to structure JSON error responses uniformly. The standardized error payload must follow this structure:
37
37
 
38
38
  ```json
39
39
  {
@@ -41,6 +41,6 @@ Tài liệu này quy định việc sử dụng Class Validator, thiết lập V
41
41
  "statusCode": 404,
42
42
  "timestamp": "2026-06-13T06:48:24.000Z",
43
43
  "path": "/api/v1/courses/999",
44
- "message": "Khóa học không tồn tại trên hệ thống."
44
+ "message": "The requested course does not exist."
45
45
  }
46
46
  ```
@@ -1,24 +1,24 @@
1
1
  ---
2
2
  name: nestjs-module
3
- description: Tự động sinh trọn bộ cấu phần gồm Module, Controller, Service, DTO, Entity theo đúng chuẩn hệ thống NestJS
3
+ description: Automatically scaffold a complete NestJS Module including Controller, Service, DTO, and Entity according to standard conventions
4
4
  ---
5
5
 
6
- Tuân thủ quy trình này để tạo mới một Module NestJS hoặc mở rộng một mô-đun hiện có.
6
+ Follow this process to generate a new NestJS Module or extend an existing one.
7
7
 
8
- Đầu vào (Inputs):
9
- - moduleName: Tên của mô-đun cần tạo ( dụ: `products`)
10
- - targetPath: Thư mục đích đặt nguồn bên dưới `src/`
11
- - functionality: Tóm tắt yêu cầu nghiệp vụ và các endpoints cần cung cấp
8
+ Inputs:
9
+ - moduleName: Name of the module to create (e.g., `products`)
10
+ - targetPath: The destination path inside `src/` to place the code
11
+ - functionality: Summary of the business requirements and endpoints to expose
12
12
 
13
- Các bước thực hiện (Steps):
14
- 1. Tạo thư mục mô-đun `<moduleName>/` bên dưới thư mục `src/` ( dụ: `src/products`).
15
- 2. Định nghĩa Entity model trong thư mục `<moduleName>/entities/`.
16
- 3. Định nghĩa các Request/Response DTO trong thư mục `<moduleName>/dto/`. Thêm các decorator validation tương ứng.
17
- 4. Xây dựng lớp Service trong `<moduleName>/` kế thừa DI của NestJS. Đặt toàn bộ business logic bắt lỗi để ném ra các HttpException tường minh ở đây.
18
- 5. Xây dựng Controller trong `<moduleName>/` để ánh xạ các yêu cầu HTTP, kiểm tra phân quyền (Guards) trả về kết quả JSON phù hợp.
19
- 6. Đăng Controller Service vào file định nghĩa mô-đun `<moduleName>.module.ts`, export Service nếu các module khác cần sử dụng.
20
- 7. Viết unit test cho Service (`.spec.ts`) cấu hình kịch bản kiểm thử tích hợp (E2E) sử dụng Supertest.
21
- 8. Chạy kiểm tra lỗi cục bộ:
13
+ Steps:
14
+ 1. Create a module directory `<moduleName>/` under the `src/` directory (e.g., `src/products`).
15
+ 2. Define the Entity model in the `<moduleName>/entities/` folder.
16
+ 3. Define the Request/Response DTO classes in the `<moduleName>/dto/` folder. Apply appropriate validation decorators.
17
+ 4. Implement the Service class in `<moduleName>/` using NestJS Dependency Injection. Write 100% of the business logic here, handle exceptions, and throw explicit HttpExceptions.
18
+ 5. Implement the Controller class in `<moduleName>/` to map HTTP requests, configure permission checks (Guards), and return the JSON response.
19
+ 6. Register the Controller and Service inside the module definition file `<moduleName>.module.ts`. Export the Service if other modules need to consume it.
20
+ 7. Write unit tests for the Service (`.spec.ts`) and create E2E integration test scripts using Supertest.
21
+ 8. Execute local validation:
22
22
  - `{{runCommand}} lint`
23
23
  - `{{runCommand}} typecheck`
24
24
  - `{{runCommand}} test`
@@ -1,41 +1,45 @@
1
- ## 🗺️ Hướng Dẫn Phát Triển Next.js (App Router)
2
-
3
- ### 🔄 Vòng Đời Phát Triển Tác Nhân (Agent Development Lifecycle)
4
- Tác nhân AI phải thực hiện tất cả các nhiệm vụ Next.js theo quy trình 5 bước sau:
5
- 1. **Thiết kế & Lập trình:** Xây dựng page và component tuân thủ cấu trúc App Router. Mặc định sử dụng React Server Components (RSC).
6
- 2. **Kiểm thử Toàn diện:** Viết unit test cho các tiện ích xử lý nghiệp vụ và kiểm thử hành vi giao diện bằng Jest/Vitest.
7
- 3. **Chất lượng Mã nguồn:** Chạy các lệnh kiểm tra lỗi cú pháp và kiểu dữ liệu:
8
- - Kiểm tra Lint: `{{runCommand}} lint`
9
- - Kiểm tra Kiểu dữ liệu: `{{runCommand}} typecheck`
10
- - Chạy Kiểm thử: `{{runCommand}} test` (hoặc `{{runCommand}} test -- --run` cho môi trường CI/CD)
11
- - Chạy Build thử nghiệm: `{{runCommand}} build`
12
- 4. **Quản lý Thư viện:** Cài đặt các thư viện mới bằng lệnh: `{{packageManager}} add [tên_thư_viện]`. Tuyệt đối cấm sửa thủ công file lock `{{lockFile}}`.
1
+ ## 🗺️ Next.js Development Guide (App Router)
13
2
 
14
- ---
15
-
16
- ### 🏗️ Kiến Trúc Hệ Thống Bản Mẫu (Template Blueprint)
17
- Vui lòng tham khảo các tài liệu quy tắc chi tiết dưới đây:
18
- - Quy ước viết mã, định dạng file, cấu trúc import tự động quy tắc tổ chức folder: `@next-style.md`
19
- - Phân định ranh giới kiến trúc giữa React Server Components (RSC) React Client Components (RCC): `@server-client-components.md`
20
- - Tiêu chuẩn hóa việc gọi API tại tầng Server, quản lý cơ chế Caching, Revalidation triển khai Server Actions bảo mật: `@data-fetching-mutations.md`
21
- - Quy định bắt buộc về Semantic HTML5 và tích hợp Dynamic Metadata API: `@seo-metadata.md`
22
- - Quy trình từng bước giúp khởi tạo một Page hoặc Route mới không lỗi: `@SKILL.md`
3
+ ### 🔄 Agent Development Lifecycle
4
+ The AI Agent must execute all Next.js tasks following this structured 5-stage lifecycle:
5
+ 1. **Design & Code:** Build pages and components adhering to the App Router conventions. Default to React Server Components (RSC) as described in `@server-client-components.md`.
6
+ 2. **Comprehensive Testing:** Write unit tests for business utilities and component behavior using Jest/Vitest.
7
+ 3. **Troubleshooting & Debugging:** When debugging data loading or hydration mismatch issues, isolate Server and Client component scopes.
8
+ 4. **Code Quality & Review:** Perform self-review using `@data-fetching-mutations.md` (for Server Actions and query caching parameters) and `@seo-metadata.md`. Check styling rules in `@next-style.md`.
9
+ 5. **Production Readiness:** Verify compilation, type checks, and next builds compile warning-free before committing.
23
10
 
24
11
  ---
25
12
 
26
- ### 🏛️ Quy Tắc Phát Triển Nghiêm Ngặt
13
+ ### 🏗️ Template Blueprint
14
+ Refer to the detailed rules below:
15
+ - Coding conventions, formatting, import sorting, and directory structure: `@next-style.md`
16
+ - Architectural boundaries between React Server Components (RSC) and React Client Components (RCC): `@server-client-components.md`
17
+ - Server-side data fetching, caching, revalidation, and secure Server Actions: `@data-fetching-mutations.md`
18
+ - Semantic HTML5 standards and Dynamic Metadata API configurations: `@seo-metadata.md`
19
+ - Step-by-step process to generate new Pages or Routes cleanly: `@next-feature`
27
20
 
28
- #### 1. Kiến Trúc Thành Phần (Rendering Paradigm)
29
- - **Mặc định là Server Components:** Tất cả các component trong thư mục `app/` mặc định phải là React Server Components (RSC).
30
- - **Cách ly Client Components (RCC):** Chỉ gắn directive `"use client"` ở lớp component lá (Leaf Components) cần tương tác (như xử lý Form, Nút bấm bắt sự kiện onClick, sử dụng useState, useEffect, hoặc các Hook trình duyệt).
31
-
32
- #### 2. Fetching Dữ Liệu & Server Actions
33
- - **Gọi dữ liệu tại gốc:** Thực hiện `fetch()` trực tiếp bên trong các async Server Components để tận dụng tối đa cơ chế tối ưu hóa request và bảo mật mã nguồn API token tại Server.
34
- - **Quản lý bộ nhớ đệm (Caching & Revalidation):** Nghiêm cấm sử dụng fetch thô không có cấu hình kiểm soát vòng đời dữ liệu.
35
- - **Đột biến dữ liệu (Mutations via Server Actions):** Toàn bộ các tương tác POST, PUT, DELETE phải qua Server Actions (`"use server"`).
36
- - **Trải nghiệm người dùng mượt mà:** Sử dụng hook `useActionState` (hoặc `useFormState`) để quản lý trạng thái phản hồi của form từ server và bọc các tác vụ mutate trong `useTransition` nhằm duy trì giao diện không bị đóng băng.
21
+ ---
37
22
 
38
- #### 3. Tối Ưu Hóa Hiệu Năng & SEO
39
- - **Tối ưu hình ảnh:** Tuyệt đối không dùng thẻ `<img>` thô. Bắt buộc sử dụng `<Image />` từ `next/image` với đầy đủ thuộc tính `sizes` và cấu hình `priority` cho các hình ảnh xuất hiện ở nấc màn hình đầu tiên (Above the fold).
40
- - **Tối ưu điều hướng:** Dùng `<Link />` từ `next/link` để kích hoạt cơ chế pre-fetching tài nguyên ngầm khi link xuất hiện trong viewport.
41
- - **Cấu hình Metadata động:** Khai báo cấu hình SEO thông qua hàm `generateMetadata` đối với các route động để tối ưu hóa SEO tối đa cho hệ thống tìm kiếm.
23
+ ### 🏛️ Strict Development Rules
24
+
25
+ #### 1. Rendering Paradigm
26
+ - **Server Components by Default:** All components within the `app/` directory must default to React Server Components (RSC).
27
+ - **Isolate Client Components (RCC):** Declare `"use client"` only at leaf components that require interactivity (e.g., Form submissions, click handlers, `useState`, `useEffect`, or browser APIs).
28
+
29
+ #### 2. Data Fetching & Server Actions
30
+ - **Fetch at the Source:** Execute `fetch()` directly inside async Server Components to optimize request caching and protect API tokens/secrets.
31
+ - **Cache Management:** Never use raw fetch without specifying caching/revalidation parameters.
32
+ - **Mutations via Server Actions:** Handle POST, PUT, and DELETE mutations using Server Actions (marked with `"use server"`).
33
+ - **Fluid UX:** Use the `useActionState` (or `useFormState`) hook to manage server response states and wrap mutation triggers in `useTransition` to keep the UI responsive.
34
+
35
+ #### 3. Performance & SEO Optimizations
36
+ - **Image Optimization:** Never use raw `<img>` tags. Use `next/image`'s `<Image />` with appropriate `sizes` attributes, and set `priority` for above-the-fold images.
37
+ - **Navigation:** Use `<Link />` from `next/link` to enable background pre-fetching when links enter the viewport.
38
+ - **Dynamic Metadata:** Export a `generateMetadata` function in dynamic routes to optimize search engine crawling.
39
+
40
+ ### 🧪 Verification & Testing
41
+ Before completing a task, run the following verification pipeline:
42
+ - **Linting:** `{{runCommand}} lint`
43
+ - **Type Checking:** `{{runCommand}} typecheck`
44
+ - **Testing:** `{{runCommand}} test`
45
+ - **Build Validation:** `{{runCommand}} build`
@@ -1,36 +1,36 @@
1
- # Gọi Dữ Liệu & Đột Biến Dữ Liệu (Data Fetching & Mutations)
1
+ # Data Fetching & Mutations
2
2
 
3
- Tài liệu này quy định tiêu chuẩn gọi API, quản lý bộ nhớ đệm (caching) thay đổi dữ liệu sử dụng Next.js Server Actions.
3
+ This document defines standard conventions for calling APIs, managing caching, and performing data mutations using Next.js Server Actions.
4
4
 
5
5
  ---
6
6
 
7
- ## 🔌 Gọi Dữ Liệu Tại Gốc (Data Fetching at the Source)
8
- - **Thực hiện trong RSC:** Gọi dữ liệu `fetch()` trực tiếp bên trong các async Server Components (`RSC`). Điều này giúp bảo mật API endpoint, token xác thực giảm thiểu độ trễ mạng bằng cách gộp xử lý trên server.
9
- - **Quy tắc:** Không sử dụng các client-side fetch wrapper tùy tiện trong các server pages. Hãy sử dụng cú pháp async/await tiêu chuẩn.
7
+ ## 🔌 Data Fetching at the Source
8
+ - **Execute inside RSCs:** Call `fetch()` directly inside async Server Components (`RSC`). This secures API endpoints, protects authentication tokens, and minimizes network latency by co-locating fetching and rendering.
9
+ - **Rule:** Do not use client-side fetch wrappers inside server pages. Use standard async/await syntax.
10
10
 
11
11
  ---
12
12
 
13
- ## 💾 Quản Lý Bộ Nhớ Đệm (Caching & Revalidation)
14
- - **Cấm Fetch Thô:** Nghiêm cấm sử dụng fetch() thô không cấu hình kiểm soát vòng đời dữ liệu hoặc chiến lược revalidate rõ ràng.
13
+ ## 💾 Caching & Revalidation
14
+ - **No Raw Fetch:** Using raw `fetch()` without specifying caching or revalidation strategies is prohibited.
15
15
 
16
- * **Không hợp lệ (❌ Nghiêm cấm):**
16
+ * **Invalid (❌ Prohibited):**
17
17
  ```typescript
18
- // Fetch dữ liệu tĩnh thời hạn mà không có chiến lược revalidate rõ ràng
18
+ // Fetches static data indefinitely without any revalidation strategy
19
19
  const res = await fetch('https://api.skillverse.vn/v1/courses');
20
20
  ```
21
- * **Hợp lệ (✔️ Khuyến khích):**
21
+ * **Valid (✔️ Recommended):**
22
22
  ```typescript
23
- // Cấu hình ISR (Incremental Static Regeneration) ràng với cache tag
23
+ // Configure ISR (Incremental Static Regeneration) with an explicit cache tag
24
24
  const res = await fetch('https://api.skillverse.vn/v1/courses', {
25
25
  next: { revalidate: 3600, tags: ['courses'] }
26
26
  });
27
27
  ```
28
- - **Làm mới bộ nhớ đệm:** Sử dụng `revalidatePath` hoặc `revalidateTag` bên trong các Server Actions để xóa các bản ghi cũ trong cache bắt buộc Next.js cập nhật lại dữ liệu mới.
28
+ - **Cache Refreshing:** Call `revalidatePath` or `revalidateTag` inside Server Actions to purge stale cache entries and force Next.js to pull fresh data.
29
29
 
30
30
  ---
31
31
 
32
- ## ⚡ Đột Biến Dữ Liệu (Mutations via Server Actions)
33
- - **Sử dụng Server Actions:** Toàn bộ các tương tác POST, PUT, DELETE, PATCH phải qua Server Actions được đánh dấu bằng directive `"use server"` đầu hàm hoặc đầu file chứa hành động.
34
- - **Trải nghiệm người dùng mượt mà:**
35
- - Sử dụng hook `useActionState` (hoặc `useFormState` trong các phiên bản trước React 19) để quản trạng thái phản hồi của form từ server kiểm soát trạng thái đang xử lý (`isPending`).
36
- - Bọc các tác vụ mutate trong `useTransition` nhằm duy trì giao diện người dùng mượt mà, không bị đóng băng trong quá trình xử lý ngầm.
32
+ ## ⚡ Mutations via Server Actions
33
+ - **Use Server Actions:** All POST, PUT, DELETE, and PATCH mutations must be processed through Server Actions marked with the `"use server"` directive at the top of the function or file.
34
+ - **Fluid User Experience:**
35
+ - Use the `useActionState` (or `useFormState` in React versions prior to 19) hook to manage server response states and track the `isPending` state.
36
+ - Wrap mutation executions inside `useTransition` to keep the user interface responsive and prevent freezing during background mutations.
@@ -1,32 +1,32 @@
1
- # Quy Ước Đặt Tên & Coding Style cho Next.js (App Router)
1
+ # Next.js Naming Conventions & Coding Style
2
2
 
3
- Tài liệu này đặc tả quy ước đặt tên file, thư mục, cấu trúc import tổ chức folder trong các dự án Next.js App Router.
3
+ This document defines conventions for directory structures, naming patterns, imports, and feature organization inside Next.js App Router projects.
4
4
 
5
5
  ---
6
6
 
7
- ## 🏷️ Quy Ước Đặt Tên (Naming Conventions)
7
+ ## 🏷️ Naming Conventions
8
8
 
9
- | Đối Tượng | Quy Chuẩn Đặt Tên | Dụ Minh Họa |
9
+ | Element | Naming Convention | Example |
10
10
  | :--- | :--- | :--- |
11
- | **Thư mục Route (`app/`)** | lowercase hoặc kebab-case | `app/dashboard/`, `app/user-profile/` |
12
- | **Route Nhóm (Route Groups)** | Bọc trong dấu ngoặc đơn `(group-name)` | `app/(auth)/login/`, `app/(dashboard)/layout.tsx` |
13
- | **Route Động (Dynamic Routes)** | Bọc trong dấu ngoặc vuông `[paramName]` | `app/blog/[id]/page.tsx`, `app/shop/[...slug]/page.tsx` |
14
- | **Tệp Giao Diện Đặc Trưng** | Định dạng chuẩn Next.js (lowercase.tsx) | `page.tsx`, `layout.tsx`, `loading.tsx`, `error.tsx` |
15
- | **Route Handlers** | Định dạng file API endpoint của Next.js | `route.ts` |
16
- | **Component UI Phụ Trợ** | PascalCase.tsx | `Button.tsx`, `ProductCard.tsx`, `SidebarSkeleton.tsx` |
17
- | **Custom Hooks** | camelCase bắt đầu bằng tiền tố `use` | `useAuth.ts`, `useLocalStorage.ts` |
11
+ | **Route Folders (`app/`)** | lowercase or kebab-case | `app/dashboard/`, `app/user-profile/` |
12
+ | **Route Groups** | Wrapped in parentheses `(group-name)` | `app/(auth)/login/`, `app/(dashboard)/layout.tsx` |
13
+ | **Dynamic Routes** | Wrapped in brackets `[paramName]` | `app/blog/[id]/page.tsx`, `app/shop/[...slug]/page.tsx` |
14
+ | **Special Routing Files** | Next.js standard filenames (lowercase) | `page.tsx`, `layout.tsx`, `loading.tsx`, `error.tsx` |
15
+ | **Route Handlers** | Next.js API endpoint filenames | `route.ts` |
16
+ | **UI Components** | PascalCase.tsx | `Button.tsx`, `ProductCard.tsx`, `SidebarSkeleton.tsx` |
17
+ | **Custom Hooks** | camelCase starting with the `use` prefix | `useAuth.ts`, `useLocalStorage.ts` |
18
18
 
19
19
  ---
20
20
 
21
21
  ## 📦 Imports & Aliasing
22
- - **Absolute Imports:** Luôn luôn sử dụng absolute imports với alias `@/` trỏ tới thư mục `src/` hoặc root ( dụ: `import { Button } from "@/components/ui/Button"`). Nghiêm cấm sử dụng relative imports với nhiều tầng nhảy thư mục sâu ( dụ: `../../../../Button`).
23
- - **CSS / Styles Imports:** Đặt các styles toàn cục trong một file duy nhất (như `globals.css` hoặc `index.css`) được import trong file `layout.tsx` gốc. Không import file CSS tùy tiện trong các component con.
22
+ - **Absolute Imports:** Always use absolute imports with the `@/` alias pointing to the root or `src/` directory (e.g., `import { Button } from "@/components/ui/Button"`). Do not use relative imports with deep directory nesting (e.g., `../../../../Button`).
23
+ - **CSS / Styles Imports:** Import global styles only in the root `layout.tsx` file (e.g., via `globals.css` or `index.css`). Do not import raw CSS files inside individual components.
24
24
 
25
25
  ---
26
26
 
27
- ## 📁 Tổ Chức Thư Mục (Folder Organization)
28
- - Giữ các thư mục bên trong `app/` dành riêng cho việc khai báo routing giao diện trang tương ứng.
29
- - Đặt các component nghiệp vụ, hook, service type bên trong thư mục `src/features/` hoặc `src/components/` bên ngoài thư mục `app/`. Mỗi feature ( dụ: `billing`) nên đóng gói các tài nguyên liên quan:
27
+ ## 📁 Directory Organization
28
+ - Keep directories within the `app/` folder focused strictly on routing and layout definitions.
29
+ - Locate business components, custom hooks, services, and types inside `src/features/` or `src/components/` outside the `app/` folder. Every feature (e.g., `billing`) should encapsulate its related resources:
30
30
  - `src/features/billing/components/BillingForm.tsx`
31
31
  - `src/features/billing/hooks/useBilling.ts`
32
- - Xuất bản public APIs của feature qua một file `index.ts` sạch sẽ.
32
+ - Expose the public API of each feature via a clean entrypoint file: `index.ts`.
@@ -1,18 +1,18 @@
1
- # Tối Ưu Hóa SEO & Cấu Trúc Semantic HTML
1
+ # SEO Optimization & Semantic HTML
2
2
 
3
- Tài liệu này quy định việc sử dụng cấu trúc thẻ Semantic, tối ưu hóa điều hướng hình ảnh và tích hợp Metadata API của Next.js để đạt thứ hạng SEO tốt nhất.
3
+ This document specifies conventions for using HTML5 Semantic tags, optimizing image delivery, and integrating Next.js Metadata APIs to achieve high SEO performance.
4
4
 
5
5
  ---
6
6
 
7
- ## 🔍 Tích Hợp Metadata API Của Next.js
8
- - **Metadata Tĩnh:** Khai báo đối tượng `metadata` tĩnh trong các layouts hoặc pages không biến số động:
7
+ ## 🔍 Next.js Metadata API
8
+ - **Static Metadata:** Declare a static `metadata` object in layouts or pages that do not require dynamic route parameters:
9
9
  ```typescript
10
10
  export const metadata = {
11
11
  title: 'Dashboard | Skillverse Platform',
12
- description: 'Trang tổng quan quản lý khóa học',
12
+ description: 'Course management overview dashboard',
13
13
  };
14
14
  ```
15
- - **Metadata Động:** Đối với các route động (như trang chi tiết bài viết, khóa học), khai báo cấu hình SEO thông qua hàm `generateMetadata` đối với các route động để tối ưu hóa SEO tối đa cho hệ thống tìm kiếm:
15
+ - **Dynamic Metadata:** For dynamic routes (e.g., article details, course views), define metadata through the exported `generateMetadata` function to optimize search engine indexing:
16
16
 
17
17
  ```typescript
18
18
  import { Metadata } from 'next';
@@ -33,18 +33,18 @@ Tài liệu này quy định việc sử dụng cấu trúc thẻ Semantic, tố
33
33
 
34
34
  ---
35
35
 
36
- ## 🎨 Cấu Trúc Semantic HTML5
37
- - **Thẻ cấu trúc:** Bắt buộc xây dựng bố cục trang bằng các thẻ HTML5 ngữ nghĩa thay lạm dụng các thẻ `<div>` vô nghĩa:
38
- - `<header>`: Thanh tiêu đề hoặc thanh đầu trang chính.
39
- - `<nav>`: Danh mục liên kết điều hướng cốt lõi.
40
- - `<main>`: Bao bọc duy nhất phần nội dung cốt lõi của trang.
41
- - `<section>`: Phân đoạn chủ đề nội dung tổng quát.
42
- - `<article>`: Các thành phần độc lập (bài viết blog, phần tử thẻ card sản phẩm).
43
- - `<footer>`: Chứa thông tin bản quyền và liên kết chân trang.
44
- - **Tiêu đề h-tags:** Đảm bảo thứ tự logic của các thẻ tiêu đề (từ `<h1>` đến `<h6>`). Đảm bảo duy nhất một thẻ `<h1>` trên mỗi trang.
36
+ ## 🎨 Semantic HTML5 Structure
37
+ - **Structural Tags:** Build layouts using semantic HTML5 tags instead of nesting generic `<div>` containers:
38
+ - `<header>`: Main navigation bar or header sections.
39
+ - `<nav>`: Primary navigation links.
40
+ - `<main>`: Wraps the unique primary content of the page.
41
+ - `<section>`: General thematic groupings of content.
42
+ - `<article>`: Independent self-contained items (e.g., blog posts, product cards).
43
+ - `<footer>`: Copyright and footer link sections.
44
+ - **Header Hierarchy:** Follow a strict heading hierarchy (from `<h1>` down to `<h6>`). Ensure there is only one `<h1>` tag per page.
45
45
 
46
46
  ---
47
47
 
48
- ## ⚡ Tối Ưu Hóa Hình Ảnh & Điều Hướng
49
- - **Tối ưu hình ảnh:** Tuyệt đối không dùng thẻ `<img>` thô. Bắt buộc sử dụng `<Image />` từ `next/image` với đầy đủ thuộc tính `sizes` cấu hình `priority` cho các hình ảnh xuất hiện ở nấc màn hình đầu tiên (Above the fold).
50
- - **Tối ưu điều hướng:** Dùng `<Link />` từ `next/link` để kích hoạt chế pre-fetching tài nguyên ngầm khi link xuất hiện trong viewport, giúp chuyển trang tức thì.
48
+ ## ⚡ Image & Link Optimizations
49
+ - **Image Optimization:** Never use raw `<img>` tags. Use Next.js `<Image />` from `next/image` with appropriate `sizes` attributes, and set `priority` for above-the-fold images.
50
+ - **Navigation Optimization:** Use `<Link />` from `next/link` to automatically trigger resource pre-fetching when links enter the viewport, enabling instant transition.
@@ -1,27 +1,27 @@
1
1
  # React Server Components (RSC) vs React Client Components (RCC)
2
2
 
3
- Tài liệu này quy định ranh giới kiến trúc quy tắc phân loại component trong ứng dụng Next.js sử dụng App Router.
3
+ This document establishes architectural boundaries and classification rules for components in Next.js App Router projects.
4
4
 
5
5
  ---
6
6
 
7
7
  ## 🏛️ React Server Components (RSC)
8
- - **Mặc định:** Tất cả các page, layout component được tạo bên trong thư mục routing `app/` mặc định phải React Server Components (RSC).
9
- - **Lợi ích của RSC:**
10
- - Gọi dữ liệu (data fetching) trực tiếp sử dụng async/await.
11
- - Sử dụng an toàn các thư viện phía server (truy vấn DB, đọc file, import khóa bảo mật).
12
- - Giảm dung lượng bundle size gửi xuống client do nguồn RSC chỉ biên dịch chạy trên server.
13
- - **Quy tắc:**
14
- - Thực hiện toàn bộ việc nạp dữ liệu cấu trúc khung trang bên trong các RSC.
15
- - Không thêm `"use client"` vào các layout hoặc page entry points trừ khi bắt buộc.
8
+ - **Default Behavior:** All pages, layouts, and components created within the `app/` routing directory must default to React Server Components (RSC).
9
+ - **RSC Benefits:**
10
+ - Fetch data directly using async/await syntax at the server level.
11
+ - Securely utilize server-side libraries and APIs (e.g., database queries, file reading, private tokens).
12
+ - Decrease client-side bundle sizes because RSC code remains on the server and is not sent to the browser.
13
+ - **Rules:**
14
+ - Perform all data fetching and layout structure setups within RSCs.
15
+ - Never add the `"use client"` directive to layout or page entrypoint files unless absolutely necessary.
16
16
 
17
17
  ---
18
18
 
19
19
  ## 💻 React Client Components (RCC)
20
- - **Định nghĩa:** Các component chạy trên trình duyệt để hỗ trợ tương tác cập nhật trạng thái động từ người dùng.
21
- - **Dấu hiệu nhận biết RCC:** Chỉ gắn directive `"use client"` lớp component (Leaf Components) khi component:
22
- - Sử dụng các Hook vòng đời và trạng thái của React (`useState`, `useReducer`, `useEffect`, `useLayoutEffect`).
23
- - Gọi các API đặc trưng của trình duyệt (`window`, `localStorage`, custom viewport hooks).
24
- - Đăng các callback lắng nghe sự kiện DOM (như `onClick`, `onChange`, `onSubmit`).
25
- - **Phân tách ranh giới RCC:**
26
- - Giữ RCC cấp (Leaf Components) cuối cùng của cây dựng hình để tối ưu hiệu năng.
27
- - * dụ:* Nếu trang danh sách sản phẩm (RSC) thanh tìm kiếm (RCC), hãy tách thanh tìm kiếm thành một component riêng (`<SearchBar />` `"use client"`) import vào trang cha chạy phía server.
20
+ - **Definition:** Components that execute on the browser to support dynamic user interactions and state updates.
21
+ - **Identifying RCCs:** Attach the `"use client"` directive only at leaf component levels when they:
22
+ - Use React hooks (`useState`, `useReducer`, `useEffect`, `useLayoutEffect`).
23
+ - Use browser-specific APIs (e.g., `window`, `localStorage`, custom viewport hooks).
24
+ - Bind DOM event listeners (e.g., `onClick`, `onChange`, `onSubmit`).
25
+ - **RCC Isolation Guidelines:**
26
+ - Keep RCCs at the absolute leaf level of the rendering tree to optimize loading speed.
27
+ - *Example:* If a product list page (RSC) includes a search input (RCC), encapsulate the search input in its own component (e.g., `<SearchBar />` marked with `"use client"`) and import it into the server-rendered parent page.
@@ -1,25 +1,25 @@
1
1
  ---
2
2
  name: next-feature
3
- description: Sinh hoặc mở rộng một page hoặc route handler Next.js + TypeScript mới kèm caching metadata
3
+ description: Generate or extend a new Next.js + TypeScript page or route handler with caching and metadata
4
4
  ---
5
5
 
6
- Tuân thủ quy trình này để tạo một page, layout hoặc API route handler mới trong Next.js.
6
+ Follow this process to generate a new page, layout, or API route handler in Next.js.
7
7
 
8
- Đầu vào (Inputs):
9
- - featureName: Tên của route hoặc trang ( dụ: `dashboard`)
10
- - targetPath: Thư mục chứa route bên trong `app/` để triển khai
11
- - userFlow: tả tóm tắt hành vi bố cục giao diện của trang
8
+ Inputs:
9
+ - featureName: Name of the route or page (e.g., `dashboard`)
10
+ - targetPath: The directory inside the `app/` folder to implement the route
11
+ - userFlow: Brief description of the page behavior and layout
12
12
 
13
- Các bước thực hiện (Steps):
14
- 1. Quét các thư mục lân cận trong `app/` để tham chiếu các layout chung ranh giới xử lý lỗi (`error.tsx`).
15
- 2. Thiết lập cấu trúc thư mục route theo chuẩn Next.js ( dụ: `app/(dashboard)/billing`).
16
- 3. Khai báo interface cho route params query parameters.
17
- 4. Triển khai cấu trúc trang hoặc layout dưới dạng **React Server Component (RSC)**.
18
- 5. Nếu tương tác người dùng hoặc form, hãy tách thành các component con cấp (RCC) được đánh dấu `"use client"` rồi import vào RSC.
19
- 6. Thiết lập chế cache ràng cho toàn bộ các thao tác gọi dữ liệu `fetch()`.
20
- 7. Cấu hình metadata tĩnh hoặc động thông qua hàm `generateMetadata`.
21
- 8. Định nghĩa file xử lỗi cục bộ (`error.tsx`) tại thư mục route gần nhất để bắt lỗi runtime.
22
- 9. Thực hiện kiểm tra lỗi cục bộ:
13
+ Steps:
14
+ 1. Scan neighboring directories in the `app/` folder to check for shared layouts and error boundaries (`error.tsx`).
15
+ 2. Set up the route directory structure according to Next.js standards (e.g., `app/(dashboard)/billing`).
16
+ 3. Declare TypeScript interfaces for route parameters and query parameters.
17
+ 4. Implement the page or layout structure as a **React Server Component (RSC)**.
18
+ 5. If user interaction or form handling is needed, isolate it in a leaf Client Component (RCC) marked with `"use client"` and import it into the parent RSC.
19
+ 6. Configure explicit caching parameters for all data fetching `fetch()` calls.
20
+ 7. Set up static or dynamic SEO metadata using the `generateMetadata` function.
21
+ 8. Define a local error handler file (`error.tsx`) in the route directory to catch runtime exceptions.
22
+ 9. Execute local validation:
23
23
  - `{{runCommand}} lint`
24
24
  - `{{runCommand}} typecheck`
25
25
  - `{{runCommand}} test`
@@ -0,0 +1,41 @@
1
+ ## 🗺️ Rust Development Guide
2
+
3
+ ### 🔄 Agent Development Lifecycle
4
+ The AI Agent must execute all Rust tasks following this structured 5-stage lifecycle:
5
+ 1. **Design & Code:** Implement business logic adhering to Rust conventions. Enforce structural separation: `main.rs` (for binary application setup) and `lib.rs` (for core business logic that can be reused and tested).
6
+ 2. **Comprehensive Testing:** Write unit tests inside internal test modules and integration tests in the `/tests` directory. Mocks and double components should be declared under `#[cfg(test)]`.
7
+ 3. **Troubleshooting & Debugging:** When debugging lifetimes, memory borrow errors, or asynchronous deadlocks, refer to `@memory-concurrency.md` directives.
8
+ 4. **Code Quality & Review:** Verify code conforms strictly to `@rust-style.md` check criteria (preventing warnings, formatting code, avoiding over-cloning).
9
+ 5. **Crate Architecture:** Organize workspace dependencies using Cargo Workspaces if building multi-crate projects, maintaining encapsulation guidelines in `@project-layout.md`.
10
+
11
+ ---
12
+
13
+ ### 🏗️ Template Blueprint
14
+ Refer to the detailed rules below:
15
+ - Idiomatic Rust, clippy lints, and cloning optimizations: `@rust-style.md`
16
+ - Crate modules, Cargo Workspaces, and Trait-based Dependency Injection: `@project-layout.md`
17
+ - Failures management, Result/Option, `thiserror`, and `anyhow`: `@error-handling.md`
18
+ - Lifetimes `'a`, Smart Pointers, and async Tokio safety: `@memory-concurrency.md`
19
+ - Scaffolding a Rust feature (Struct, traits, implementations, unit tests): `@rust-feature`
20
+ - Scaffolding asynchronous database repositories and models: `@rust-db`
21
+
22
+ ---
23
+
24
+ ### 🏛️ Strict Development Rules
25
+
26
+ #### 1. Ownership & Borrowing
27
+ - **Avoid Over-Cloning:** Call `.clone()` on Heap types only when you must own an independent copy. Otherwise, design functions to receive read references `&T` or write references `&mut T`.
28
+ - **Exclusive Mutable Borrow:** Ensure only one mutable reference `&mut T` exists at a time, and never let it coexist with any read references `&T` in the same scope.
29
+
30
+ #### 2. Safe Error Handling
31
+ - **No Unwraps:** Never use `.unwrap()` or `.expect()` in production code (except in tests). Propagate errors using `Result<T, E>` or `Option<T>` to ensure system reliability. Manage library errors with `thiserror` and application errors with `anyhow` as outlined in `@error-handling.md`.
32
+
33
+ #### 3. Async Concurrency (Tokio)
34
+ - **CPU-Bound Tasks:** Never run heavy CPU operations (e.g., encryption, intensive loops) directly inside async contexts. Offload them using `tokio::task::spawn_blocking`.
35
+ - **Mutex Selection:** Prefer standard `std::sync::Mutex` for synchronizing state across threads if the guard is not held across `.await` points. Use `tokio::sync::Mutex` only when needed to prevent scheduling blocking.
36
+
37
+ ### 🧪 Verification & Testing
38
+ Before completing a task, run the following verification pipeline locally:
39
+ - **Lint check:** `cargo clippy --all-targets -- -D warnings`
40
+ - **Testing:** `cargo test`
41
+ - **Formatting:** `cargo fmt -- --check`
@@ -0,0 +1,36 @@
1
+ # Error Handling & Fault Control in Rust
2
+
3
+ This document defines strict rules for handling, wrapping, and propagating failures using idiomatic Rust patterns.
4
+
5
+ ---
6
+
7
+ ## 🚫 Avoid Panics in Production
8
+ - **Strict Rule:** Never use `panic!`, `.unwrap()`, or `.expect()` in production application code. Doing so triggers process termination, resulting in service interruption.
9
+ - **Exceptions:** Only use panics in:
10
+ - Unit and Integration Tests.
11
+ - Initial bootstrapping (e.g., parsing critical files at startup) when missing items make recovery impossible.
12
+ - Invariants where the logic guarantees a failure is impossible.
13
+
14
+ ---
15
+
16
+ ## 🔄 Result Propagation with the `?` Operator
17
+ - All fallible business logic operations must return `Result<T, E>` or `Option<T>`.
18
+ - Use the `?` operator to propagate errors up the call stack, maintaining a clean syntax.
19
+
20
+ ---
21
+
22
+ ## 📚 Error Libraries: `thiserror` vs `anyhow`
23
+ Never mix these libraries arbitrarily. Comply with the following separation:
24
+ - **Use `thiserror` for Library Crates / Domain Modules:** Creates strongly-typed, detailed error definitions with custom display messages.
25
+ ```rust
26
+ use thiserror::Error;
27
+
28
+ #[derive(Error, Debug)]
29
+ pub enum DatabaseError {
30
+ #[error("User not found with ID {0}")]
31
+ UserNotFound(i64),
32
+ #[error("Database connection failure: {0}")]
33
+ ConnectionFailed(String),
34
+ }
35
+ ```
36
+ - **Use `anyhow` for Application Entrypoints (API Gateway / CLI main):** Ideal for general error grouping and stack propagation without complex type mapping.