Skip to main content
CF

Clean Architecture & Domain-Driven Design in NestJS

12h 21m 25s
English
Paid
Added to CourseFlix

Clean Architecture & Domain-Driven Design in NestJS is a 80-lesson 12 hours 21 minutes self-paced course by Michael Guay, Udemy. Course on Clean Architecture and Domain-Driven Design in NestJS will help you transition from simple CRUD applications to designing a real backend in Node.

Course facts

Lessons
80
Duration
12 hours 21 minutes
Language
English
Added to CourseFlix
November 2026
Instructor
Michael Guay, Udemy
Price
Premium

Course on Clean Architecture and Domain-Driven Design in NestJS will help you transition from simple CRUD applications to designing a real backend in Node.js, where business logic is isolated from the framework, database, and external services, is easily testable, and does not break when requirements change.

In practice, you will create a complete e-commerce system on NestJS from scratch with products, customers, orders, payments, email notifications, and Stripe integration. The project will be divided into autonomous Bounded Contexts, and the application architecture will be built around the principles of Domain-Driven Design, Clean Architecture, CQRS, and Ports & Adapters.

What this course is about

This course focuses on backend development beyond the standard CRUD. You will learn how to design an application so that controllers, ORM, database, Stripe, Mailtrap, and other infrastructure details do not dictate the structure of the business logic.

Instead of distributing rules across controllers, services, and repositories, you will learn to build a rich domain model: aggregates, entities, and Value Objects will ensure the correctness of the system state, while the application layer will coordinate usage scenarios through commands, queries, and handlers.

What you will learn

  • Design a backend in NestJS with separation into domain, application, infrastructure, and presentation layers.
  • Apply Clean Architecture in a real NestJS project, not just in abstract diagrams.
  • Develop a domain model following the principles of Domain-Driven Design: aggregates, entities, Value Objects, invariants, and business rules.
  • Identify Bounded Contexts and build boundaries between modules of the e-commerce system.
  • Implement CQRS with commands, queries, and handlers based on @nestjs/cqrs.
  • Use domain events and sagas to coordinate business processes between contexts.
  • Apply the Ports & Adapters approach so that business logic is not dependent on PostgreSQL, MongoDB, Stripe, Mailtrap, or other external services.
  • Implement business invariants and state machines within aggregates, rather than smearing rules across services.
  • Integrate payments with Stripe and handle webhook events without breaking architectural boundaries.
  • Send email notifications via Mailtrap with a replaceable infrastructure adapter.
  • Create a REST API with DTO, validation, and pass actions to the application through commands.
  • Test domain logic separately from NestJS, databases, and external APIs.

What you will create in practice

Throughout the course, you will develop an e-commerce backend, divided into several independent bounded contexts. Each context will have its own model, rules, and architectural boundaries.

Context of Products

You will implement product management and their domain logic: creation, modification, data correctness checks, and state protection using Value Objects and entities.

Context of Customers

You will create a customer model and discuss how to separate customer data and rules from the rest of the system to ensure the customer context does not become a collection of random DTOs and tables.

Context of Orders

You will model the order lifecycle, its statuses, business invariants, and state transitions. Special attention is given to how the order aggregate protects itself from incorrect operations.

Context of Payments

You will integrate payments via Stripe, implement webhook event handling, and link payment to the order lifecycle through domain events and sagas.

Key topics of the course

Domain-Driven Design in NestJS

You will study DDD not as a set of terms but as a practical approach to organizing code. Using an e-commerce system as an example, you will discuss where business rules should reside, how to build aggregates, and why the domain model should not depend on ORM, controllers, and REST API.

Clean Architecture

The course shows how to implement clean architecture in a NestJS project: the domain layer does not know about the infrastructure, the application layer describes use cases, and adapters handle working with databases, payments, notifications, and external services.

CQRS and Command Handlers

You will separate data modification and reading operations using CQRS. Commands describe the intention to change the system, handlers execute scenarios, and queries handle data retrieval without mixing business operations and reading.

Domain Events and Sagas

You will add events that reflect important business facts: order created, payment initiated, payment successful. Then, using sagas, you will organize processes between contexts, such as automatic payment creation after order placement and order confirmation after successful payment.

Ports & Adapters

