agent-workflow-kit-cli 1.3.2 → 1.3.3

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 (39) hide show
  1. package/dist/cli/commands/add.js +3 -1
  2. package/dist/cli/commands/init.js +6 -0
  3. package/dist/core/analyzer.js +70 -0
  4. package/dist/core/detector.js +22 -0
  5. package/package.json +1 -1
  6. package/templates/common/AGENTS.md.hbs +4 -0
  7. package/templates/common/GLOBAL_RULES.md +101 -0
  8. package/templates/dotnet/AGENTS.md.hbs +34 -34
  9. package/templates/dotnet/rules/api-structure.md +15 -15
  10. package/templates/dotnet/rules/csharp-style.md +17 -17
  11. package/templates/dotnet/rules/dependency-injection.md +12 -12
  12. package/templates/dotnet/rules/error-handling-validation.md +15 -15
  13. package/templates/dotnet/skills/dotnet-controller/SKILL.md +16 -16
  14. package/templates/express/AGENTS.md.hbs +33 -33
  15. package/templates/express/rules/error-handling.md +18 -18
  16. package/templates/express/rules/express-style.md +19 -19
  17. package/templates/express/rules/router-controller.md +16 -16
  18. package/templates/express/skills/express-endpoint/SKILL.md +14 -14
  19. package/templates/golang/AGENTS.md.hbs +36 -0
  20. package/templates/golang/rules/concurrency.md +71 -0
  21. package/templates/golang/rules/error-handling.md +42 -0
  22. package/templates/golang/rules/golang-style.md +24 -0
  23. package/templates/golang/rules/project-layout.md +39 -0
  24. package/templates/nestjs/AGENTS.md.hbs +29 -29
  25. package/templates/nestjs/rules/module-architecture.md +14 -14
  26. package/templates/nestjs/rules/nestjs-style.md +12 -12
  27. package/templates/nestjs/rules/validation-errors.md +15 -15
  28. package/templates/nestjs/skills/nestjs-module/SKILL.md +15 -15
  29. package/templates/next-js/AGENTS.md.hbs +32 -32
  30. package/templates/next-js/rules/data-fetching-mutations.md +17 -17
  31. package/templates/next-js/rules/next-style.md +17 -17
  32. package/templates/next-js/rules/seo-metadata.md +18 -18
  33. package/templates/next-js/rules/server-client-components.md +17 -17
  34. package/templates/next-js/skills/next-feature/SKILL.md +16 -16
  35. package/templates/rust/AGENTS.md.hbs +34 -0
  36. package/templates/rust/rules/error-handling.md +36 -0
  37. package/templates/rust/rules/memory-concurrency.md +47 -0
  38. package/templates/rust/rules/project-layout.md +49 -0
  39. package/templates/rust/rules/rust-style.md +26 -0
@@ -1,38 +1,38 @@
1
- ## 🗺️ Hướng Dẫn Phát Triển NestJS (Node.js Backend)
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ụ NestJS theo quy trình 5 bước sau:
5
- 1. **Thiết kế & Lập trình:** Triển khai các lớp nghiệp vụ tuân thủ cấu trúc Module-driven. Giữ Controller mỏng, đặt 100% logic nghiệp vụ trong Service.
6
- 2. **Kiểm thử Toàn diện:** Viết unit test cho các Service sử dụng Jest Mocking (`.spec.ts`) viết kiểm thử tích hợp đầu cuối (E2E) sử dụng Supertest.
7
- 3. **Chất lượng 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
+ ## 🗺️ NestJS Development Guide (Node.js Backend)
2
+
3
+ ### 🔄 Agent Development Lifecycle
4
+ The AI Agent must execute all NestJS tasks following this 5-step workflow:
5
+ 1. **Design & Implementation:** Implement business logic adhering to the Module-driven architecture. Keep Controllers thin; place 100% of business logic within Services.
6
+ 2. **Comprehensive Testing:** Write unit tests for Services using Jest Mocking (`.spec.ts`) and end-to-end (E2E) integration tests using Supertest.
7
+ 3. **Code Quality & Type Safety:** Run syntax check and type check commands:
8
+ - Linting: `{{runCommand}} lint`
9
+ - Type Checking: `{{runCommand}} typecheck`
10
+ - Testing: `{{runCommand}} test` (or `{{runCommand}} test -- --run` for CI/CD environments)
11
+ - Build Validation: `{{runCommand}} build`
12
+ 4. **Dependency Management:** Install new libraries using `{{packageManager}} add [library_name]`. Never modify the lockfile `{{lockFile}}` manually.
13
13
 
