nestjs-modular-monolith

Designs and implements NestJS modular monoliths using DDD, Clean Architecture, and optional CQRS.

Updated Sep 15, 2026
One-click install
npx skills add https://github.com/Peterson-Benhame/agent-skills --skill nestjs-modular-monolith-peterson-benhame
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nestjs-modular-monolith
Source: https://github.com/Peterson-Benhame/agent-skills/tree/main/packages/skills-catalog/skills/%28development%29/nestjs-modular-monolith
Command: npx skills add https://github.com/Peterson-Benhame/agent-skills --skill nestjs-modular-monolith-peterson-benhame

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? Building large NestJS backends without clear module boundaries leads to tangled dependencies, shared database tables, and codebases that are hard to scale or split into microservices later. This Skill guides the design and implementation of modular monolith architectures with enforced bounded contexts, state isolation, and event-driven module communication. ## Core Features & Use Cases - Bounded Context Design: Maps business domains to NX monorepo libraries with Clean Architecture layers (domain, application, infrastructure, presentation) and explicit module interfaces. - Event-Driven Communication: Implements cross-module communication via domain events with pluggable publishers (in-memory, Kafka, SQS, Redis) instead of direct service imports. - State Isolation Validation: Ships a validation script that detects duplicate entity names, cross-module imports, shared mutable state, and improper Prisma relations. - Use Case: A team starting a new SaaS backend asks the agent to design identity, billing, and orders modules. The Skill produces the bounded context map, NestJS module structure with Prisma schemas, event contracts, and tests, then validates isolation before shipping. ## Quick Start Ask the agent to design a modular monolith backend for your product with NestJS, specifying your bounded contexts and preferred stack such as Fastify, Prisma, and NX.

Frequently Asked Questions about nestjs-modular-monolith

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

FAQPage Schema
How do I structure a modular monolith in NestJS?

Structure each bounded context as an NX library with four Clean Architecture layers: domain, application, infrastructure, and presentation. Each module gets its own NestJS Module class with explicit imports and exports, and cross-module communication happens only through domain events.

When should I use CQRS in a NestJS modular monolith?

Use CQRS only when a module has genuinely distinct read and write patterns, such as read-heavy workloads needing optimized queries. The default approach is simple injectable services; upgrade to command and query handlers only when complexity justifies it.

Should I use Passport JWT or Better Auth with NestJS?

Use Passport with JWT when you need full control over authentication flows or have existing Passport infrastructure. Use Better Auth when you want built-in social login, session management, and two-factor authentication with less boilerplate via the @thallesp/nestjs-better-auth adapter.

How do modules communicate in a modular monolith?

Modules communicate exclusively through domain events defined in a shared contracts library, never through direct service imports. Use an in-memory publisher for development and Kafka, SQS, or Redis publishers for production, swapped via dependency injection.

When should I not use a modular monolith architecture?

Avoid it for simple CRUD APIs with fewer than ten endpoints, prototypes where speed matters more than structure, and microservices-first architectures. Standard NestJS defaults are sufficient for small applications without complex domain boundaries.

How do I enforce state isolation between NestJS modules?

Prefix every entity with its module name, use plain ID fields instead of Prisma relations across modules, and run the included validate-isolation.sh script. It detects duplicate model names, cross-module imports, shared mutable state, and synchronous cross-module calls.