Backend API

Generate NestJS REST API endpoints with controllers, use cases, and repositories.

1|Updated Dec 4, 2024
One-click install
npx skills add https://github.com/imkdw/imkdw-dev --skill backend-api-imkdw
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Backend API
Source: https://github.com/imkdw/imkdw-dev/tree/main/.claude/skills/backend-api
Command: npx skills add https://github.com/imkdw/imkdw-dev --skill backend-api-imkdw

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solves?

Inconsistent API design and implementation can lead to confusion for frontend developers, security vulnerabilities, and difficult maintenance. This Skill standardizes API development with NestJS, ensuring clarity, security, and scalability.

Core Features & Use Cases

  • Layered Architecture: Implement controllers, use cases, and repositories for clear separation of concerns, making the API logic easy to understand and maintain.
  • Swagger Documentation: Automatically generate and maintain comprehensive API documentation using @nestjs/swagger, simplifying integration for consumers.
  • Authentication & Authorization: Secure endpoints with route guards and custom decorators (e.g., @Public, @MemberRoles), ensuring proper access control.
  • Use Case: When creating a new API endpoint for fetching articles, ensure it uses the correct @Get decorator, integrates with a GetArticlesQuery, and is documented with @ApiTags and @Swagger.getItems for clear API contract.

Quick Start

Help me create a new NestJS controller for managing 'Comments', including a @Post endpoint to create a comment and a @Get endpoint to retrieve comments, with basic Swagger documentation.

Frequently Asked Questions about Backend API

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure a NestJS REST API with controllers, use cases, and repositories?

NestJS REST APIs use layered architecture with @Controller-decorated files handling HTTP requests, use cases managing business logic, and repositories handling data access. This separation of concerns makes APIs maintainable and testable, with each layer having a single responsibility.

What's the best way to document NestJS API endpoints with Swagger?

Use @nestjs/swagger decorators like @ApiTags and @Swagger methods on controller endpoints to generate OpenAPI documentation automatically. Swagger decorators ensure your API contract is always current and accessible to frontend developers.

How do I implement authentication and authorization guards in NestJS controllers?

Apply route guards and custom decorators such as @Public and @MemberRoles to @Controller-decorated files to control endpoint access. Guards intercept requests before they reach handlers, enforcing security policies consistently across your API.

Do I need to separate read and write operations in NestJS API design?

Yes. NestJS layered architecture enforces Query operations for reads and UseCase operations for writes, keeping data access patterns explicit and predictable. This separation prevents side effects and improves API reliability.

What's the proper way to handle DTOs and HTTP status codes in NestJS endpoints?

Use DTOs (Data Transfer Objects) to validate and shape request/response data, and apply @HttpCode or @HttpStatus decorators to specify correct response codes. This ensures type safety and correct HTTP semantics across all endpoints.

Can I use dependency injection in NestJS controller constructors?

Yes. NestJS supports constructor-based dependency injection for controllers, allowing you to inject services, repositories, and use cases directly. This makes controllers testable and decouples them from concrete implementations.