14
14
  ---
15
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
- - Hướng dẫn coding style chuẩn TypeScript, quy tắc căn lề, sắp xếp decorator tổ chức nguồn sạch: `@nestjs-style.md`
19
- - Quy định chặt chẽ về ranh giới Module, cơ chế cô lập mã nguồn, Encapsulation chia sẻ tài nguyên: `@module-architecture.md`
20
- - Cấu hình Class Validator, chuyển đổi dữ liệu thông qua ValidationPipe xử lỗi tập trung bằng Exceptions Filters: `@validation-errors.md`
21
- - Quy trình tự động sinh trọn bộ cấu phần gồm Module, Controller, Service, DTO, Entity theo đúng chuẩn hệ thống: `@SKILL.md`
16
+ ### 🏗️ Template Blueprint
17
+ Refer to the detailed rules below:
18
+ - TypeScript coding style, indentation, decorator sorting, and clean code conventions: `@nestjs-style.md`
19
+ - Strict module boundaries, encapsulation, and resource sharing rules: `@module-architecture.md`
20
+ - Class Validator setups, ValidationPipe data transformations, and Exception Filters: `@validation-errors.md`
21
+ - Process to scaffold modular components (Module, Controller, Service, DTO, Entity): `@SKILL.md`
22
22
 
23
23
  ---
24
24
 
25
- ### 🏛️ Quy Tắc Phát Triển Nghiêm Ngặt
25
+ ### 🏛️ Strict Development Rules
26
26
 
27
- #### 1. Tiêm Phụ Thuộc (Dependency Injection)
28
- - **Cấm tiêm thuộc tính (Property Injection):** Tuyệt đối không dùng `@Inject()` trực tiếp trên thuộc tính của Class trừ trường hợp tiêm các token tùy biến (Custom Tokens).
29
- - **Bắt buộc tiêm qua Hàm Khởi Tạo (Constructor Injection):** Sử dụng chế tự động phân giải phụ thuộc của NestJS qua từ khóa `private readonly`.
27
+ #### 1. Dependency Injection (DI)
28
+ - **No Property Injection:** Never use the `@Inject()` decorator directly on class properties unless injecting Custom Tokens. Property injection limits test mocking capabilities.
29
+ - **Constructor Injection Required:** Leverage NestJS's auto-dependency resolution via constructor parameters using `private readonly`.
30
30
 
31
- #### 2. Kiểm Thử Dữ Liệu Đầu Vào (Validation & Transformation)
32
- - **Đị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`.
33
- - **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) và tự động ép kiểu dữ liệu (transform).
31
+ #### 2. Input Validation & Transformation
32
+ - **Strict DTO Definitions:** All incoming HTTP request parameters (`@Body()`, `@Query()`, `@Param()`) must be mapped to DTO classes decorated with `class-validator` rules.
33
+ - **Global Validation Pipe:** Configure a global `ValidationPipe` in `main.ts` to strip non-whitelisted properties and automatically transform types.
34
34
 
35
- #### 3. Quản Lý Ngoại Lệ Toàn Cục (Unified Exception Handling)
36
- - **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) ra ngoài client với mã lỗi 500.
37
- - **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`).
38
- - **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.
35
+ #### 3. Unified Exception Handling
36
+ - **No Raw Server Errors:** Never expose raw database or system exceptions (HTTP 500) to clients.
37
+ - **Built-in HttpExceptions:** Handle try/catch flows inside Services and map errors to explicit NestJS HttpExceptions (e.g., `NotFoundException`, `BadRequestException`, `ForbiddenException`).
38
+ - **Global Exception Filter:** Expose a global Exception Filter to format all error responses consistently in JSON format.
@@ -1,14 +1,14 @@
1
- # Kiến Trúc Mô-đun & Chế Tiêm Phụ Thuộc (DI)
1
+ # Modular Architecture & Dependency Injection (DI)
2
2
 
