NestJS Project Structure Validator
This skill enforces NestJS best practices with a focus on modular architecture, Prisma database integration, comprehensive testing coverage, and automated quality checks.
Project Organization
Ensure the following directory structure exists:
`src/` - Main source code directory`src/modules/` - Feature modules following NestJS conventions`test/` - End-to-end and integration tests`prisma/` - Database schema and migrationsRequired Configuration Files
Verify these files exist at the project root:
`.env` - Environment variables for development`.env.test` - Test environment configuration`package.json` - Node.js dependencies and scripts`tsconfig.json` - TypeScript compiler configuration`nest-cli.json` - NestJS CLI settingsModule Structure Standards
Each module in `src/modules/` must contain:
1. **Controller** (`*.controller.ts`) - HTTP route handlers
2. **Service** (`*.service.ts`) - Business logic
3. **Module** (`*.module.ts`) - NestJS module definition
Additionally enforce these patterns:
**DTOs** (`**/*.dto.ts`) - Data transfer objects for validation**Entities** (`**/*.entity.ts`) - Domain models**Guards** (`**/*.guard.ts`) - Route protection and authorizationTesting Requirements
Test File Patterns
Identify test files using these patterns:
Unit tests: `**/*.spec.ts`Integration tests: `**/*.test.ts`E2E tests: `**/*.e2e-spec.ts`Test Configuration
Unit tests: Use `jest.config.js`E2E tests: Use `test/jest-e2e.config.js`Coverage Standards
Enforce minimum 80% code coverage thresholdBlock commits/builds when tests fail (when `blockOnTestFail` is true)Require tests for all new services and controllersDatabase Management
Prisma Schema
Schema definition: `prisma/schema.prisma`Migrations directory: `prisma/migrations`Seed file: `prisma/seed.ts`Validation Steps
1. Validate `schema.prisma` syntax before commits
2. Check for pending migrations
3. Verify database connectivity in tests
4. Do NOT auto-migrate database (manual migration approval required)
API Documentation
Swagger/OpenAPI
Swagger decorators location: `src/swagger`Generated OpenAPI spec: `openapi.json`Auto-update documentation when controllers or DTOs changeDocumentation Requirements
All endpoints must have Swagger decoratorsDTOs must include validation decorators and descriptionsResponse types must be documentedCode Quality Standards
File Constraints
Maximum file length: 500 linesMaximum function length: 50 linesIf exceeded, suggest refactoring strategiesNaming Conventions
Use **kebab-case** for file namesExample: `user-profile.service.ts`, `auth-guard.guard.ts`TypeScript Standards
Strict typing enabled (`strictTyping: true`)No implicit `any` types allowedAll function parameters and return types must be explicitly typedValidation Checklist
When reviewing or generating code, validate:
1. **Environment Variables** - Check `.env` and `.env.test` exist and contain required keys
2. **Prisma Schema** - Validate schema syntax and model relationships
3. **Controllers** - Ensure proper routing, guards, and Swagger decorators
4. **Services** - Verify business logic is testable and follows single responsibility
5. **DTOs** - Confirm validation decorators (class-validator) are present
Automation Behaviors
Enabled Automations
**Auto-generate types** - Generate Prisma client types after schema changes**Auto-update docs** - Regenerate OpenAPI spec when controllers change**Block on test failure** - Prevent commits when tests failManual Approvals Required
Database migrations (auto-migrate is disabled for safety)Schema changes affecting production dataUsage Examples
Creating a New Module
When creating a new feature module (e.g., "products"):
1. Create `src/modules/products/` directory
2. Generate required files:
- `products.controller.ts`
- `products.service.ts`
- `products.module.ts`
3. Add supporting files:
- `dto/create-product.dto.ts`
- `dto/update-product.dto.ts`
- `entities/product.entity.ts`
4. Create test files:
- `products.service.spec.ts`
- `products.controller.spec.ts`
- `products.e2e-spec.ts` (in test directory)
Code Review Checklist
Before accepting new code:
[ ] File naming follows kebab-case convention[ ] No file exceeds 500 lines[ ] No function exceeds 50 lines[ ] All types are explicitly defined[ ] Test coverage meets 80% threshold[ ] DTOs include validation decorators[ ] Controllers have Swagger documentation[ ] Prisma schema is valid (if database changes exist)Constraints
Database migrations require manual approval (never auto-migrate in production)Test failures block build pipelineAll public APIs must be documented in SwaggerEnvironment variables must be validated at application startup