You will learn to design interfaces and adapters so that the infrastructure can be replaced without rewriting the domain. For example, PostgreSQL on Drizzle can be replaced with MongoDB, and console notifications can be swapped for email sending through Mailtrap.

Invariants and State Machines

You will study how aggregates control permissible state transitions. Rather than checking rules in different services, you will embed critical business logic within the model, preventing the system from transitioning into an incorrect state.

Program and learning sequence

  1. Analysis of issues in typical CRUD approach in NestJS.
  2. Designing application layers using Clean Architecture.
  3. Creating Value Objects and protecting primitive values.
  4. Designing entities and aggregates based on DDD.
  5. Implementing business invariants and state change rules.
  6. Identifying Bounded Contexts for products, customers, orders, and payments.
  7. Implementing CQRS: commands, queries, and handlers.
  8. Implementing repositories through ports and infrastructure adapters.
  9. Connecting PostgreSQL and Drizzle without domain dependency on the database.
  10. Adding domain events and sagas.
  11. Integrating Stripe and handling webhook events.
  12. Connecting Mailtrap for sending email notifications.
  13. Creating a clean REST API with DTO and validation.
  14. Final assembling of the e-commerce backend with isolated business logic.

Why this approach is important

In small projects, CRUD may suffice, but as requirements grow, business logic often ends up scattered between controllers, services, ORM models, and external event handlers. This complicates testing, increases coupling, and makes changes risky.

Clean Architecture and DDD help solve this problem: business rules become the core of the system, while the framework, database, and external APIs turn into replaceable implementation details. This approach is especially useful for long-lived backend projects, where requirements change, and the codebase needs to remain manageable.

Technologies and tools

  • NestJS — the main backend framework for the course.
  • TypeScript — the language used for developing domain and application logic.
  • @nestjs/cqrs — implementation of commands, queries, handlers, events, and sagas.
  • PostgreSQL — the relational database for the practical project.
  • Drizzle — working with the database on the infrastructure level.
  • Stripe — payment integration and webhook event handling.
  • Mailtrap — sending and testing email notifications.
  • REST API — presentation layer with DTO and validation.

Who this course is for

  • Intermediate level backend developers who can already create CRUD applications and want to design more resilient systems.
  • NestJS and Node.js developers who have heard of DDD, CQRS, and Clean Architecture but want to see their application in a full-fledged project.
  • TypeScript developers who want to deepen their understanding of backend application architecture and business logic handling.
  • Developers preparing for roles such as Senior Developer or Software Architect, where it is essential to design the domain model, system boundaries, and module interactions.

Knowledge requirements

  • Confident knowledge of TypeScript: classes, interfaces, types, modules, async/await.
  • Basic knowledge of NestJS: modules, controllers, providers, dependency injection.
  • Understanding of REST API fundamentals and backend development.
  • Installed Node.js and access to PostgreSQL — locally or through Docker.
  • Previous experience with DDD, CQRS, or Clean Architecture is not required: key concepts are explained gradually from scratch.

What you will gain

After completing the course, you will have not just an educational example, but a practical architecture template for complex NestJS applications. You will be able to apply DDD, Clean Architecture, and CQRS in projects where long-term support, testability, and independence of business logic from infrastructure are important.

You will understand how to make architectural decisions consciously: where to place business rules, when to introduce aggregates, how to separate contexts, why domain events are needed, and how not to turn a NestJS application into a set of interconnected services without a clear model.

Frequently Asked Questions

Is the course suitable for beginners in backend development?

The course is better suited for those already familiar with TypeScript and the basic capabilities of NestJS. If you have never written backend applications, you should first learn the basics of Node.js, REST API, and NestJS.

Is experience in Domain-Driven Design required?

No. The main concepts of DDD are explained as the project develops: Value Objects, entities, aggregates, invariants, domain events, and Bounded Contexts are introduced gradually.

Will there only be theory?

No. The course is structured around practical development of an e-commerce backend. Theory is immediately applied in code, and each pattern appears when it is truly needed for the project.

Can these approaches be used in work projects?

Yes. The architectural solutions in the course are applicable for commercial backend systems in NestJS, especially if the project involves complex business logic, integrations, payments, events, and multiple domains.

Who teaches Clean Architecture & Domain-Driven Design in NestJS?

Michael Guay

Michael Guay thumbnail

Michael Guay is a US software engineer and prolific independent instructor publishing course material on the .NET / C# stack and the modern web frameworks adjacent to it.