3
- Tài liệu này quy định ranh giới Module, chế cô lập mã nguồn, Encapsulation cách tiêm phụ thuộc chuẩn trong NestJS.
3
+ This document defines module boundaries, code isolation (encapsulation), and dependency injection standards in NestJS.
4
4
 
5
5
  ---
6
6
 
7
- ## 💉 Tiêm Phụ Thuộc (Dependency Injection)
8
- - **Cấm tiêm thuộc tính (Property Injection):** Tuyệt đối không dùng `@Inject()` trực tiếp trên thuộc tính của Class trừ trường hợp tiêm các token tùy biến (Custom Tokens). Việc tiêm thuộc tính làm giảm khả năng kiểm thử (mocking) và làm loãng mã nguồn.
9
- - **Bắt buộc tiêm qua Hàm Khởi Tạo (Constructor Injection):** Sử dụng chế tự động phân giải phụ thuộc của NestJS qua từ khóa `private readonly` trong constructor.
7
+ ## 💉 Dependency Injection (DI)
8
+ - **No Property Injection:** Never use the `@Inject()` decorator directly on class properties unless injecting Custom Tokens. Property injection degrades mock testing and litters class definitions.
9
+ - **Constructor Injection Required:** Use constructor parameter injection with the `private readonly` modifier to leverage NestJS's dependency resolution.
10
10
 
11
- * **Không hợp lệ (❌ Cấm viết):**
11
+ * **Invalid (❌ Prohibited):**
12
12
  ```typescript
13
13
  @Injectable()
14
14
  export class AuthService {
@@ -16,7 +16,7 @@ Tài liệu này quy định ranh giới Module, cơ chế cô lập mã nguồn
16
16
  private readonly usersService: UsersService;
17
17
  }
18
18
  ```
