agent-workflow-kit-cli 1.3.1 β 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/doctor.js +8 -1
- package/dist/cli/commands/init.js +6 -0
- package/dist/cli/index.js +2 -2
- package/dist/core/analyzer.js +216 -1
- package/dist/core/awos/intelligence.js +30 -6
- package/dist/core/detector.js +54 -4
- 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 +53 -0
- package/templates/dotnet/rules/api-structure.md +43 -0
- package/templates/dotnet/rules/csharp-style.md +33 -0
- package/templates/dotnet/rules/dependency-injection.md +54 -0
- package/templates/dotnet/rules/error-handling-validation.md +86 -0
- package/templates/dotnet/skills/dotnet-controller/SKILL.md +24 -0
- package/templates/express/AGENTS.md.hbs +41 -0
- package/templates/express/rules/error-handling.md +88 -0
- package/templates/express/rules/express-style.md +39 -0
- package/templates/express/rules/router-controller.md +27 -0
- package/templates/express/skills/express-endpoint/SKILL.md +24 -0
- 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 +38 -0
- package/templates/nestjs/rules/module-architecture.md +35 -0
- package/templates/nestjs/rules/nestjs-style.md +41 -0
- package/templates/nestjs/rules/validation-errors.md +46 -0
- package/templates/nestjs/skills/nestjs-module/SKILL.md +25 -0
- package/templates/next-js/AGENTS.md.hbs +41 -0
- package/templates/next-js/rules/data-fetching-mutations.md +36 -0
- package/templates/next-js/rules/next-style.md +32 -0
- package/templates/next-js/rules/seo-metadata.md +50 -0
- package/templates/next-js/rules/server-client-components.md +27 -0
- package/templates/next-js/skills/next-feature/SKILL.md +26 -0
- package/templates/react-ts/AGENTS.md.hbs +109 -32
- package/templates/react-ts/rules/data-fetching.md +45 -0
- package/templates/react-ts/rules/forms-validation.md +55 -0
- package/templates/react-ts/rules/premium-ui.md +45 -0
- package/templates/react-ts/rules/react-style.md +38 -26
- package/templates/react-ts/rules/routing-splitting.md +21 -0
- package/templates/react-ts/rules/seo-accessibility.md +34 -0
- package/templates/react-ts/skills/react-feature/SKILL.md +5 -5
- 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
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Golang Project Architecture & Layout
|
|
2
|
+
|
|
3
|
+
This document defines the Standard Go Project Layout and Clean Architecture conventions.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ποΈ Standard Directory Structure
|
|
8
|
+
Adhere to the following layout guidelines:
|
|
9
|
+
- **/cmd:** Contains only the entrypoints of the application (e.g., `cmd/api/main.go`). Code here must only parse configs, initialize the DI container, and start the server. Do not write business logic here.
|
|
10
|
+
- **/internal:** Contains all core application code. The Go compiler enforces that external packages cannot import code from this directory. Write 100% of business logic here.
|
|
11
|
+
- **/pkg:** Contains standalone utility libraries that can be shared with other projects (e.g., `pkg/logger`, `pkg/crypto`). Code in `/pkg` must never import packages from `/internal`.
|
|
12
|
+
- **/api:** Contains API contract definitions (OpenAPI/Swagger schemas, gRPC proto files).
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## ποΈ Clean Architecture Layers
|
|
17
|
+
Organize code inside `/internal/app` or `/internal/<domain>` into 3 distinct layers:
|
|
18
|
+
1. **Entities (Domain Models):** Pure Go structs and core business rules. They must be free of external dependencies.
|
|
19
|
+
2. **Use Cases (Services):** Coordinates business logic. Interacts only with interfaces representing external components.
|
|
20
|
+
3. **Adapters (Controllers / Repositories):** Manages external communications (e.g., database operations using GORM, API routes using Fiber/Echo, gRPC handlers).
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## π Manual Dependency Injection (DI)
|
|
25
|
+
- **Constructor Injection:** Pass dependencies to structs (UseCases or Repositories) via `New[StructName]` constructors. Dependencies must be passed as interfaces.
|
|
26
|
+
- **Example:**
|
|
27
|
+
```go
|
|
28
|
+
type UserRepository interface {
|
|
29
|
+
GetByID(ctx context.Context, id int64) (*domain.User, error)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type UserUseCase struct {
|
|
33
|
+
repo UserRepository // Access via interface
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
func NewUserUseCase(r UserRepository) *UserUseCase {
|
|
37
|
+
return &UserUseCase{repo: r}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
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
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
### ποΈ Strict Development Rules
|
|
26
|
+
|
|
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
|
+
|
|
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
|
+
|
|
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.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Modular Architecture & Dependency Injection (DI)
|
|
2
|
+
|
|
3
|
+
This document defines module boundaries, code isolation (encapsulation), and dependency injection standards in NestJS.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
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
|
+
|
|
11
|
+
* **Invalid (β Prohibited):**
|
|
12
|
+
```typescript
|
|
13
|
+
@Injectable()
|
|
14
|
+
export class AuthService {
|
|
15
|
+
@Inject(UsersService)
|
|
16
|
+
private readonly usersService: UsersService;
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
* **Valid (βοΈ Recommended):**
|
|
20
|
+
```typescript
|
|
21
|
+
@Injectable()
|
|
22
|
+
export class AuthService {
|
|
23
|
+
constructor(private readonly usersService: UsersService) {}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
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).
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# NestJS Naming Conventions & Coding Style
|
|
2
|
+
|
|
3
|
+
This document outlines standard guidelines for TypeScript coding styles, filename notations, and class naming conventions in NestJS.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## π·οΈ Naming Conventions
|
|
8
|
+
|
|
9
|
+
### Filename Notation (Dot Notation)
|
|
10
|
+
All filenames in NestJS must strictly comply with the following format: `<name>.<type>.ts`.
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
# Module directories should use consistent singular or plural names (e.g., auth, users, products)
|
|
14
|
+
src/users/
|
|
15
|
+
βββ users.module.ts
|
|
16
|
+
βββ users.controller.ts
|
|
17
|
+
βββ users.service.ts
|
|
18
|
+
βββ dto/
|
|
19
|
+
β βββ create-user-request.dto.ts
|
|
20
|
+
β βββ update-user-response.dto.ts
|
|
21
|
+
βββ entities/
|
|
22
|
+
β βββ user.entity.ts
|
|
23
|
+
βββ guards/
|
|
24
|
+
β βββ roles.guard.ts
|
|
25
|
+
βββ interceptors/
|
|
26
|
+
βββ logging.interceptor.ts
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Class Naming
|
|
30
|
+
Class names must use `PascalCase` and end with the specific component suffix representing their role:
|
|
31
|
+
- **Controller:** `src/auth/auth.controller.ts` $\rightarrow$ `export class AuthController {}`
|
|
32
|
+
- **Service:** `src/auth/auth.service.ts` $\rightarrow$ `export class AuthService {}`
|
|
33
|
+
- **Module:** `src/auth/auth.module.ts` $\rightarrow$ `export class AuthModule {}`
|
|
34
|
+
- **DTO:** `src/auth/dto/login.dto.ts` $\rightarrow$ `export class LoginRequestDto {}`
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
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.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Data Validation & Unified Exception Handling
|
|
2
|
+
|
|
3
|
+
This document specifies conventions for using Class Validator, configuring the global ValidationPipe, and handling errors centrally via Exception Filters in NestJS.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
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
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
// Inside main.ts
|
|
13
|
+
app.useGlobalPipes(
|
|
14
|
+
new ValidationPipe({
|
|
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
|
+
}),
|
|
19
|
+
);
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
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
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
try {
|
|
30
|
+
return await this.courseRepo.findOneOrFail(id);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
throw new NotFoundException("The requested course does not exist.");
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
- **Global Exception Filter:** Implement a global Exception Filter to structure JSON error responses uniformly. The standardized error payload must follow this structure:
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"success": false,
|
|
41
|
+
"statusCode": 404,
|
|
42
|
+
"timestamp": "2026-06-13T06:48:24.000Z",
|
|
43
|
+
"path": "/api/v1/courses/999",
|
|
44
|
+
"message": "The requested course does not exist."
|
|
45
|
+
}
|
|
46
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: nestjs-module
|
|
3
|
+
description: Automatically scaffold a complete NestJS Module including Controller, Service, DTO, and Entity according to standard conventions
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Follow this process to generate a new NestJS Module or extend an existing one.
|
|
7
|
+
|
|
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
|
+
|
|
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
|
+
- `{{runCommand}} lint`
|
|
23
|
+
- `{{runCommand}} typecheck`
|
|
24
|
+
- `{{runCommand}} test`
|
|
25
|
+
- `{{runCommand}} build`
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
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
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
### ποΈ Strict Development Rules
|
|
27
|
+
|
|
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
|
+
|
|
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
|
+
|
|
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.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Data Fetching & Mutations
|
|
2
|
+
|
|
3
|
+
This document defines standard conventions for calling APIs, managing caching, and performing data mutations using Next.js Server Actions.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
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
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## πΎ Caching & Revalidation
|
|
14
|
+
- **No Raw Fetch:** Using raw `fetch()` without specifying caching or revalidation strategies is prohibited.
|
|
15
|
+
|
|
16
|
+
* **Invalid (β Prohibited):**
|
|
17
|
+
```typescript
|
|
18
|
+
// Fetches static data indefinitely without any revalidation strategy
|
|
19
|
+
const res = await fetch('https://api.skillverse.vn/v1/courses');
|
|
20
|
+
```
|
|
21
|
+
* **Valid (βοΈ Recommended):**
|
|
22
|
+
```typescript
|
|
23
|
+
// Configure ISR (Incremental Static Regeneration) with an explicit cache tag
|
|
24
|
+
const res = await fetch('https://api.skillverse.vn/v1/courses', {
|
|
25
|
+
next: { revalidate: 3600, tags: ['courses'] }
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
- **Cache Refreshing:** Call `revalidatePath` or `revalidateTag` inside Server Actions to purge stale cache entries and force Next.js to pull fresh data.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
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.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Next.js Naming Conventions & Coding Style
|
|
2
|
+
|
|
3
|
+
This document defines conventions for directory structures, naming patterns, imports, and feature organization inside Next.js App Router projects.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## π·οΈ Naming Conventions
|
|
8
|
+
|
|
9
|
+
| Element | Naming Convention | Example |
|
|
10
|
+
| :--- | :--- | :--- |
|
|
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
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## π¦ Imports & Aliasing
|
|
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
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
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
|
+
- `src/features/billing/components/BillingForm.tsx`
|
|
31
|
+
- `src/features/billing/hooks/useBilling.ts`
|
|
32
|
+
- Expose the public API of each feature via a clean entrypoint file: `index.ts`.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# SEO Optimization & Semantic HTML
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
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
|
+
```typescript
|
|
10
|
+
export const metadata = {
|
|
11
|
+
title: 'Dashboard | Skillverse Platform',
|
|
12
|
+
description: 'Course management overview dashboard',
|
|
13
|
+
};
|
|
14
|
+
```
|
|
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
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { Metadata } from 'next';
|
|
19
|
+
|
|
20
|
+
type Props = { params: Promise<{ id: string }> };
|
|
21
|
+
|
|
22
|
+
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
|
23
|
+
const id = (await params).id;
|
|
24
|
+
const course = await getCourseDetail(id);
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
title: `${course.title} | Skillverse Platform`,
|
|
28
|
+
description: course.shortDescription,
|
|
29
|
+
openGraph: { images: [course.thumbnailUrl] }
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
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
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
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.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# React Server Components (RSC) vs React Client Components (RCC)
|
|
2
|
+
|
|
3
|
+
This document establishes architectural boundaries and classification rules for components in Next.js App Router projects.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ποΈ React Server Components (RSC)
|
|
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
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## π» React Client Components (RCC)
|
|
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.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: next-feature
|
|
3
|
+
description: Generate or extend a new Next.js + TypeScript page or route handler with caching and metadata
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Follow this process to generate a new page, layout, or API route handler in Next.js.
|
|
7
|
+
|
|
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
|
+
|
|
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
|
+
- `{{runCommand}} lint`
|
|
24
|
+
- `{{runCommand}} typecheck`
|
|
25
|
+
- `{{runCommand}} test`
|
|
26
|
+
- `{{runCommand}} build`
|
|
@@ -1,47 +1,124 @@
|
|
|
1
1
|
## React + TypeScript Guidelines
|
|
2
2
|
|
|
3
|
-
###
|
|
4
|
-
|
|
3
|
+
### π End-to-End Agent Development Lifecycle
|
|
4
|
+
AI Agents must execute all React + TypeScript tasks following this structured 5-stage lifecycle:
|
|
5
|
+
1. **Design & Code:** Implement components and logic following the guidelines below. Keep logic inside Custom Hooks.
|
|
6
|
+
2. **Comprehensive Testing:** Write component tests using React Testing Library and hook tests for complex behavior.
|
|
7
|
+
3. **Code Quality & Validation:** Perform self-review and execute dynamic linter, type checks, and tests:
|
|
8
|
+
- Linting check: `{{runCommand}} lint`
|
|
9
|
+
- Type checking: `{{runCommand}} typecheck`
|
|
10
|
+
- Unit tests: `{{runCommand}} test` (or `{{runCommand}} test -- --run` in CI/CD)
|
|
11
|
+
- Production build: `{{runCommand}} build`
|
|
12
|
+
4. **Dependency Management:** Install new packages using `{{packageManager}} add [package_name]` (or `npm install [package_name]` if using npm). Never manually modify the lock file `{{lockFile}}`.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
### ποΈ Architecture & Feature Conventions
|
|
17
|
+
Use a strict **feature-first** modular packaging layout. Keep routing modules thin, and place feature UI, custom hooks, services, types, and tests together within the feature module:
|
|
5
18
|
|
|
6
19
|
```text
|
|
7
20
|
src/
|
|
8
|
-
app/ # App shell, router, providers
|
|
21
|
+
app/ # App shell, router, context providers
|
|
9
22
|
features/
|
|
10
23
|
billing/
|
|
11
|
-
components/
|
|
24
|
+
components/ # Feature-specific components
|
|
12
25
|
BillingPanel.tsx
|
|
13
|
-
hooks/
|
|
26
|
+
hooks/ # Feature-specific custom hooks (queries, state)
|
|
14
27
|
useBilling.ts
|
|
15
|
-
services/
|
|
28
|
+
services/ # API clients and data transformers
|
|
16
29
|
billingClient.ts
|
|
17
|
-
types
|
|
18
|
-
|
|
19
|
-
|
|
30
|
+
types/ # Feature type definitions
|
|
31
|
+
billing.ts
|
|
32
|
+
__tests__/ # Component and hook unit tests
|
|
33
|
+
BillingPanel.test.tsx
|
|
34
|
+
index.ts # Public API for this feature
|
|
35
|
+
shared/ # Core shared assets, hooks, components, utils
|
|
20
36
|
components/
|
|
21
37
|
hooks/
|
|
22
38
|
utils/
|
|
23
39
|
```
|
|
24
40
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
### π¨ Aesthetics, Styling & Premium UI
|
|
44
|
+
The UI must feel premium, modern, and cohesive.
|
|
45
|
+
- **Strict Tailwind CSS usage**: Never write inline custom CSS. Build the interface entirely using Tailwind Utility Classes.
|
|
46
|
+
- **Dynamic Classes helper**: Never use string interpolation to join dynamic classNames. Always use the `cn()` helper (combining `clsx` and `tailwind-merge`):
|
|
47
|
+
```typescript
|
|
48
|
+
// src/utils/cn.ts
|
|
49
|
+
import { ClassValue, clsx } from "clsx";
|
|
50
|
+
import { twMerge } from "tailwind-merge";
|
|
51
|
+
|
|
52
|
+
export function cn(...inputs: ClassValue[]) {
|
|
53
|
+
return twMerge(clsx(inputs));
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
Usage:
|
|
57
|
+
`className={cn("px-4 py-2 text-white transition-all", isActive ? "bg-blue-500" : "bg-gray-500", customClass)}`
|
|
58
|
+
- **Mobile-First Design**: Design layouts for mobile by default. Use breakpoints (`sm:`, `md:`, `lg:`, `xl:`) only to add or modify responsive styles as viewport size increases.
|
|
59
|
+
- **Micro-animations & Motion**: Use `framer-motion` (or equivalent core transition library) for physical state changes:
|
|
60
|
+
- Transition duration should be short (between `0.2s` and `0.3s`).
|
|
61
|
+
- Use natural easing curves (`easeOut`, `easeInOut`) or spring physics for buttons/modals.
|
|
62
|
+
- Wrap conditional components in `<AnimatePresence>` to execute smooth exit animations.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
### π Asynchronous Server-State & API Call Conventions
|
|
67
|
+
- **No raw useEffect Fetching**: Never fetch data using raw `useEffect` blocks.
|
|
68
|
+
- **Centralized API Client**: Route all outgoing requests through a unified client instance (e.g. `src/lib/api-client.ts`) that manages baseURL, interceptors, auth token inclusion, and global error mappings.
|
|
69
|
+
- **Asynchronous Server-State**: Manage all server state using **TanStack Query (React Query)** or **SWR**.
|
|
70
|
+
- **Separation of Concerns**: UI components must only call custom query hooks and render UI based on three states (`isLoading`, `isError`, and `data`). All fetching, caching, and mutation logic must be kept inside custom hooks:
|
|
71
|
+
```typescript
|
|
72
|
+
// src/features/roadmap/api/use-roadmap.ts
|
|
73
|
+
import { useQuery } from "@tanstack/react-query";
|
|
74
|
+
import { apiClient } from "@/lib/api-client";
|
|
75
|
+
|
|
76
|
+
export const useRoadmap = (roadmapId: string) => {
|
|
77
|
+
return useQuery({
|
|
78
|
+
queryKey: ["roadmaps", roadmapId],
|
|
79
|
+
queryFn: async () => {
|
|
80
|
+
const response = await apiClient.get(`/roadmaps/${roadmapId}`);
|
|
81
|
+
return response.data;
|
|
82
|
+
},
|
|
83
|
+
staleTime: 5 * 60 * 1000,
|
|
84
|
+
gcTime: 10 * 60 * 1000,
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
### π Forms & Schema Validation
|
|
92
|
+
Forms must remain performant and prevent rendering bottleneck.
|
|
93
|
+
- **React Hook Form**: Manage form states with React Hook Form to isolate re-rendering and ensure smooth typing.
|
|
94
|
+
- **Controller integration**: For complex third-party elements (Rich Text Editors, selectors, etc.), wrap them in the RHF `<Controller>` component.
|
|
95
|
+
- **Schema-Driven Validation**: Avoid raw if/else statements for input validation. Use **Zod** to declare data schemas and automatically resolve validator rules:
|
|
96
|
+
```typescript
|
|
97
|
+
import { useForm } from "react-hook-form";
|
|
98
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
99
|
+
import * as z from "zod";
|
|
100
|
+
|
|
101
|
+
const loginSchema = z.object({
|
|
102
|
+
email: z.string().min(1, "Email cannot be empty").email("Invalid email format"),
|
|
103
|
+
password: z.string().min(8, "Password must contain at least 8 characters"),
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
### β‘ Routing & Code Splitting
|
|
110
|
+
Optimizing bundle loading performance is mandatory.
|
|
111
|
+
- **Code Splitting**: Do not statically import Page Components. Use `React.lazy()` to segment routes into separate chunks loaded only when the route is visited.
|
|
112
|
+
- **Premium Loading**: Wrap all lazy-loaded route elements inside a `<Suspense>` boundary containing a premium Shimmer Skeleton loader or spinner.
|
|
113
|
+
- **Centralized Data Routers**: Configure routes using `createBrowserRouter` (React Router v6+) instead of JSX tags.
|
|
114
|
+
- **Loaders & Actions**: Fetch data parallel to route transitions using router Loaders, and manage data mutations via router Actions.
|
|
115
|
+
- **Route Error Boundaries**: Specify an `errorElement` on all primary route branches to isolate crashes and show a dedicated recovery panel instead of freezing the entire application.
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
### π SEO & Accessibility (a11y)
|
|
120
|
+
- **Dynamic SEO Metadata**: Update document metadata (`title`, `description`, Open Graph tags) on route changes using `react-helmet-async`.
|
|
121
|
+
- **Semantic HTML5 Structure**: Restructure elements using semantic tags: `<header>`, `<nav>`, `<main>`, `<section>`, `<article>`, `<footer>`. Ensure heading tags (`<h1>` to `<h6>`) follow logical hierarchy.
|
|
122
|
+
- **Accessible Images**: All `<img>` tags must possess an `alt` attribute. Provide descriptive alt text for informative images; write `alt=""` for purely decorative images so screen readers skip them.
|
|
123
|
+
- **Icon-Only Controls**: Buttons or links containing only SVG icons (e.g. close buttons, like buttons) must have an explicit `aria-label` or `aria-labelledby` attribute.
|
|
124
|
+
- **Visual Keyboard Focus**: Do not disable the browser focus outline without adding a custom indicator. Interactable elements must display a distinct ring when navigated via keyboard (`:focus-visible`, e.g. `focus-visible:ring-2 focus-visible:ring-primary focus-visible:outline-none`).
|