nestjs-clean-hex-cqrs-api-playbook

Enforce Clean Architecture, Hexagonal, and CQRS-lite boundaries in NestJS APIs.

Updated Jan 29, 2026
One-click install
npx skills add https://github.com/khoidang2110/agent-skills --skill nestjs-clean-hex-cqrs-api-playbook
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nestjs-clean-hex-cqrs-api-playbook
Source: https://github.com/khoidang2110/agent-skills/tree/main/skills/nestjs
Command: npx skills add https://github.com/khoidang2110/agent-skills --skill nestjs-clean-hex-cqrs-api-playbook

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill ensures NestJS APIs adhere to Clean Architecture, Hexagonal (Ports & Adapters), and CQRS-lite patterns, preventing architectural drift in large Nx monorepos.

Core Features & Use Cases

  • Architectural enforcement: guides the layering from controllers to persistence and enforces port-based DI.
  • Standardized workflow: provides a step-by-step playbook for adding or modifying any NestJS API endpoint.
  • Guidance on persistence & errors: codifies DomainError usage and Prisma 6.x persistence practices.

Quick Start

Follow the NestJS API Playbook when adding or updating any NestJS API. Start by mapping the HTTP contract in libs/api, then implement the QueryService/UseCase, wire ports via tokens, add a persistence adapter, and ensure Prisma schema alignment.

Frequently Asked Questions about nestjs-clean-hex-cqrs-api-playbook

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

FAQPage Schema
How do I structure a NestJS API using Clean Architecture and Hexagonal patterns?

To structure a NestJS API with Clean Architecture and Hexagonal patterns, you separate API logic from business rules using Ports and Adapters. This skill guides layering from controllers to persistence adapters, enforcing token-based dependency injection within an Nx monorepo.

What is the best way to prevent architectural drift in a large NestJS Nx monorepo?

Preventing architectural drift in a large NestJS Nx monorepo requires enforcing strict module boundaries and standardized workflows. This skill provides a step-by-step playbook mandating CQRS-lite separation, port-based dependency injection, and DomainError usage to maintain consistency.

How do I add a new API endpoint in NestJS following CQRS-lite and Hexagonal boundaries?

Adding an endpoint following CQRS-lite involves mapping the HTTP contract in libs/api, implementing the QueryService or UseCase, wiring ports via tokens, and adding a persistence adapter. This ensures API logic remains strictly separate from core business rules.

Does this NestJS Clean Architecture playbook support Prisma 6.x for persistence?

Yes, this NestJS Clean Architecture playbook supports Prisma 6.x. It codifies specific Prisma 6.x persistence rules and ensures alignment with the Prisma schema while mandating the use of DomainError for handling errors across the persistence adapters.

Why should I use token-based dependency injection in NestJS Hexagonal Architecture?

Token-based dependency injection in NestJS Hexagonal Architecture enforces strict module boundaries by decoupling port interfaces from concrete adapter implementations. This prevents architectural drift and ensures API logic remains separate from business rules and persistence concerns.

When do I need CQRS-lite in a NestJS API project?

You need CQRS-lite in a NestJS API project when separating query services from use cases to maintain strict architectural boundaries. It helps scale large Nx monorepos by ensuring API logic and business rules remain isolated across controller and persistence layers.