- The primary goal of DDD is to map real-world systems or processes into software artifacts
domain typically refers to the business logic and rules.
- problem that the project is being developed for, in a e-commerce domains are sales, customer management.
terms and definitions used by the entire team, both technical and nontechnical.
- Ubiquitous Language means to create a language that words and phrases from domain used in the codebase, language that can be understood by business experts and developers
Bounded Contexts are used to manage large domain models by dividing them into distinct sections.
- This approach groups similar components and concepts minimizing confusion
-
E-commerce System
- Order Management Context: Handles orders, payment processing, and shipping details. Concepts like Order, Payment, and Shipment are grouped here.
- Product Catalog Context: Manages products, categories, and inventory. Concepts like Product, Category, and Stock belong here.
- User Management Context: Deals with user accounts, authentication, and profiles. Concepts like User, Role, and Permission are grouped here.
-
Healthcare System
- Patient Management Context: Handles patient records, appointments, and histories. Concepts like Patient, MedicalHistory, and Appointment are part of this context.
- Billing Context: Manages invoices, payments, and insurance claims. Concepts like Invoice, Payment, and Insurance are grouped here.
- Diagnostics Context: Focuses on lab tests and results. Concepts like LabTest and Result are grouped here.
-
Banking System
- Account Management Context: Deals with accounts, balances, and transactions. Concepts like Account, Transaction, and Balance are grouped here.
- Loan Management Context: Manages loans, repayments, and interest rates. Concepts like Loan, Repayment, and Interest belong to this context.
- Fraud Detection Context: Handles monitoring and identifying fraudulent activities. Concepts like FraudAlert and RiskScore are grouped here.
By clearly dividing these contexts, each team can work independently without creating conflicts or confusion around shared terms like User or Account. Let me know if you'd like more examples or details!
- It is the biggest zone/area/place where a term has a consistent meaning (it means the same thing for the business specialists and the developers).
domain layer contains the business logic and rules that define the application's behavior.
- this layer is where abstractions are made, the design of interfaces are included in the domain layer.
- An important factor is that objects do not have too many technical details.
- should be written using the ubiquitous language
application layer coordinates the interactions between the domain and infrastructure layers.
- It is the layer where business process flows are handled
- Could also be seen as the service layer of your application
infrastructure layer provides the necessary services and infrastructure for the application, such as databases, message queues, and web servers.
- The infrastructure layer is responsible for communication with external websites, access to data (persistence storage) or to other resources.
UI layer provides the interface for users to interact with the application.
- This layer is the part where interaction with external world happens.
- it can be a cli, website...
One of the key features of Layered Architecture is that the dependencies between layers are inward-facing. This means that higher-level layers can only depend on lower-level layers. For example, the domain layer can only depend on other code within the domain layer. The application layer can depend on the domain layer and other code within the application layer, but it cannot depend on the UI layer.
group of objects that treated as a single unit, all the object are consistent
-
For example, an Order Line object doesn't make sense without an Order to belong to, so we say that the Order is the aggregate root.
-
Aggregates focus on enforcing business rules and ensuring that all interactions with the domain happen in a controlled way through the Aggregate Root. This avoids inconsistencies and ensures invariants are always respected.
- Aggregate: Order
- Aggregate Root:
Order
- Components:
OrderItem
,ShippingAddress
,PaymentDetails
- Description: The
Order
is the Aggregate Root, and it ensures consistency, such as verifying that allOrderItems
belong to the same order and the payment is correctly linked. External systems interact only with theOrder
object to modify or query the order.
- Aggregate Root:
- Aggregate: Account
- Aggregate Root:
Account
- Components:
Transaction
,AccountHolder
- Description: The
Account
is the Aggregate Root that enforces rules, such as ensuring transactions do not result in a negative balance unless an overdraft is allowed.
- Aggregate Root:
Entities are object that have unique identifier and lifecycle that are mutable and not equal to each other, like a user record in DB
is an object that carries data between processes.
-
- DTOs are simple objects that should not contain any business logic
-
- but may contain serialization and deserialization mechanisms for transferring data over the wire.
are Immutable and not have unique identifier
used to process and retrieve aggregate, abstraction over data access
encapsulate domain logic that does not belong to a specific entity
used to encapsulated a complex object
used to communicate and capture domain specific information