The course catalog covers C# and .NET fundamentals, ASP.NET Core for back-end development, Entity Framework for data access, Blazor for full-stack C# web applications, plus the surrounding tooling and deployment patterns. The teaching style is patient and project-oriented, with each course typically building a working application end-to-end.

The CourseFlix listing under this source carries over 20 Michael Guay courses spanning that range. Material is paid and aimed at developers picking up the .NET stack or extending their existing .NET experience into newer parts of the platform.

Udemy

Udemy thumbnail

Udemy is the largest open marketplace for online courses on the internet. Founded in 2010 by Eren Bali, Oktay Caglar, and Gagan Biyani and headquartered in San Francisco, the company went public on the Nasdaq in 2021 under the ticker UDMY. The platform hosts well over two hundred thousand courses across software development, IT and cloud, data science, design, business, marketing, and creative skills, taught by tens of thousands of independent instructors. Roughly seventy million learners use it worldwide, and the corporate arm — Udemy Business — supplies a curated subset of that catalog to enterprise customers.

Because Udemy is a marketplace rather than a single editorial publisher, the catalog is uneven by design. The strongest material lives in the long-form, project-based courses authored by working engineers — full-stack JavaScript, React, Node.js, Python data science, AWS, Docker and Kubernetes, mobile development with Flutter and React Native, and cloud certification preparation. The CourseFlix listing under this source is the slice of that catalog that has been mirrored here for offline-friendly viewing, organized by topic and updated as new releases land. Pricing on Udemy itself swings dramatically with the site's near-permanent sales, which is why the platform is best treated as a deep reference catalog: pick instructors with strong reviews and a track record of updating their material rather than buying on the headline price alone.

What lessons are included in Clean Architecture & Domain-Driven Design in NestJS?

This is a demo lesson (10:00 remaining)

Watch the first 10 minutes free. One payment unlocks all 80 lessons here and every other premium course. No auto-renew.

View Pricing
0:00
/
#1: 1 - Introduction
All Course Lessons (80)
#Lesson TitleDurationAccess
1
1 - Introduction Demo
02:08
2
2 - Overview
01:14
3
3 - Requirements
01:13
4
4 - Clean Architecture
13:21
5
5 - Ports & Adapters
05:05
6
7 - Setup
02:56
7
8 - Shared Domain - Part 1
10:28
8
9 - Shared Domain - Part 2
10:38
9
10 - MongoDB
12:47
10
11 - Drizzle ORM
09:36
11
12 - Product Identifier & Sku
14:49
12
13 - Product Entity
12:27
13
14 - Product Repository Port
06:14
14
15 - Drizzle Product Adapter
04:26
15
16 - Product Schema
08:43
16
17 - Drizzle Product - Save
08:05
17
18 - Drizzle Product - Find
10:54
18
19 - Product Controller & DTOs
14:17
19
20 - Create Product Command
10:44
20
21 - Create Product Handler
07:43
21
22 - Drizzle Kit Migrations
06:47
22
23 - Create Product Testing
03:16
23
24 - Get Products
12:23
24
25 - Application Exceptions
19:56
25
26 - Domain Exceptions
05:39
26
27 - Get Product
09:57
27
28 - Delete Product
06:25
28
29 - MongoDB Product Repository
09:35
29
30 - MongoDB Repository Methods
09:35
30
31 - Dynamic Database Provider
08:11
31
32 - Customer Entity
14:33
32
33 - Customer Repository Port
03:32
33
34 - Customer Schema
07:03
34
35 - Customer - Save
05:19
35
36 - Customer - Find
07:44
36
37 - Customer Controller - Register
08:09
37
38 - Register Customer Handler
13:29
38
39 - Get & Delete Customer
14:45
39
40 - Notification Port
06:33
40
41 - Customer Registered Event
07:08
41
42 - Customer Registered Handler
08:50
42
43 - Mailtrap
04:13
43
44 - Nodemailer Adapter
08:13
44
45 - Email Provider
04:22
45
46 - Order Entity
04:14
46
47 - Order Status Invariance
13:39
47
48 - Shipping Address
08:24
48
49 - Order Item
14:03
49
50 - Order Entity Model
10:30
50
51 - Order Repository Port
02:16
51
52 - Order Schema
14:00
52
53 - Order Repository Adapter - Save
06:38
53
54 - Order Item Repository Adapter - Save
11:01
54
55 - Order Repository Adapter - Find One
10:16
55
56 - Order Relations & Finds
10:56
56
57 - Orders Controller
08:23
57
58 - Order Response
10:42
58
59 - Place Order Handler
13:43
59
60 - Customer & Product Port
11:29
60
61 - Order Placed Event
08:43
61
62 - Get Orders
13:35
62
63 - Confirm Order
10:44
63
64 - Order Confirmed Event
08:32
64
65 - Ship Order
13:47
65
66 - Deliver Order
08:57
66
67 - Cancel Order
10:33
67
68 - Order Discount
05:53
68
69 - Payment Status
06:26
69
70 - Payment Entity
07:46
70
71 - Payment Schema
07:47
71
72 - Drizzle Payment Adapter
09:36
72
73 - Payment Gateway Port
04:10
73
74 - Stripe Setup
02:20
74
75 - Stripe Payment Adapter
12:34
75
76 - Create Payment Handler - Part 1
15:16
76
77 - Order Pricing Adapter
10:31
77
78 - Create Payment Handler - Part 2
13:05
78
79 - Stripe Webhooks
13:47
79
80 - Confirm Payment
24:00
80
81 - Order Fulfillment Saga
09:44
Watch the other 79 lessons

