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.
- package/dist/cli/commands/add.js +3 -1
- 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/dotnet/AGENTS.md.hbs +34 -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 +33 -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/golang/AGENTS.md.hbs +36 -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/nestjs/AGENTS.md.hbs +29 -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 +32 -32
- 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 +34 -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
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
## 🗺️
|
|
2
|
-
|
|
3
|
-
### 🔄
|
|
4
|
-
|
|
5
|
-
1. **
|
|
6
|
-
2. **
|
|
7
|
-
3. **
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
4. **
|
|
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
|
-
### 🏗️
|
|
17
|
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
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
|
-
### 🏛️
|
|
25
|
+
### 🏛️ Strict Development Rules
|
|
26
26
|
|
|
27
|
-
#### 1.
|
|
28
|
-
- **
|
|
29
|
-
- **
|
|
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.
|
|
32
|
-
-
|
|
33
|
-
- **
|
|
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.
|
|
36
|
-
- **
|
|
37
|
-
- **
|
|
38
|
-
- **
|
|
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
|
-
#
|
|
1
|
+
# Modular Architecture & Dependency Injection (DI)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This document defines module boundaries, code isolation (encapsulation), and dependency injection standards in NestJS.
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
## 💉
|
|
8
|
-
- **
|
|
9
|
-
- **
|
|
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
|
-
* **
|
|
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
|
-
* **
|
|
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
|
-
## 🏗️
|
|
30
|
-
- **
|
|
31
|
-
- **
|
|
32
|
-
1.
|
|
33
|
-
2.
|
|
34
|
-
*
|
|
35
|
-
- **
|
|
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
|
-
#
|
|
1
|
+
# NestJS Naming Conventions & Coding Style
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
## 🏷️
|
|
7
|
+
## 🏷️ Naming Conventions
|
|
8
8
|
|
|
9
|
-
###
|
|
10
|
-
|
|
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
|
-
#
|
|
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
|
-
###
|
|
30
|
-
|
|
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 &
|
|
39
|
-
- **
|
|
40
|
-
- **
|
|
41
|
-
- **
|
|
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
|
-
#
|
|
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,41 @@
|
|
|
1
|
-
## 🗺️
|
|
2
|
-
|
|
3
|
-
### 🔄
|
|
4
|
-
|
|
5
|
-
1. **
|
|
6
|
-
2. **
|
|
7
|
-
3. **
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
4. **
|
|
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
|
-
### 🏗️
|
|
17
|
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
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
|
-
### 🏛️
|
|
26
|
+
### 🏛️ Strict Development Rules
|
|
27
27
|
|
|
28
|
-
#### 1.
|
|
29
|
-
- **
|
|
30
|
-
- **
|
|
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
|
|
33
|
-
- **
|
|
34
|
-
- **
|
|
35
|
-
-
|
|
36
|
-
- **
|
|
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.
|
|
39
|
-
- **
|
|
40
|
-
- **
|
|
41
|
-
- **
|
|
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
|
-
#
|
|
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.
|