API Contracts Generator

Generate synchronized DTOs and TypeScript types for Next.js and NestJS API contracts.

Updated Oct 31, 2025
One-click install
npx skills add https://github.com/RomualdP/hoki --skill api-contracts-generator
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: API Contracts Generator
Source: https://github.com/RomualdP/hoki/tree/main/.claude/skills/api-contracts
Command: npx skills add https://github.com/RomualdP/hoki --skill api-contracts-generator

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires class-validator, @nestjs/swagger, zod.

What problem does it solve?

This Skill eliminates common frontend-backend communication errors by generating consistent API contracts, ensuring synchronized types, standardized validation, and uniform error handling across Next.js and NestJS applications.

Core Features & Use Cases

  • Backend DTOs (NestJS): Defines Request and Response DTOs using class-validator and @nestjs/swagger for robust validation and automatic API documentation.
  • Frontend Types (Next.js): Guides on generating or manually synchronizing TypeScript types for frontend consumption, ensuring type safety.
  • Standardized Error Handling: Implements a consistent error response format across the API, making it easier for the frontend to parse and display errors.
  • Use Case: When creating a new API endpoint for club creation, define a CreateClubDto in NestJS with validation rules. Then, create a corresponding TypeScript type on the frontend to ensure the data sent by the UI matches the backend's expectations, preventing runtime errors.

Quick Start

To define a new API contract, create a CreateXDto in your backend's presentation/dtos/ folder using class-validator and @ApiProperty decorators. Ensure the frontend uses a corresponding TypeScript type for the request body.

Frequently Asked Questions about API Contracts Generator

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

FAQPage Schema
How do I keep TypeScript types synchronized between Next.js frontend and NestJS backend?

Generate synchronized TypeScript types by defining DTOs in your NestJS backend using class-validator decorators, then create corresponding frontend types that match the backend contract. This prevents runtime mismatches and ensures type safety across your full-stack application.

What's the best way to validate API requests consistently in Next.js and NestJS?

Define validation rules once in NestJS DTOs using class-validator, then mirror those rules on the frontend with matching TypeScript types. This unified approach catches invalid data early and standardizes error responses across your API.

Can I auto-generate API documentation from NestJS validation rules?

Yes. Use @nestjs/swagger decorators alongside class-validator in your DTOs to automatically generate Swagger documentation. The backend contracts drive both validation and documentation, keeping them synchronized without manual effort.

How do I implement consistent error handling across my Next.js and NestJS API?

Define a standardized error response format in your NestJS backend DTOs, then use the same structure on the frontend for parsing errors. Consistent formatting makes error handling predictable and reduces integration bugs.

Do I need to manually sync frontend and backend types, or can this be automated?

API contract generation synchronizes types by establishing a single source of truth in your NestJS DTOs. The frontend consumes those contracts, eliminating manual type duplication and keeping both layers aligned as your API evolves.

What happens if my Next.js client sends data that doesn't match the NestJS backend contract?

Class-validator rules in your NestJS DTOs reject invalid payloads before processing. By generating matching frontend types, you catch mismatches during development, while the backend validation provides runtime protection against unexpected data shapes.