Nestjs 上下文验证
- 作者仓库星标 0
- 作者仓库 skills-registry
NestJS-specific implementation of DDD + Hexagonal + CQRS patterns. For the underlying theory (aggregates, domain events, architecture layers), see engineering-toolkit:engineering-foundations. This skill covers the NestJS-specific HOW. Before applying any topic, read its reference file in reference/.
Topics
| Topic | When to Use | Reference |
|---|---|---|
| Error Handling | Exception filters, domain error -> HTTP mapping | reference/error-handling.md |
| Config | Environment variables, config modules, validation | reference/config.md |
| Auth | Guards, JWT strategies, RBAC | reference/auth.md |
| API Design | Endpoints, DTOs, Swagger, pagination | reference/api-design.md |
| Code Structure | Where to place code, resolving circular imports | reference/code-structure.md |
| Logging | Structured logging with Pino, correlation IDs | reference/logging.md |
| Domain Model (NestJS) | @nestjs/cqrs AggregateRoot, EventPublisher | reference/nestjs-domain-model.md |
| TypeORM Migrations | Creating database migrations | reference/typeorm-migrations.md |
| TypeORM Queries | Writing queries and transactions | reference/typeorm-queries.md |
Architecture Overview
+------------------------------------------------------------------+
| PRESENTATION LAYER |
| apps/ (HTTP Controllers, DTOs, Request/Response handling) |
+------------------------------------------------------------------+
| APPLICATION LAYER |
| modules/ (Commands, Queries, Handlers, Events) |
+------------------------------------------------------------------+
| DOMAIN LAYER |
| libs/common/domain/ (Entities, Value Objects, Enums) |
+------------------------------------------------------------------+
| INFRASTRUCTURE LAYER |
| libs/ (Repositories, External APIs, Database, Messaging) |
+------------------------------------------------------------------+
Quick Decision Guide
Writing an endpoint?
-> reference/api-design.md + reference/code-structure.md
Handling errors?
-> reference/error-handling.md
Setting up config/env?
-> reference/config.md
Adding authentication?
-> reference/auth.md
Writing a database query?
-> reference/typeorm-queries.md
Creating a migration?
-> reference/typeorm-migrations.md
Implementing a domain model with events?
-> reference/nestjs-domain-model.md
Adding logging?
-> reference/logging.md
Gotchas
Claude-specific failure modes in NestJS codebases:
- Throwing
HttpExceptionfrom domain/application layer — Claude defaults to HTTP exceptions everywhere. Domain layer must throw domain-specific exceptions; the exception filter maps them to HTTP responses. - Using
process.env.Xinstead of ConfigService — Claude reaches forprocess.envout of habit. Always injectConfigServiceand use.get(). - Putting auth logic in services — Claude tends to add
if (!user.isAdmin)checks inside service methods. Auth belongs in guards; services receive already-validated context. - Returning entities directly from controllers — Claude skips DTO mapping when "it's the same shape anyway." Always use response DTOs, even if they mirror the entity — the contract must be explicit.
- Circular imports between modules — Claude creates circular dependencies when wiring cross-module services. Use
forwardRef()as last resort; prefer restructuring. - Logging message-first instead of context-first — Claude writes
logger.log('User created', { userId })instead oflogger.log({ userId }, 'User created'). Pino expects context object first. - Raw SQL when QueryBuilder suffices — Claude jumps to raw SQL for anything beyond
.find(). Follow the hierarchy: built-in methods > QueryBuilder > raw SQL. - Forgetting to release QueryRunner — Must always release in a
finallyblock. Claude sometimes putsrelease()only in the happy path. - Importing from other module's internal paths — Use the module's public API (barrel exports), not deep
../other-module/internal/fileimports.
Key Rules (Always Apply)
- Domain layer MUST NOT import HTTP exceptions — use domain exceptions, map in filters
- Never access
process.envdirectly — use ConfigService - Auth in guards, not in services — domain receives validated user context
- DTOs for all input/output — never expose entities directly
- Relative imports within modules — path aliases across modules
- Context-first logging — structured fields before message string
- Query hierarchy — built-in methods first, query builder second, raw SQL last resort
- Release query runners — always in a
finallyblock
<!-- tomevault:4.0:skill_md:2026-05-22 -->Source: anpham1925/claude-marketplace — distributed by TomeVault.
- 流狐分类
- 设计与多媒体
- 作者声明 Agent
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 88 / 100 · 启发式扫描,不代表运行安全
- 作者 / 版本 / 许可
- @tomevault-io · 未声明 license
- 流狐 Token 估算
- 低消耗
- 流狐接入估算
- 即装即用
- 是否需要外部 API Key
- 未发现要求
- 检测到的系统要求
- 未声明
- 底层运行要求
- 未声明
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- 读取环境变量
- 检测到的网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
作者没有在当前 SKILL.md 中定义固定输出样例。 Topic · When to Use · Reference Error Handling · Exception filters, domain error -> HTTP mapping · reference/error-handling.md Config · Environment variables, config modules, validation · reference/config.md
Architecture Overview
Quick Decision Guide
Claude-specific failure modes in NestJS codebases: Throwing HttpException from domain/application layer — Claude defaults to HTTP exceptions everywhere. Domain layer must throw domain-specific exceptions; the exception filter maps them to HTTP responses.
Domain layer MUST NOT import HTTP exceptions — use domain exceptions, map in filters Never access process.env directly — use ConfigService Auth in guards, not in services — domain receives validated user context
NestJS-specific implementation of DDD + Hexagonal + CQRS patterns. For the underlying theory (aggregates, domain events, architecture layers), see `engineering-toolkit:engineering-foundations`. This skill covers the NestJS-specific HOW. Before applying any topic, read its reference file in `reference/`.
## Topics
| Topic | When to Use | Reference |
|---|---|---|
| **Error Handling** | Exception filters, domain error -> HTTP mapping | `reference/error-handling.md` |
| **Config** | Environment variables, config modules, validation | `reference/config.md` |
| **Auth** | Guards, JWT strategies, RBAC | `reference/auth.md` |
| **API Design** | Endpoints, DTOs, Swagger, pagination | `reference/api-design.md` |
| **Code Structure** | Where to place code, resolving circular imports | `reference/code-structure.md` |
| **Logging** | Structured logging with Pino, correlation IDs | `reference/logging.md` |
| **Domain Model (NestJS)** | @nestjs/cqrs AggregateRoot, EventPublisher | `reference/nestjs-domain-model.md` |
| **TypeORM Migrations** | Creating database migrations | `reference/typeorm-migrations.md` |
| **TypeORM Queries** | Writing queries and transactions | `reference/typeorm-queries.md` |
## Architecture Overview
```
+------------------------------------------------------------------+
| PRESENTATION LAYER |
| apps/ (HTTP Controllers, DTOs, Request/Response handling) |
+------------------------------------------------------------------+
| APPLICATION LAYER |
| modules/ (Commands, Queries, Handlers, Events) |
+------------------------------------------------------------------+
| DOMAIN LAYER |
… 作者原文负责流程事实;流狐只索引当前章节、要点、文件与命令。
章节 -> Topics → Architecture Overview → Quick Decision Guide → Gotchas → Key Rules (Always Apply)
要点 -> Error Handling · Config · Auth · API Design · Code Structure · Logging · Domain Model (NestJS) · TypeORM Migrations
文件/命令 -> engineering-toolkit:engineering-foundations · reference/ · reference/error-handling.md · reference/config.md · reference/auth.md · reference/api-design.md · reference/code-structure.md · reference/logging.md
内容 SHA-256 -> 58701f688d03
原文结构
适用与边界
原文中的明确线索
engineering-toolkit:engineering-foundations、reference/、reference/error-handling.md、reference/config.md、reference/auth.md、reference/api-design.md、reference/code-structure.md、reference/logging.md