One payment unlocks this course and every other premium course. No auto-renew.

See plans

What courses are similar to Clean Architecture & Domain-Driven Design in NestJS?

More courses by Michael Guay

Frequently asked questions

Should I already know NestJS before starting?
You'll get more out of the course if you're already comfortable building a basic Node.js backend and understand how NestJS controllers and services fit together. The project starts from scratch, but the main challenge is architectural: deciding where business rules belong and how different layers communicate. If you've built a CRUD application and started struggling with logic scattered across services and repositories, you'll have a useful reference point for the problems being addressed.
What will I actually build while following along?
You'll build an e-commerce backend with products, customers, orders, payments, and email notifications, including a Stripe integration. The work goes beyond adding endpoints: you'll model rules around things such as order state, connect persistence through repository adapters, and coordinate application actions with commands and handlers. The project is divided into bounded contexts, so you'll also practice deciding which parts of the business should own their own models and responsibilities.
How is this different from another NestJS CRUD tutorial?
The difference is where you put the application's rules. Rather than treating controllers, services, and database models as the whole design, you'll work with a separate domain model and an application layer that coordinates use cases. Entities, value objects, and aggregates give business rules a home outside the framework. You'll still implement familiar operations such as creating and fetching products, but those operations become a way to practice Clean Architecture, CQRS, and dependency boundaries.
Which database and external services will I work with?
You'll work with Drizzle ORM and MongoDB, including product repository implementations and a dynamic database provider. On the integration side, the project uses Stripe for payments and Mailtrap with a Nodemailer adapter for email. These tools aren't just setup details: you'll practice placing persistence and notification code behind ports and adapters, so the domain doesn't have to depend directly on a particular database or email implementation.
Will I build a storefront too, or is the work mainly on the backend?
You should approach this as a backend architecture course, not a storefront-building course. The practical work centers on NestJS, domain models, application handlers, persistence, payments, and notifications. A complete e-commerce backend is the project, but that doesn't mean you should expect a shopping interface or browser-side checkout implementation. If your main goal is designing product pages or learning a frontend framework, this isn't aimed at that part of the stack.
How much time should I set aside if I want to code along?
There's 12 hours and 21 minutes of video across 80 lessons. That's the viewing time, not a reliable estimate for finishing the project yourself. If you code along, you'll need additional time to set things up, work through the implementations, and revisit architectural decisions. A useful way to pace yourself is to stop after a feature or architectural boundary and check that you understand why the code belongs in that layer before continuing.
Will these ideas still help if my next project doesn't use NestJS?
Yes—the architectural ideas extend beyond NestJS, even though that's the framework you'll use here. Separating business rules from infrastructure, defining repository ports, and coordinating use cases through an application layer are approaches you can carry into other backends. The bounded-context work also gives you practice drawing boundaries around business responsibilities. You'll still need to adapt the implementation to another framework; the transferable part is the reasoning about dependencies and ownership, not every piece of framework-specific code.