# Domain Driven Design

Domain driven design (DDD) is a software development approach that induces the implementation of a continuous improvement scenario and can be an extremely useful tool to develop quality software that meets customer needs. Created by Eric Evans, he has a book of patterns based on the author experience with over 20 years developing using Object Oriented techniques.

To maintain focus on the domain, we need to isolate the domain from the other parts of the system.

ExpressWebJs natively supports the domain architectural style of development. Most of the concepts discussed in this documentation, such as dependency injection, controllers, repository, validation, routes, etc apply equally to domain driven design.


📁 App/
📁 Command/
📁 Config/
📁 Database/
📁 Domain/
     📁 Account/       👈 Account domain
         📁 Http/
         📁 Model/
         📁 Events/
         📁 Listeners/
         📁 Exceptions/
         📁 Providers/  
         📁 Repository/
         📁 Service/
         📁 Routes/
     📁 Inventory/      👈 Inventory domain
         📁 Http/
         📁 Model/
         📁 Events/
         📁 Listeners/
         📁 Exceptions/
         📁 Providers/  
         📁 Repository/
         📁 Service/
         📁 Routes/
📁 Logs/
📁 Routes/
📁 Storage/
📁 Utils/
📘 app.ts
⚙️ .env
📘 maker.ts

With this implementation:

  • If there is a bug on the X domain, that will be fixed on X domain
  • If there is a new feature do be implemented in Y domain? that will be done on Y domain
  • If a new developer is in charge of domain Z? the developers will develop inside Z domain
  • The domain W could be uncoupled into a microservice? So take the domain W into a microservice

To get started, run the maker make-domain command with the name of your domain.

This command will first create a Domains directory in your project root directory, then it will create your Accounts domain in the Domains directory.



📁 Domain/
     📁 Accounts/       👈 Accounts domain
         📁 Http/
         📁 Model/
         📁 Events/
         📁 Listeners/
         📁 Exceptions/
         📁 Providers/  
         📁 Repository/
         📁 Service/
         📁 Routes/

To create domain controllers, use the maker domain:make-controller command while specifying the controller name and domain it belongs to:

Here we are creating UserController in Accounts domain.

To create a resource controller in a domain, we add the resource flag r after the domain:make-controller

To create domain model, use the maker domain:make-model command while specifying the model name and domain it belongs to:

Here we are creating User model in Accounts domain.