Domain-Driven Design (DDD) with NestJS Essentials 2026
Model your domain properly, then wire it into NestJS with downloadable starter code

(voice overs) Most NestJS codebases start clean and end up as a big ball of mud: fat controllers, anemic entities, repositories that leak SQL into the domain, and business rules scattered across services. This course fixes that by teaching Domain-Driven Design as a practical discipline, not a vocabulary list. You will learn to separate the problem space (subdomains) from the solution space (bounded contexts), map how contexts relate, and run an Event Storming session that produces real boundaries instead of a wall of sticky notes.
On the tactical side you will build Entities, Value Objects, Aggregates, Domain Events, Repositories, and Domain Services in plain TypeScript, then see exactly where each one lives in a hexagonal NestJS project. You will implement a TypeORM adapter and a Mongoose variant, add CQRS with @nestjs/cqrs, handle transactions with a Unit of Work, and use the Outbox pattern so domain events survive a crash. The course closes with a capstone where you model and implement a task-management domain end to end, plus a code review checklist you can take to your team on Monday.
The teaching is slide-driven with worked examples throughout: Money as a value object, the Task aggregate, a full Event Storming session, and a reference folder structure you can copy. Every NestJS feature — modules, controllers, providers, custom tokens, pipes, guards, interceptors, filters — is shown in service of keeping the domain pure, so you can see where the framework helps and where it should stay out of the way.
We also included a starter pack for you to work on, this starter is a fork of
[deadislove/nestJS-hexagonal-architecture-template]
**What is the difference between a subdomain and a bounded context?**
A subdomain is part of the problem space (Core, Supporting, or Generic), while a bounded context is a boundary in the solution space where one model applies. Lesson 2 devotes a dedicated slide to Subdomain vs Bounded Context and walks through the seven context mapping patterns the course covers: Partnership, Shared Kernel, Customer-Supplier, Conformist, Anticorruption Layer, Open Host Service, and Published Language.
**How do I run an Event Storming session?**
Lesson 3 teaches the Event Storming notation, how to run the session, and how to convert a wall of orange events into bounded context boundaries. It includes a full worked example on a task-management domain.
**Where should repository interfaces live in a NestJS project?**
Repository interfaces belong in the domain layer, bound in NestJS with custom providers and tokens. Lesson 5 covers Where Does the Interface Live? and repository pitfalls; lesson 11 ends with the repository interface and its injection token.
**How do I implement CQRS in NestJS?**
Use @nestjs/cqrs to dispatch domain events and implement commands, command handlers, queries, query handlers, and sagas. Aggregates extend the library's `AggregateRoot`, queue events with `apply()`, and dispatch them through `EventPublisher.mergeObjectContext(aggregate)` plus `commit()`. Lesson 11 covers each of these in 12:20, and lesson 7 explains when CQRS pays off.
**What is the Outbox pattern and why do I need it?**
The Outbox pattern makes domain events survive a crash by persisting them alongside the transaction before dispatch. Lesson 12 covers the Outbox pattern together with Unit of Work transactions.
**How do I keep my domain layer pure when using NestJS?**
Write the domain layer in plain TypeScript with no decorators or ORM types, then wire it in through adapters. Lesson 10 shows identity, value objects, and an aggregate root that raises events in plain TypeScript, and lesson 6 answers how pure the domain must be.
**How do I test a DDD domain in NestJS?**
Write fast domain unit tests in plain TypeScript, then add integration and E2E tests for the adapters. Lesson 13 covers Testing the Domain plus Integration and E2E Tests, and lesson 9 covers Jest setup.
**When should I not use DDD?**
Skip DDD when the business rules are trivial and a simple CRUD model suffices. Lesson 13 has a dedicated When Not to Use DDD section and also covers adopting DDD incrementally.
What you will learn
- Distinguish subdomains from bounded contexts and draw a context map using Partnership, Shared Kernel, Customer-Supplier, Conformist, Anticorruption Layer, and O
- Run an Event Storming session and convert the output into concrete bounded context boundaries
- Implement Entities, Value Objects, Aggregates, and Domain Events in plain TypeScript with enforced invariants
- Design small aggregates and decide when to reference another aggregate by identity
- Place repository interfaces in the domain layer and bind them in NestJS with custom providers and tokens
- Build a hexagonal NestJS project with TypeORM and Mongoose adapters, mappers, and controllers as primary adapters
- Add CQRS with @nestjs/cqrs — commands, queries, sagas — and implement the Outbox pattern for reliable event dispatch
- Write fast domain unit tests plus integration and E2E tests, and apply a code review checklist to catch tactical anti-patterns
What is in the course
DDD Foundations and the Ubiquitous Language
1DDD Foundations and the Ubiquitous Language23 min
- Explains why architecture matters, dissects the anatomy of a big ball of mud, and introduces the two halves of DDD. You will learn how to build a glossary and spot language traps that silently corrupt a model.
- In this lesson:
- Course Overview
- Why Architecture Matters
- Course Roadmap
- Anatomy of a Big Ball of Mud
- What Is Domain-Driven Design?
- The Two Halves of DDD
- The Ubiquitous Language
- Ubiquitous Language in Code
- Language Traps
- Building a Glossary
Subdomains Bounded Contexts and Context Mapping
2Subdomains Bounded Contexts and Context Mapping23 min
- Classifies subdomains as Core, Supporting, or Generic and distinguishes them from bounded contexts. Walks through every context mapping pattern — Partnership, Shared Kernel, Customer-Supplier, Conformist, Anticorruption Layer, Open Host Service — and shows how to read a full context map.
- In this lesson:
- Subdomains: Core, Supporting, Generic
- Invest in the Core Domain
- Bounded Context
- Subdomain vs Bounded Context
- Context Mapping: Overview
- Partnership and Shared Kernel
- Customer-Supplier and Conformist
- Anticorruption Layer
- Open Host Service and Published Language
- Reading a Context Map
Event Storming and Finding Boundaries
3Event Storming and Finding Boundaries14 min
- Teaches the Event Storming notation, how to run a session, and how to turn a wall of orange events into bounded context boundaries. Includes a full worked example on a task-management domain.
- In this lesson:
- Model-Driven Design
- Event Storming: Purpose
- Event Storming: The Notation
- Running the Session
- From Storm to Boundaries
- Worked Example: Task Management
Entities Value Objects and Aggregates
4Entities Value Objects and Aggregates33 min
- Covers identity strategies, value object semantics, and a complete Money implementation. Explains aggregate roots, invariants, the four aggregate design rules, and why small aggregates win, ending with a worked Task aggregate.
- In this lesson:
- Tactical Patterns Overview
- Entities
- Choosing an Identity Strategy
- Value Objects
- Value Object Semantics
- Implementing Money
- Value Objects That Guard Rules
- Entity or Value Object?
- Aggregates
- The Aggregate Root
- Invariants
- Aggregate Design Rules
- Small Aggregates Win
- Referencing Other Aggregates
- Worked Example: The Task Aggregate
Domain Events Repositories and Services
5Domain Events Repositories and Services22 min
- Distinguishes domain events from integration events and shows how to name and shape them. Covers where repository interfaces live, common repository pitfalls, domain services, application services, factories, and how to organize modules and packages.
- In this lesson:
- Domain Events
- Domain Events vs Integration Events
- Naming and Shaping Events
- Repositories
- Where Does the Interface Live?
- Repository Pitfalls
- Domain Services
- Application Services
- Factories
- Modules and Packages
Layered Hexagonal and Onion Architecture
6Layered Hexagonal and Onion Architecture16 min
- Contrasts anemic and rich domain models, then explains layered architecture and the Dependency Rule. Draws the hexagonal and onion shapes, clarifies primary versus secondary adapters, and answers how pure the domain must be when NestJS is involved.
- In this lesson:
- Anemic vs Rich Domain Model
- Layered Architecture
- The Dependency Rule
- Hexagonal Architecture
- Onion Architecture
- Primary vs Secondary Adapters
- Where NestJS Fits
- How Pure Must the Domain Be
CQRS Event Sourcing and Anti-Patterns
7CQRS Event Sourcing and Anti-Patterns10 min
- Explains CQRS, when it pays off, and gives a first look at event sourcing with its consequences for transactions and eventual consistency. Closes by naming the recurring tactical anti-patterns to avoid.
- In this lesson:
- CQRS: Separating Writes from Reads
- When CQRS Pays Off
- Event Sourcing: A First Look
- Transactions and Eventual Consistency
- Tactical Anti-Patterns
NestJS Essentials Modules Controllers and Dependency Injection
8NestJS Essentials Modules Controllers and Dependency Injection20 min
- Installs the toolchain and walks the generated project structure. Covers modules, controllers, providers, custom providers and tokens for repository interfaces, and provider scopes.
- In this lesson:
- Why NestJS
- NestJS Architecture at a Glance
- Installing the Toolchain
- Generated Project Structure
- Modules
- Controllers
- Providers and Dependency Injection
- Custom Providers and Tokens
- Provider Scopes
NestJS Request Pipeline Validation and Tooling
9NestJS Request Pipeline Validation and Tooling25 min
- Works through middleware, pipes, DTOs with class-validator, guards, interceptors, and exception filters in order. Adds configuration, Jest testing, CLI generators, logging, and OpenAPI documentation as a Published Language.
- In this lesson:
- Middleware
- Pipes and Transformation
- DTOs with class-validator
- Guards
- Interceptors
- Exception Filters
- Configuration
- Testing with Jest
- CLI Generators and Libraries
- Logging
- OpenAPI Documentation
Mapping DDD onto NestJS
10Mapping DDD onto NestJS11 min
- Maps DDD layers onto NestJS and presents a reference folder structure. Shows how to write the domain layer in plain TypeScript — identity, value objects, and an aggregate root that raises events — with no decorators or ORM types.
- In this lesson:
- Mapping DDD Layers onto NestJS
- Reference Folder Structure
- The Domain Layer in Plain TypeScript
- Identity in TypeScript
- Value Objects in TypeScript
- The Aggregate Root with Events
CQRS in NestJS Events Commands and Queries
11CQRS in NestJS Events Commands and Queries12 min
- Dispatches domain events with @nestjs/cqrs, implements commands and command handlers, queries and query handlers, and sagas for long-running processes. Ends with the repository interface and its injection token.
- In this lesson:
- Domain Events with @nestjs/cqrs
- Commands and Command Handlers
- Queries and Query Handlers
- Sagas for Long-Running Processes
- The Repository Interface and Token
Persistence Adapters Transactions and the Outbox
12Persistence Adapters Transactions and the Outbox22 min
- Builds a TypeORM adapter and a Mongoose/MongoDB variant, plus mappers between model and persistence. Covers controllers as primary adapters, application service versus command handler, Unit of Work transactions, the Outbox pattern, mapping domain errors to HTTP, and boundary validation versus domain invariants.
- In this lesson:
- TypeORM Adapter
- Mongoose and MongoDB Variant
- Mappers: Model to Persistence
- Controllers as Primary Adapters
- Application Service or Command Handler?
- Transactions and Unit of Work
- The Outbox Pattern
- Domain Errors to HTTP
- Boundary Validation vs Domain Invariants
Testing Adoption and When Not to Use DDD
13Testing Adoption and When Not to Use DDD15 min
- Writes fast domain unit tests and integration/E2E tests, then catalogs the mistakes junior teams repeat when combining DDD and NestJS. Explains incremental adoption, when not to use DDD, and provides a code review checklist.
- In this lesson:
- Testing the Domain
- Integration and E2E Tests
- Common Mistakes When Combining DDD and NestJS
- Adopting DDD Incrementally
- When Not to Use DDD
- Code Review Checklist
Capstone Build It End to End
14Capstone Build It End to End10 min
- Takes a project brief, models the domain, implements the core in plain TypeScript, and wires the adapters. This is the full DDD plus NestJS build in one pass.
- In this lesson:
- Capstone: Project Brief
- Capstone: Modeling the Domain
- Capstone: Implementing the Core
- Capstone: Wiring the Adapters
Performance Team Practices and Wrap-Up
15Performance Team Practices and Wrap-Up13 min
- Addresses mapping overhead and performance concerns, then covers team practices that keep the model alive. Clears up four common misconceptions, lists further reading and reference repositories, and wraps up the course.
- In this lesson:
- Performance and Mapping Overhead
- Team Practices That Keep the Model Alive
- Misconceptions to Drop
- Further Reading
- Reference Repositories
- Course Wrap-Up
Domain-Driven Design (DDD) with NestJS Essentials 2026
Get the course on UdemySold and hosted on Udemy, with Udemy's 30-day refund policy.
This course contains the use of artificial intelligence.