Set up PostgreSQL database configuration and enhance application structure
- Added .env.example with database connection details and JWT configuration. - Introduced docker-compose.yml for PostgreSQL service setup with health checks. - Created drizzle.config.ts for database schema and migration management. - Updated nest-cli.json to include Swagger plugin configuration for API documentation. - Enhanced package.json with new database-related scripts and dependencies. - Implemented initial database migrations for user and token management. - Configured application bootstrap process to load environment variables and set up Swagger. - Added shared application configuration in configure-app.ts for consistent setup. - Included unit tests for application configuration and Swagger setup.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
---
|
||||
description: NestJS OpenAPI/Swagger conventions for controllers and DTOs
|
||||
globs: "src/**/*.controller.ts,src/**/dto/**/*.ts,src/common/swagger/**/*.ts,src/main.ts,nest-cli.json"
|
||||
alwaysApply: false
|
||||
---
|
||||
|
||||
# NestJS Swagger Best Practices
|
||||
|
||||
## Controllers
|
||||
|
||||
Document every HTTP handler:
|
||||
|
||||
```typescript
|
||||
@ApiTags('auth')
|
||||
@Controller('auth')
|
||||
export class AuthController {
|
||||
@Post('login')
|
||||
@ApiOperation({ summary: 'Log in' })
|
||||
@ApiOkResponse({ type: TokenPairDto })
|
||||
login(@Body() dto: LoginDto) { /* ... */ }
|
||||
|
||||
@Get('me')
|
||||
@ApiBearerAuth('access-token')
|
||||
@ApiOkResponse({ type: MeResponseDto })
|
||||
me(@CurrentUser() user: AuthUser) { /* ... */ }
|
||||
}
|
||||
```
|
||||
|
||||
- Use `@ApiTags`, `@ApiOperation`, and typed `@ApiOkResponse` / `@ApiCreatedResponse` / `@ApiNoContentResponse`
|
||||
- Response types must be DTO **classes**, not interfaces or domain entities
|
||||
- Add `@ApiBearerAuth('access-token')` only on JWT-protected routes
|
||||
- Public (`@Public()`) routes must omit bearer auth
|
||||
- Document expected errors (`@ApiBadRequestResponse`, `@ApiUnauthorizedResponse`, etc.) when meaningful
|
||||
|
||||
## DTOs
|
||||
|
||||
- Request and response DTOs live under `dto/`
|
||||
- Never expose domain entities or sensitive fields (`passwordHash`, secrets) in OpenAPI
|
||||
- Nest CLI Swagger plugin is enabled — use `@ApiProperty` for examples, `format: 'password'`, `writeOnly`, not to restate every class-validator rule
|
||||
- Examples must be fake; never real tokens or secrets
|
||||
|
||||
```typescript
|
||||
// BAD — documents entity / real secret
|
||||
@ApiOkResponse({ type: User })
|
||||
@ApiProperty({ example: process.env.JWT_ACCESS_SECRET })
|
||||
|
||||
// GOOD — response DTO + fake example
|
||||
@ApiOkResponse({ type: MeResponseDto })
|
||||
@ApiProperty({ example: 'alice', format: 'password', writeOnly: true })
|
||||
```
|
||||
|
||||
## Bootstrap
|
||||
|
||||
- Mount UI at `/docs` and JSON at `/docs-json` only (via `setupSwagger` / `configureApp`)
|
||||
- Swagger is off when `NODE_ENV=production` unless `SWAGGER_ENABLED=true`
|
||||
- Keep the `@nestjs/swagger` plugin in `nest-cli.json` (`classValidatorShim`, `introspectComments`, `dtoFileNameSuffix: [".dto.ts"]`)
|
||||
@@ -13,6 +13,7 @@ Stack: NestJS + PostgreSQL + Drizzle ORM. Follow `.agents/skills/nestjs-best-pra
|
||||
- One feature folder under `src/modules/`
|
||||
- Each feature has `*.module.ts`, `*.controller.ts`, `*.service.ts`, `dto/`
|
||||
- Share cross-cutting code via `src/common/` (filters, guards, pipes, interceptors)
|
||||
- Document HTTP endpoints per `.cursor/rules/nestjs-swagger.mdc`
|
||||
|
||||
## Tests
|
||||
|
||||
|
||||
Reference in New Issue
Block a user