返回 AiToEarn
nestjs-layering.yaml
根目录 / project / aitoearn-backend / .claude / instincts / nestjs-layering.yaml
1 ---
2 id: aitoearn-nestjs-layering
3 trigger: "when creating or modifying NestJS code"
4 confidence: 0.95
5 domain: architecture
6 source: local-repo-analysis
7 ---
8
9 # NestJS Layered Architecture
10
11 ## Action
12 Follow strict separation of concerns:
13
14 1. **Controller** - Only routing, parameter binding, VO transformation
15 2. **Service** - Business logic, permission filtering, entity mapping
16 3. **Repository** - Data access only, no business logic
17
18 ## Rules
19 - Controller MUST NOT contain business logic
20 - Controller MUST NOT access database directly
21 - Controller MUST return VO (not entity)
22 - Service handles permission filtering via query conditions
23 - Repository MUST NOT contain permission checks
24 - Repository MUST NOT perform cross-model operations
25
26 ## File Structure
27 ```
28 src/
29 ├── module-name/
30 │ ├── module-name.controller.ts
31 │ ├── module-name.service.ts
32 │ ├── module-name.module.ts
33 │ ├── dto/
34 │ │ ├── module-name.dto.ts
35 │ │ └── module-name.vo.ts
36 │ └── (repository in libs/)
37 ```
38
39 ## Evidence
40 - Consistent pattern across all apps
41 - Enforced in CLAUDE.md development standards
42
42 lines YAML