19
- * **Hợp lệ (✔️ Khuyến khích):**
19
+ * **Valid (✔️ Recommended):**
20
20
  ```typescript
21
21
  @Injectable()
22
22
  export class AuthService {
@@ -26,10 +26,10 @@ Tài liệu này quy định ranh giới Module, cơ chế cô lập mã nguồn
26
26
 
27
27
  ---
28
28
 
29
- ## 🏗️ Ranh Giới Mô-đun & Encapsulation
30
- - ** lập theo mặc định (Encapsulation by Default):** Các Provider (Services, Repositories) bên trong một Module mặc định private. Các module khác không thể truy cập nếu không được export công khai.
31
- - **Chia sẻ tài nguyên qua Module:** Khi Module B muốn sử dụng Service của Module A:
32
- 1. Thêm Service đó vào mảng `exports` trong `@Module()` của Module A.
33
- 2. Import Module A vào mảng `imports` của Module B.
34
- * Nghiêm cấm import trực tiếp Service của Module A vào danh sách `providers` của Module B.
35
- - **Mô-đun Toàn cục (Global Modules):** Hạn chế sử dụng `@Global()` ngoại trừ các mô-đun hạ tầng chung cực kỳ ổn định (như sở dữ liệu hoặc cấu hình hệ thống).
29
+ ## 🏗️ Module Boundaries & Encapsulation
30
+ - **Encapsulated by Default:** Providers (Services, Repositories) inside a Module are private by default. Other modules cannot access them unless they are explicitly exported.
31
+ - **Sharing Resources:** When Module B needs to use a Service declared in Module A:
32
+ 1. Add that Service to the `exports` array in Module A's `@Module()` decorator.
33
+ 2. Add Module A to the `imports` array in Module B's `@Module()` decorator.
34
+ * **Strict Rule:** Never import a Service of Module A directly into the `providers` array of Module B.
35
+ - **Global Modules:** Avoid using `@Global()` unless configuring highly stable infrastructure modules (e.g., Database connections or Config systems).
@@ -1,16 +1,16 @@
1
- # Quy Ước Đặt Tên & Coding Style cho NestJS
1
+ # NestJS Naming Conventions & Coding Style
2
2
 
3
- Tài liệu này hướng dẫn coding style chuẩn TypeScript, quy tắc đặt tên tệp tin lớp trong NestJS.
3
+ This document outlines standard guidelines for TypeScript coding styles, filename notations, and class naming conventions in NestJS.
4
4
 
5
5
  ---
6
6
 
7
- ## 🏷️ Quy Ước Đặt Tên (Naming Conventions)
7
+ ## 🏷️ Naming Conventions
8
8
 
9
- ### Kỹ thuật Đặt Tên Tệp (Dot Notation)
10
- Tất cả các tệp tin trong NestJS phải tuân thủ nghiêm ngặt định dạng cấu trúc: `<tên-đối-tượng>.<loại-cấu-phần>.ts`.
9
+ ### Filename Notation (Dot Notation)
10
+ All filenames in NestJS must strictly comply with the following format: `<name>.<type>.ts`.
11
11
 
12
12
  ```bash
13
- # Thư mục module luôn dùng số nhiều hoặc số ít đồng nhất ( dụ: auth, users, products)
13
+ # Module directories should use consistent singular or plural names (e.g., auth, users, products)
14
14
  src/users/
15
15
  ├── users.module.ts
16
16
  ├── users.controller.ts
@@ -26,8 +26,8 @@ src/users/
26
26
  └── logging.interceptor.ts
