后端嵌套

工程开发 社区

技能解读

当前原文的自动摘译,尚未人工审校。

惯例

application/ DTO 中每个文件一个用例,在presentation/ 中带有类验证器装饰器 用于在infrastructure/ 模块范围提供程序中进行数据访问的存储库模式;仅导出需要的内容

测试

堆栈:Vitest(首选)或 Jest 具有模拟依赖项的单元测试用例源旁边的测试文件:*.spec.ts 所有测试均采用英文命名:“当 Y 时应该执行 X”

错误处理

使用 NestJS 内置异常(BadRequestException、NotFoundException 等) 自定义异常扩展 HttpException 未处理错误的全局异常过滤器

数据库

使用查询生成器或存储库模式 始终使用事务进行多表写入 为频繁查询的列添加索引 在写入查询之前使用数据库 MCP 检查架构

预提交清单

构建通行证? (pnpm build) Lint 通过了吗? (pnpm lint) 测试通过了吗? (pnpm test) DTO 有适当的验证吗?错误案例处理了吗?

流狐档案 运行与权限由流狐静态检查推断,不代表作者声明或实际测试结果。
领域
工程开发
作者声明的智能体
未找到明确声明;不据此推断已兼容或已测试
静态检查
88 / 100 · 启发式扫描,不代表运行安全
运行环境证据
未执行;当前没有隔离运行测试证据
作者 / 版本 / 许可证
@arvoreeducacao · 未声明许可证
上下文用量评级
低消耗
接入复杂程度
即装即用
是否需要外部接口密钥
不需要
兼容的系统
未声明(默认跨平台)
运行环境要求
未检出明确要求
检测到的文件与系统行为
  • 只读
网络行为
仅限本地
安装命令数
无(仅作为资料)

需要注意: 未声明工具权限范围;实际权限由运行环境决定。

作者说明文件(原文) SKILL.md

# NestJS Backend Development

## When to Use This Skill

Use when developing backend code in a NestJS project with TypeScript.

## Recommended Project Structure

```
src/
├── core/
│   ├── config/              # Configuration (env validation)
│   ├── database/            # Database connections, migrations
│   ├── guards/              # Auth guards
│   ├── interceptors/        # Request/response interceptors
│   ├── filters/             # Exception filters
│   └── decorators/          # Custom decorators
├── modules/
│   └── <domain>/
│       ├── application/     # Use cases / services
│       ├── domain/          # Entities, value objects, interfaces
│       ├── infrastructure/  # Repositories, external services
│       ├── presentation/    # Controllers, DTOs, validators
│       └── <domain>.module.ts
├── shared/
│   ├── utils/
│   ├── types/
│   └── constants/
└── main.ts
```

## Conventions

- One use case per file in `application/`
- DTOs with class-validator decorators in `presentation/`
- Repository pattern for data access in `infrastructure/`
- Module-scoped providers; export only what's needed

## Testing

- Stack: Vitest (preferred) or Jest
- Unit test use cases with mocked dependencies
- Test file next to source: `*.spec.ts`
- All tests in English
- Naming: "should do X when Y"

## Commands

```bash
pnpm dev          # Development with hot reload
pnpm build        # Production build
pnpm lint         # ESLint
pnpm test         # Run tests
pnpm test:cov     # Coverage report
```

## Error Handling

- Use NestJS built-in exceptions (BadRequestException, NotFoundException, etc.)
- Custom exceptions extend HttpException
- Global exception filter for unhandled errors

## Database

- Use query builder or repository pattern
- Always use transactions for multi-table writes
- Add indexes for frequently queried columns
- Use database MCPs to inspect schema before writing queries

## Pre-commit Checklist

- Build passes? (`pnpm build`)
- Lint passes? (`pnpm lint`)
- Tests pass? (`pnpm test`)
- DTOs have proper validation?
- Error cases handled?

讨论

基于 GitHub Discussions。登录 GitHub 即可参与讨论、点赞、订阅更新。