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.
- package/dist/cli/commands/add.js +3 -1
- package/dist/cli/commands/doctor.js +145 -47
- package/dist/cli/commands/init.js +6 -0
- package/dist/core/analyzer.js +70 -0
- package/dist/core/detector.js +22 -0
- package/package.json +1 -1
- package/templates/common/AGENTS.md.hbs +4 -0
- package/templates/common/GLOBAL_RULES.md +101 -0
- package/templates/devops/AGENTS.md.hbs +32 -0
- package/templates/devops/skills/devops/SKILL.md +477 -0
- package/templates/diagram/AGENTS.md.hbs +30 -0
- package/templates/diagram/skills/drawio-diagram/SKILL.md +427 -0
- package/templates/dotnet/AGENTS.md.hbs +38 -34
- package/templates/dotnet/rules/api-structure.md +15 -15
- package/templates/dotnet/rules/csharp-style.md +17 -17
- package/templates/dotnet/rules/dependency-injection.md +12 -12
- package/templates/dotnet/rules/error-handling-validation.md +15 -15
- package/templates/dotnet/skills/dotnet-controller/SKILL.md +16 -16
- package/templates/express/AGENTS.md.hbs +37 -33
- package/templates/express/rules/error-handling.md +18 -18
- package/templates/express/rules/express-style.md +19 -19
- package/templates/express/rules/router-controller.md +16 -16
- package/templates/express/skills/express-endpoint/SKILL.md +14 -14
- package/templates/fastapi/AGENTS.md.hbs +25 -3
- package/templates/fastapi/rules/api-testing.md +24 -0
- package/templates/fastapi/rules/database-async.md +26 -0
- package/templates/golang/AGENTS.md.hbs +42 -0
- package/templates/golang/rules/concurrency.md +71 -0
- package/templates/golang/rules/error-handling.md +42 -0
- package/templates/golang/rules/golang-style.md +24 -0
- package/templates/golang/rules/project-layout.md +39 -0
- package/templates/golang/skills/golang-db/SKILL.md +27 -0
- package/templates/golang/skills/golang-feature/SKILL.md +42 -0
- package/templates/nestjs/AGENTS.md.hbs +33 -29
- package/templates/nestjs/rules/module-architecture.md +14 -14
- package/templates/nestjs/rules/nestjs-style.md +12 -12
- package/templates/nestjs/rules/validation-errors.md +15 -15
- package/templates/nestjs/skills/nestjs-module/SKILL.md +15 -15
- package/templates/next-js/AGENTS.md.hbs +39 -35
- package/templates/next-js/rules/data-fetching-mutations.md +17 -17
- package/templates/next-js/rules/next-style.md +17 -17
- package/templates/next-js/rules/seo-metadata.md +18 -18
- package/templates/next-js/rules/server-client-components.md +17 -17
- package/templates/next-js/skills/next-feature/SKILL.md +16 -16
- package/templates/rust/AGENTS.md.hbs +41 -0
- package/templates/rust/rules/error-handling.md +36 -0
- package/templates/rust/rules/memory-concurrency.md +47 -0
- package/templates/rust/rules/project-layout.md +49 -0
- package/templates/rust/rules/rust-style.md +26 -0
- package/templates/rust/skills/rust-db/SKILL.md +27 -0
- package/templates/rust/skills/rust-feature/SKILL.md +34 -0
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Data Validation & Unified Exception Handling
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
## 🛡️
|
|
8
|
-
-
|
|
9
|
-
- **
|
|
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
|
-
//
|
|
12
|
+
// Inside main.ts
|
|
13
13
|
app.useGlobalPipes(
|
|
14
14
|
new ValidationPipe({
|
|
15
|
-
whitelist: true, //
|
|
16
|
-
forbidNonWhitelisted: true, //
|
|
17
|
-
transform: true, //
|
|
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
|
-
## 🚨
|
|
25
|
-
- **
|
|
26
|
-
- **
|
|
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("
|
|
32
|
+
throw new NotFoundException("The requested course does not exist.");
|
|
33
33
|
}
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
- **
|
|
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": "
|
|
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:
|
|
3
|
+
description: Automatically scaffold a complete NestJS Module including Controller, Service, DTO, and Entity according to standard conventions
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Follow this process to generate a new NestJS Module or extend an existing one.
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
- moduleName:
|
|
10
|
-
- targetPath:
|
|
11
|
-
- functionality:
|
|
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
|
-
|
|
14
|
-
1.
|
|
15
|
-
2.
|
|
16
|
-
3.
|
|
17
|
-
4.
|
|
18
|
-
5.
|
|
19
|
-
6.
|
|
20
|
-
7.
|
|
21
|
-
8.
|
|
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
|
-
## 🗺️
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
###
|
|
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
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
- **
|
|
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
|
-
#
|
|
1
|
+
# Data Fetching & Mutations
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
## 🔌
|
|
8
|
-
- **
|
|
9
|
-
- **
|
|
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
|
-
## 💾
|
|
14
|
-
- **
|
|
13
|
+
## 💾 Caching & Revalidation
|
|
14
|
+
- **No Raw Fetch:** Using raw `fetch()` without specifying caching or revalidation strategies is prohibited.
|
|
15
15
|
|
|
16
|
-
* **
|
|
16
|
+
* **Invalid (❌ Prohibited):**
|
|
17
17
|
```typescript
|
|
18
|
-
//
|
|
18
|
+
// Fetches static data indefinitely without any revalidation strategy
|
|
19
19
|
const res = await fetch('https://api.skillverse.vn/v1/courses');
|
|
20
20
|
```
|
|
21
|
-
* **
|
|
21
|
+
* **Valid (✔️ Recommended):**
|
|
22
22
|
```typescript
|
|
23
|
-
//
|
|
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
|
-
- **
|
|
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
|
-
## ⚡
|
|
33
|
-
- **
|
|
34
|
-
- **
|
|
35
|
-
-
|
|
36
|
-
-
|
|
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
|
-
#
|
|
1
|
+
# Next.js Naming Conventions & Coding Style
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
## 🏷️
|
|
7
|
+
## 🏷️ Naming Conventions
|
|
8
8
|
|
|
9
|
-
|
|
|
9
|
+
| Element | Naming Convention | Example |
|
|
10
10
|
| :--- | :--- | :--- |
|
|
11
|
-
| **
|
|
12
|
-
| **Route
|
|
13
|
-
| **
|
|
14
|
-
| **
|
|
15
|
-
| **Route Handlers** |
|
|
16
|
-
| **
|
|
17
|
-
| **Custom Hooks** | camelCase
|
|
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:**
|
|
23
|
-
- **CSS / Styles Imports:**
|
|
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
|
-
## 📁
|
|
28
|
-
-
|
|
29
|
-
-
|
|
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
|
-
-
|
|
32
|
+
- Expose the public API of each feature via a clean entrypoint file: `index.ts`.
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
#
|
|
1
|
+
# SEO Optimization & Semantic HTML
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
## 🔍
|
|
8
|
-
- **Metadata
|
|
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: '
|
|
12
|
+
description: 'Course management overview dashboard',
|
|
13
13
|
};
|
|
14
14
|
```
|
|
15
|
-
- **Metadata
|
|
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
|
-
## 🎨
|
|
37
|
-
- **
|
|
38
|
-
- `<header>`:
|
|
39
|
-
- `<nav>`:
|
|
40
|
-
- `<main>`:
|
|
41
|
-
- `<section>`:
|
|
42
|
-
- `<article>`:
|
|
43
|
-
- `<footer>`:
|
|
44
|
-
- **
|
|
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
|
-
## ⚡
|
|
49
|
-
- **
|
|
50
|
-
- **
|
|
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
|
-
|
|
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
|
-
- **
|
|
9
|
-
- **
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
- **
|
|
14
|
-
-
|
|
15
|
-
-
|
|
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
|
-
-
|
|
21
|
-
- **
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
- **
|
|
26
|
-
-
|
|
27
|
-
- *
|
|
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:
|
|
3
|
+
description: Generate or extend a new Next.js + TypeScript page or route handler with caching and metadata
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Follow this process to generate a new page, layout, or API route handler in Next.js.
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
- featureName:
|
|
10
|
-
- targetPath:
|
|
11
|
-
- userFlow:
|
|
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
|
-
|
|
14
|
-
1.
|
|
15
|
-
2.
|
|
16
|
-
3.
|
|
17
|
-
4.
|
|
18
|
-
5.
|
|
19
|
-
6.
|
|
20
|
-
7.
|
|
21
|
-
8.
|
|
22
|
-
9.
|
|
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.
|