Awesome-omni-skills nestjs-modular-monolith
Modular Monolith Specialist workflow skill. Use this skill when the user needs Specialist in designing and implementing scalable modular monolith architectures using NestJS with DDD, Clean Architecture, and CQRS patterns. Use when building modular monolith backends, designing bounded contexts, creating domain modules, implementing event-driven module communication, or when user mentions \"modular monolith\", \"bounded contexts\", \"module boundaries\", \"DDD\", \"CQRS\", \"clean architecture NestJS\", or \"monolith to microservices\". Do NOT use for simple CRUD APIs, frontend work, or general NestJS questions without architectural context and the operator should preserve the upstream workflow, copied support files, and provenance before merging or handing off.
git clone https://github.com/diegosouzapw/awesome-omni-skills
T=$(mktemp -d) && git clone --depth=1 https://github.com/diegosouzapw/awesome-omni-skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/nestjs-modular-monolith" ~/.claude/skills/diegosouzapw-awesome-omni-skills-nestjs-modular-monolith && rm -rf "$T"
skills/nestjs-modular-monolith/SKILL.mdModular Monolith Specialist
Overview
This public intake copy packages
packages/skills-catalog/skills/(development)/nestjs-modular-monolith from https://github.com/tech-leads-club/agent-skills into the native Omni Skills editorial shape without hiding its origin.
Use it when the operator needs the upstream workflow, support files, and repository context to stay intact while the public validator and private enhancer continue their normal downstream flow.
This intake keeps the copied upstream files intact and uses
metadata.json plus ORIGIN.md as the provenance anchor for review.
Modular Monolith Specialist Consultative architect and implementer specializing in robust, scalable modular monolith systems using NestJS. Designs architectures that balance modularity, maintainability, and evolutionary potential through DDD and Clean Architecture.
Imported source sections that did not map cleanly to the public headings are still preserved below or in the support files. Notable imported sections: Role Definition, Module Structure, Stack Recommendations, Constraints, Output Templates, Quick Anti-Pattern Detection.
When to Use This Skill
Use this section as the trigger filter. It should make the activation boundary explicit before the operator loads files, runs commands, or opens a pull request.
- Designing a new modular monolith from scratch
- Defining bounded contexts and domain boundaries
- Creating NestJS modules with Clean Architecture layers
- Setting up event-driven communication between modules
- Optionally implementing CQRS when the domain justifies it
- Planning monolith-to-microservices evolution paths
Operating Table
| Situation | Start here | Why it matters |
|---|---|---|
| First-time use | | Confirms repository, branch, commit, and imported path before touching the copied workflow |
| Provenance review | | Gives reviewers a plain-language audit trail for the imported source |
| Workflow execution | | Starts with the smallest copied file that materially changes execution |
| Supporting context | | Adds the next most relevant copied source file without loading the entire package |
| Handoff decision | | Helps the operator switch to a stronger native skill when the task drifts |
Workflow
This workflow is intentionally editorial and operational at the same time. It keeps the imported source useful to the operator while still satisfying the public intake standards that feed the downstream enhancer flow.
- Identify the business domain — What problem does the system solve?
- Map bounded contexts — Which business capabilities are distinct?
- Define aggregates and entities — What are the core domain objects?
- Clarify scaling requirements — Which modules need independent scaling?
- Identify integrations — External systems, APIs, event sources?
- HTTP adapter: Fastify (recommended for performance) or Express?
- ORM: Prisma (type-safe, recommended) or TypeORM?
Imported Workflow Notes
Imported: Core Workflow
Phase 1: Discovery
Before writing any code, understand the domain.
- Identify the business domain — What problem does the system solve?
- Map bounded contexts — Which business capabilities are distinct?
- Define aggregates and entities — What are the core domain objects?
- Clarify scaling requirements — Which modules need independent scaling?
- Identify integrations — External systems, APIs, event sources?
Ask the user about stack preferences:
- HTTP adapter: Fastify (recommended for performance) or Express?
- ORM: Prisma (type-safe, recommended) or TypeORM?
- API style: tRPC (type-safe) or REST with Swagger?
- Monorepo: NX (recommended) or Turborepo?
- Linting: Biome (fast, recommended) or ESLint+Prettier?
- Auth: Passport/JWT or Better Auth? (see
)references/authentication.md - Complexity: Simple services (default) or CQRS? (see
)references/architecture-patterns.md
Exit criteria:
- Bounded contexts identified with clear responsibilities
- Stack preferences confirmed
- Scaling and integration requirements documented
Phase 2: Design
Architect the system before implementation.
- Design module structure — Map bounded contexts to NX libraries
- Define module interfaces — Public API surface of each module
- Plan communication — Events for cross-module, direct calls within module
- Design data model — Per-module schemas with state isolation
- Plan authentication — Choose and configure auth strategy
Load
references/architecture-patterns.md for Clean Architecture layers and module structure guidance.
Output: Architecture document with module map, communication diagram, and data model overview.
Exit criteria:
- Each module has defined responsibilities and public interface
- Communication contracts specified (events for cross-module)
- Data model shows strict module ownership
- No shared entities across module boundaries
Phase 3: Implementation
Build modules following Clean Architecture layers. For each module, implement in this order:
Default approach (simple services):
- Domain layer — Entities, value objects, domain events, repository interfaces
- Application layer — Services with business logic, DTOs
- Infrastructure layer — Repository implementations, external adapters
- Presentation layer — Controllers, resolvers, route definitions
CQRS approach (only when the domain has distinct read/write patterns — ask the user first):
- Domain layer — Same as above
- Application layer — Commands, queries, handlers (instead of services)
- Infrastructure layer — Same as above
- Presentation layer — Controllers using CommandBus/QueryBus instead of services
Load references as needed:
— For bootstrap, Prisma, Biome configsreferences/stack-configuration.md
— For event system implementationreferences/module-communication.md
— For entity naming and isolation checksreferences/state-isolation.md
— For auth guard and session setupreferences/authentication.md
— For test structure and mocksreferences/testing-patterns.md
Implementation rules:
- Every module gets its own NestJS
class with explicit imports/exportsModule - Repository interfaces live in domain layer; implementations in infrastructure
- Cross-module communication happens ONLY via events or shared contracts
- Never import a module's internal service directly from another module
- Use dependency injection for all services — no manual instantiation
Phase 4: Validation
Verify the architecture holds before shipping.
- State isolation check — Run
or the entity duplication detection fromscripts/validate-isolation.shreferences/state-isolation.md - Boundary check — Verify no direct cross-module imports
- Test coverage — Unit tests for domain, integration for boundaries
- Communication check — Events flow correctly between modules
- Build check — NX build graph respects module boundaries
Exit criteria:
- No duplicate entity names across modules
- No direct cross-module service imports
- All modules build and test independently
- Event contracts are validated
Imported: Role Definition
You are a senior backend architect with deep expertise in modular monolith design. You guide users from domain analysis to production-ready implementation. You combine the benefits of microservices (boundaries, independence, testability) with monolith simplicity (single deployment, shared infrastructure, simple ops) while maintaining a clear evolution path to microservices when needed.
Examples
Example 1: Ask for the upstream workflow directly
Use @nestjs-modular-monolith to handle <task>. Start from the copied upstream workflow, load only the files that change the outcome, and keep provenance visible in the answer.
Explanation: This is the safest starting point when the operator needs the imported workflow, but not the entire repository.
Example 2: Ask for a provenance-grounded review
Review @nestjs-modular-monolith against metadata.json and ORIGIN.md, then explain which copied upstream files you would load first and why.
Explanation: Use this before review or troubleshooting when you need a precise, auditable explanation of origin and file selection.
Example 3: Narrow the copied support files before execution
Use @nestjs-modular-monolith for <task>. Load only the copied references, examples, or scripts that change the outcome, and name the files explicitly before proceeding.
Explanation: This keeps the skill aligned with progressive disclosure instead of loading the whole copied package by default.
Example 4: Build a reviewer packet
Review @nestjs-modular-monolith using the copied upstream files plus provenance, then summarize any gaps before merge.
Explanation: This is useful when the PR is waiting for human review and you want a repeatable audit packet.
Best Practices
Treat the generated public skill as a reviewable packaging layer around the upstream repository. The goal is to keep provenance explicit and load only the copied source material that materially improves execution.
- Boundaries: Clear interfaces between modules, minimal coupling
- Composability: Modules can be recombined dynamically
- Independence: Each module is self-contained with its own domain
- Scalability: Per-module optimization without system-wide changes
- Explicit Communication: Contracts between modules, never implicit
- Replaceability: Any module can be substituted without system impact
- Logical Deployment Separation: Even in monolith, maintain separation
Imported Operating Notes
Imported: Core Principles
10 Modular Monolith Principles — these override general NestJS defaults when they conflict:
- Boundaries: Clear interfaces between modules, minimal coupling
- Composability: Modules can be recombined dynamically
- Independence: Each module is self-contained with its own domain
- Scalability: Per-module optimization without system-wide changes
- Explicit Communication: Contracts between modules, never implicit
- Replaceability: Any module can be substituted without system impact
- Logical Deployment Separation: Even in monolith, maintain separation
- State Isolation: Strict data boundaries — no shared database tables
- Observability: Module-level monitoring and tracing
- Resilience: Failures in one module don't cascade
Imported: Behavioral Guidelines
These principles govern HOW you work, not just WHAT you build:
Think Before Coding. Before implementing any module or layer: state your assumptions about domain boundaries explicitly. If multiple bounded context interpretations exist, present them — don't pick silently. If a simpler module structure exists, say so and push back when warranted. If the domain is unclear, stop and ask — don't guess.
Simplicity First. Design the minimum viable architecture: no CQRS unless the domain has distinct read/write patterns. No Event Sourcing unless audit trail is a real requirement. No abstractions for single-use code. If 3 modules suffice, don't create 8. Start with simple services, upgrade to CQRS only when complexity warrants it.
Surgical Changes. When working with existing modular monoliths: don't "improve" adjacent modules that aren't part of the task. Match existing style and conventions, even if you'd do it differently. If you spot unrelated issues, mention them — don't fix them silently.
Goal-Driven Execution. For every architectural decision, define verifiable success criteria. "Add a new module" → "Module has isolated state, clear interface, passing tests". "Fix communication" → "Events flow correctly, no direct cross-module imports".
Troubleshooting
Problem: The operator skipped the imported context and answered too generically
Symptoms: The result ignores the upstream workflow in
packages/skills-catalog/skills/(development)/nestjs-modular-monolith, fails to mention provenance, or does not use any copied source files at all.
Solution: Re-open metadata.json, ORIGIN.md, and the most relevant copied upstream files. Load only the files that materially change the answer, then restate the provenance before continuing.
Problem: The imported workflow feels incomplete during review
Symptoms: Reviewers can see the generated
SKILL.md, but they cannot quickly tell which references, examples, or scripts matter for the current task.
Solution: Point at the exact copied references, examples, scripts, or assets that justify the path you took. If the gap is still real, record it in the PR instead of hiding it.
Problem: The task drifted into a different specialization
Symptoms: The imported skill starts in the right place, but the work turns into debugging, architecture, design, security, or release orchestration that a native skill handles better. Solution: Use the related skills section to hand off deliberately. Keep the imported provenance visible so the next skill inherits the right context instead of starting blind.
Related Skills
- Use when the work is better handled by that native specialization after this imported skill establishes context.@accessibility
- Use when the work is better handled by that native specialization after this imported skill establishes context.@ai-cold-outreach
- Use when the work is better handled by that native specialization after this imported skill establishes context.@ai-pricing
- Use when the work is better handled by that native specialization after this imported skill establishes context.@ai-sdr
Additional Resources
Use this support matrix and the linked files below as the operator packet for this imported skill. They should reflect real copied source material, not generic scaffolding.
| Resource family | What it gives the reviewer | Example path |
|---|---|---|
| copied reference notes, guides, or background material from upstream | |
| worked examples or reusable prompts copied from upstream | |
| upstream helper scripts that change execution or validation | |
| routing or delegation notes that are genuinely part of the imported package | |
| supporting assets or schemas copied from the source package | |
- architecture-patterns.md
- authentication.md
- module-communication.md
- stack-configuration.md
- validate-isolation.sh
- architecture-patterns.md
Imported Reference Notes
Imported: Reference Guide
Load detailed guidance based on the current task:
| Topic | Reference | Load When |
|---|---|---|
| Architecture | | Designing modules, layers, DDD patterns, CQRS, NX config |
| Authentication | | Setting up auth: JWT/Passport or Better Auth with NestJS |
| Communication | | Implementing events, cross-module contracts, publishers |
| State Isolation | | Checking entity duplication, naming conventions, anti-patterns |
| Testing | | Writing unit, integration, or E2E tests for modules |
| Stack Config | | Bootstrap, Prisma schemas, Biome config, DTOs, exception filters |
Imported: Knowledge Reference
NestJS, Fastify, Express, TypeScript, NX, Prisma, TypeORM, tRPC, DDD, Clean Architecture, CQRS, Event Sourcing, Bounded Contexts, Domain Events, Passport, JWT, Better Auth, class-validator, class-transformer, Swagger/OpenAPI, Jest, Supertest, Biome, Kafka, SQS, Redis, RabbitMQ
Imported: Module Structure
Recommended NX monorepo structure:
apps/ api/ # NestJS application entry point src/ main.ts # Bootstrap with Fastify adapter app.module.ts # Root module importing all domain modules libs/ shared/ domain/ # Shared kernel: base classes, value objects contracts/ # Cross-module event/command interfaces infrastructure/ # Shared infra: database, logging, config [module-name]/ # One per bounded context domain/ # Entities, aggregates, repository interfaces application/ # Services (or commands/queries if using CQRS) infrastructure/ # Repository implementations, adapters presentation/ # Controllers, resolvers [module-name].module.ts # NestJS module definition
Imported: Stack Recommendations
When the user hasn't specified preferences, recommend this stack with rationale:
| Component | Recommendation | Why |
|---|---|---|
| HTTP Adapter | Fastify | 2-3x faster than Express, better TS support, plugin architecture |
| ORM | Prisma | Type-safe queries, declarative schema, excellent migrations |
| API Layer | tRPC or REST+Swagger | tRPC for full-stack TS; REST+Swagger for public APIs |
| Monorepo | NX | Task orchestration, affected commands, module boundaries |
| Linting | Biome | 35x faster than Prettier, single tool for format+lint |
| Testing | Jest (unit) + Supertest (E2E) | NestJS native support, well-documented |
| Auth | Passport/JWT or Better Auth | Passport for standard flows; Better Auth for modern, plugin-based auth |
| Complexity | Simple services (default) | CQRS only when domain has distinct read/write patterns |
Always ask the user before assuming. Present alternatives with tradeoffs.
Imported: Constraints
MUST DO
- Use dependency injection for ALL services
- Validate ALL inputs via DTOs with
class-validator - Define repository interfaces in domain layer, implement in infrastructure
- Prefix entities with module name (e.g.,
, notBillingPlan
)Plan - Use events for cross-module communication
- Document module public API via exports in NestJS module
- Write unit tests for services or command/query handlers
- Use environment variables for ALL configuration
- Document APIs with Swagger decorators (REST) or tRPC router types
MUST NOT DO
- ❌ Share database tables across modules
- ❌ Import internal services from another module directly
- ❌ Use
type — leverage TypeScript strict modeany - ❌ Create circular dependencies between modules
- ❌ Use Node.js EventEmitter for production inter-module communication
- ❌ Use generic entity names (
,User
,Plan
) without module prefixItem - ❌ Hardcode configuration values
- ❌ Skip error handling — use domain-specific exceptions
- ❌ Export internal services that should stay private to a module
- ❌ Access shared mutable state across modules
- ❌ Force CQRS on modules that don't need it — start simple
Imported: Output Templates
When implementing a complete module, provide files in this order:
- Domain entities — With module-prefixed names and business logic
- Repository interface — In domain layer, defines data access contract
- Service (default) or Commands/Queries + Handlers (if CQRS) — Implementing business rules
- DTOs — Request/response with Swagger decorators and validation
- Repository implementation — Prisma/TypeORM in infrastructure layer
- Controller — With guards, Swagger docs, and proper HTTP codes
- Module definition — NestJS module with explicit imports/exports
- Tests — Unit tests for services/handlers, integration tests for boundaries
- Domain events — If cross-module communication is needed
When designing architecture (not implementing), provide:
- Executive Summary — Architecture overview, key decisions, rationale
- Bounded Contexts Map — Responsibilities, aggregates, communication
- Module Interface Contracts — Public API surface of each module
- Data Model — Per-module schemas with ownership boundaries
- Communication Diagram — Event flows between modules
- Evolution Path — How to extract modules to microservices later
Imported: Quick Anti-Pattern Detection
Before finalizing any module, run
scripts/validate-isolation.sh or verify manually:
# Check duplicate entity names across modules grep -r "@Entity.*name:" libs/ | grep -o "name: '[^']*'" | sort | uniq -d # Detect direct cross-module imports (should only import from index) grep -r "from.*@company.*/" libs/ | grep -v shared | grep -v index # Find shared mutable state grep -r "export.*=.*new" libs/ | grep -v test # Check for synchronous inter-module calls grep -r "await.*\..*Service" libs/ | grep -v "this\."
If any check finds violations, fix them before proceeding.
Imported: MCP Tools
Use these MCP tools when available for enhanced results:
- context7: Query latest docs for NestJS, Prisma, Better Auth, NX, and other stack components. Always prefer fresh docs over built-in knowledge.
- sequential-thinking: Use for complex architectural analysis, multi-step design decisions, and tradeoff evaluation.