27
27
  ```
28
28
 
29
- ### Quy ước đặt tên Lớp (Class Naming)
30
- Tên lớp phải được viết theo định dạng PascalCase kết thúc bằng tên cụ thể của loại cấu phần đó:
29
+ ### Class Naming
30
+ Class names must use `PascalCase` and end with the specific component suffix representing their role:
31
31
  - **Controller:** `src/auth/auth.controller.ts` $\rightarrow$ `export class AuthController {}`
32
32
  - **Service:** `src/auth/auth.service.ts` $\rightarrow$ `export class AuthService {}`
33
33
  - **Module:** `src/auth/auth.module.ts` $\rightarrow$ `export class AuthModule {}`
@@ -35,7 +35,7 @@ Tên lớp phải được viết theo định dạng PascalCase và kết thúc
35
35
 
36
36
  ---
37
37
 
38
- ## 📦 TypeScript & Sắp Xếp Decorator
39
- - **Sắp xếp Decorator:** Nhóm sắp xếp các decorator một cách khoa học. Các decorator định nghĩa phương thức HTTP (`@Get()`, `@Post()`) nằm trên cùng, tiếp theo cấu hình bảo mật hoặc kiểm duyệt đầu vào (`@UseGuards()`, `@UseInterceptors()`).
40
- - **Kiểu trả về tường minh:** Khai báo kiểu trả về ràng cho tất cả các phương thức trong Controller Service để bảo đảm tính chặt chẽ của kiểu dữ liệu.
41
- - **Nghiêm cấm kiểu dữ liệu `any`:** Luôn khai báo class hoặc interface tương ứng cho các tham số kết quả xử lý.
38
+ ## 📦 TypeScript & Decorator Sorting
39
+ - **Decorator Sorting:** Group and organize decorator annotations systematically. Place HTTP methods (`@Get()`, `@Post()`) on top, followed by guards or interceptors (`@UseGuards()`, `@UseInterceptors()`).
40
+ - **Explicit Return Types:** Always define clear return types for all Controller and Service methods to guarantee type safety.
41
+ - **Strictly Ban the `any` Type:** Avoid generic `any` keywords. Create proper classes, interfaces, or types for all arguments and responses.
@@ -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,41 @@
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 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ử nghiệp vụ và kiểm thử hành vi giao diện bằng Jest/Vitest.
7
- 3. **Chất lượng 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)
2
+
3
+ ### 🔄 Agent Development Lifecycle
4
+ The AI Agent must execute all Next.js tasks following this 5-step workflow:
5
+ 1. **Design & Implementation:** Build pages and components adhering to the App Router conventions. Default to React Server Components (RSC).
6
+ 2. **Comprehensive Testing:** Write unit tests for business utilities and component behavior using Jest/Vitest.
7
+ 3. **Code Quality & Type Safety:** Run syntax check and type check commands:
8
+ - Linting: `{{runCommand}} lint`
9
+ - Type Checking: `{{runCommand}} typecheck`
10
+ - Testing: `{{runCommand}} test` (or `{{runCommand}} test -- --run` for CI/CD environments)
11
+ - Build Validation: `{{runCommand}} build`
12
+ 4. **Dependency Management:** Install new libraries using `{{packageManager}} add [library_name]`. Never modify the lockfile `{{lockFile}}` manually.
13
13
 
14
14
  ---
15
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 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`
16
+ ### 🏗️ Template Blueprint
17
+ Refer to the detailed rules below:
18
+ - Coding conventions, formatting, import sorting, and directory structure: `@next-style.md`
19
+ - Architectural boundaries between React Server Components (RSC) and React Client Components (RCC): `@server-client-components.md`
20
+ - Server-side data fetching, caching, revalidation, and secure Server Actions: `@data-fetching-mutations.md`
21
+ - Semantic HTML5 standards and Dynamic Metadata API configurations: `@seo-metadata.md`
22
+ - Step-by-step process to generate new Pages or Routes cleanly: `@SKILL.md`
23
23
 
24
24
  ---
25
25
 
26
- ### 🏛️ Quy Tắc Phát Triển Nghiêm Ngặt
26
+ ### 🏛️ Strict Development Rules
27
27
 
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 React Server Components (RSC).
30
- - **Cách ly Client Components (RCC):** Chỉ gắn directive `"use client"` lớp component (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).
28
+ #### 1. Rendering Paradigm
29
+ - **Server Components by Default:** All components within the `app/` directory must default to React Server Components (RSC).
30
+ - **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).
31
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 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ấ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 trạng thái phản hồi của form từ server bọc các tác vụ mutate trong `useTransition` nhằm duy trì giao diện không bị đóng băng.
32
+ #### 2. Data Fetching & Server Actions
33
+ - **Fetch at the Source:** Execute `fetch()` directly inside async Server Components to optimize request caching and protect API tokens/secrets.
34
+ - **Cache Management:** Never use raw fetch without specifying caching/revalidation parameters.
35
+ - **Mutations via Server Actions:** Handle POST, PUT, and DELETE mutations using Server Actions (marked with `"use server"`).
36
+ - **Fluid UX:** Use the `useActionState` (or `useFormState`) hook to manage server response states and wrap mutation triggers in `useTransition` to keep the UI responsive.
37
37
 
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` 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.
38
+ #### 3. Performance & SEO Optimizations
39
+ - **Image Optimization:** Never use raw `<img>` tags. Use `next/image`'s `<Image />` with appropriate `sizes` attributes, and set `priority` for above-the-fold images.
40
+ - **Navigation:** Use `<Link />` from `next/link` to enable background pre-fetching when links enter the viewport.
41
+ - **Dynamic Metadata:** Export a `generateMetadata` function in dynamic routes to optimize search engine crawling.
@@ -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.