ddd-architecture

Implements Domain-Driven Design patterns for NestJS applications with entities, aggregates, CQRS, and domain events.

Updated Jun 14, 2026
One-click install
npx skills add https://github.com/ironkid90-s/lucky5-v7 --skill ddd-architecture-ironkid90-s
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ddd-architecture
Source: https://github.com/ironkid90-s/lucky5-v7/tree/main/.ptah/skills/ddd-architecture
Command: npx skills add https://github.com/ironkid90-s/lucky5-v7 --skill ddd-architecture-ironkid90-s

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Structuring complex business domains in NestJS applications becomes unmanageable without clear architectural boundaries, leading to tangled business logic, inconsistent terminology, and hard-to-test code. This Skill provides tactical and strategic DDD patterns to organize entities, aggregates, value objects, repositories, CQRS handlers, and domain events into a maintainable layered architecture. ## Core Features & Use Cases - Tactical DDD Patterns: Implement entities with identity and lifecycle, immutable value objects (Money, Email, Address, DateRange), and aggregates that enforce invariants and raise domain events. - CQRS and Event-Driven Architecture: Separate command and query handlers using @nestjs/cqrs, publish domain events after persistence, and build read models or event sourcing stores for audit trails. - Repository Abstraction: Define repository interfaces in the domain layer with Prisma implementations, specification patterns for complex queries, and in-memory repositories for testing. - Use Case: When building an order management module, use this Skill to design an Order aggregate with OrderItem child entities, a Money value object, a PrismaOrderRepository, and OrderPlacedEvent handlers for notifications and loyalty points. ## Quick Start Ask the assistant to design a DDD-based order module with entities, value objects, CQRS handlers, and a Prisma repository for your NestJS project.

Frequently Asked Questions about ddd-architecture

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

FAQPage Schema
How do I implement DDD aggregates in NestJS?

Create an aggregate root class with a private constructor and static factory methods like create() and reconstitute(). Encapsulate child entities inside the aggregate, enforce invariants in business methods, and raise domain events that are published after repository save.

What is the difference between entities and value objects in DDD?

Entities have identity and lifecycle, so two entities with identical attributes are still distinct. Value objects like Money or Email are immutable, validated at creation, and compared by attribute equality rather than identity.

When should I use CQRS with NestJS?

Use CQRS when read and write models diverge, domain logic is complex, or you need separate scaling for queries. Skip it for simple CRUD where the same model serves both operations, since the added handlers and buses increase complexity.

How do domain events work with the repository pattern?

Aggregates collect domain events internally during business operations. The repository retrieves these events during save, persists the aggregate in a transaction, clears the events, and then publishes them through the NestJS EventBus to registered handlers.

When should I not use Domain-Driven Design?

Avoid full DDD for simple CRUD applications with no complex business rules or entity lifecycles. The Skill's complexity assessment suggests plain services for low scores, tactical patterns for medium complexity, and full strategic DDD only for multi-team, complex domains.