IDDD_Samples
These are the sample Bounded Contexts from the book "Implementing Domain-Driven Design" by Vaughn Vernon: http://vaughnvernon.co/?page_id=168
Top Related Projects
Full Modular Monolith application with Domain-Driven Design approach.
Clean Architecture Solution Template: A starting point for Clean Architecture with ASP.NET Core
Cross-platform .NET sample microservices and container based application that runs on Linux Windows and macOS. Powered by .NET 7, Docker Containers and Azure Kubernetes Services. Supports Visual Studio, VS for Mac and CLI based environments with Docker CLI, dotnet CLI, VS Code or any other code editor. Moved to https://github.com/dotnet/eShop.
A comprehensive Domain-Driven Design example with problem space strategic analysis and various tactical patterns.
Quick Overview
IDDD_Samples is a GitHub repository containing sample code for Implementing Domain-Driven Design (IDDD) patterns and practices. It provides practical examples of DDD concepts in various programming languages, including Java, C#, and Scala, to help developers understand and implement DDD in their projects.
Pros
- Offers concrete implementations of DDD concepts across multiple languages
- Provides real-world examples that demonstrate how to apply DDD principles
- Includes comprehensive documentation and explanations for each sample
- Maintained by Vaughn Vernon, a respected authority in the DDD community
Cons
- Some examples may be outdated or not follow the latest best practices
- Limited coverage of certain DDD patterns or advanced concepts
- May require prior knowledge of DDD to fully understand the samples
- Not actively maintained, with infrequent updates
Code Examples
Here are a few code examples from the Java implementation:
- Defining an Entity:
public class Product extends ConcurrencySafeEntity {
private ProductId productId;
private String name;
private String description;
public Product(ProductId productId, String name, String description) {
this.productId = productId;
this.name = name;
this.description = description;
}
// ... other methods
}
- Implementing a Value Object:
public final class Money implements Serializable {
private final BigDecimal amount;
private final String currency;
public Money(BigDecimal amount, String currency) {
this.amount = amount;
this.currency = currency;
}
// ... other methods
}
- Using a Repository:
public interface ProductRepository {
void add(Product product);
Product productOfId(ProductId productId);
void remove(Product product);
}
Getting Started
To get started with the IDDD_Samples:
-
Clone the repository:
git clone https://github.com/VaughnVernon/IDDD_Samples.git
-
Navigate to the desired language implementation (e.g., Java):
cd IDDD_Samples/iddd_common/src
-
Explore the code samples and accompanying documentation to understand how DDD concepts are implemented in practice.
-
Use the samples as a reference when implementing DDD in your own projects, adapting them to your specific domain and requirements.
Competitor Comparisons
Full Modular Monolith application with Domain-Driven Design approach.
Pros of modular-monolith-with-ddd
- Implements a modular monolith architecture, showcasing a modern approach to DDD
- Provides a more comprehensive example with real-world scenarios and practices
- Includes detailed documentation and architectural decision records (ADRs)
Cons of modular-monolith-with-ddd
- More complex structure, which may be overwhelming for DDD beginners
- Focuses on a specific architectural style, potentially limiting its applicability
- Less variety in domain examples compared to IDDD_Samples
Code Comparison
IDDD_Samples:
public class BacklogItem extends ConcurrencySafeEntity {
private BacklogItemId backlogItemId;
private String summary;
private String category;
private BacklogItemStatus status;
// ...
}
modular-monolith-with-ddd:
public class MeetingGroup : Entity, IAggregateRoot
{
public MeetingGroupId Id { get; private set; }
public string Name { get; private set; }
public string Description { get; private set; }
public MeetingGroupLocation Location { get; private set; }
// ...
}
Both repositories demonstrate DDD concepts, but modular-monolith-with-ddd uses a more modern C# approach with cleaner separation of concerns. IDDD_Samples provides a broader range of examples in Java, which may be beneficial for learning DDD principles across different contexts.
Clean Architecture Solution Template: A starting point for Clean Architecture with ASP.NET Core
Pros of CleanArchitecture
- More focused on .NET and C# specific implementations
- Includes a comprehensive test suite demonstrating best practices
- Provides a ready-to-use template for new projects
Cons of CleanArchitecture
- Less emphasis on Domain-Driven Design (DDD) principles
- Fewer examples of complex domain logic implementations
- More opinionated structure, which may not fit all project types
Code Comparison
IDDD_Samples (Java):
public class BacklogItem extends ConcurrencySafeEntity {
private BacklogItemId backlogItemId;
private String summary;
private String category;
private BacklogItemStatus status;
// ...
}
CleanArchitecture (C#):
public class ToDoItem : BaseEntity
{
public string Title { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public bool IsDone { get; private set; }
public void MarkComplete() => IsDone = true;
}
Both repositories offer valuable insights into software architecture, with IDDD_Samples focusing more on DDD concepts and CleanArchitecture providing a practical .NET implementation. The choice between them depends on the specific needs of the project and the developer's preferred language and framework.
Cross-platform .NET sample microservices and container based application that runs on Linux Windows and macOS. Powered by .NET 7, Docker Containers and Azure Kubernetes Services. Supports Visual Studio, VS for Mac and CLI based environments with Docker CLI, dotnet CLI, VS Code or any other code editor. Moved to https://github.com/dotnet/eShop.
Pros of eShopOnContainers
- Comprehensive microservices architecture demonstration
- Utilizes modern cloud-native technologies (Docker, Kubernetes)
- Includes multiple client applications (Web, Mobile)
Cons of eShopOnContainers
- More complex setup and learning curve
- Less focus on core DDD principles and patterns
- Potentially overwhelming for beginners in DDD
Code Comparison
IDDD_Samples (Java):
@Entity
public class Product extends AbstractEntity {
@Basic(optional = false)
@Column(name = "name", nullable = false)
private String name;
@Basic(optional = false)
@Column(name = "price", nullable = false)
private BigDecimal price;
}
eShopOnContainers (C#):
public class CatalogItem
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
public string PictureFileName { get; set; }
public int CatalogTypeId { get; set; }
public CatalogType CatalogType { get; set; }
public int CatalogBrandId { get; set; }
public CatalogBrand CatalogBrand { get; set; }
public int AvailableStock { get; set; }
}
The IDDD_Samples code focuses on core DDD concepts with a simpler entity structure, while eShopOnContainers demonstrates a more feature-rich, microservices-oriented approach with additional properties and relationships.
A comprehensive Domain-Driven Design example with problem space strategic analysis and various tactical patterns.
Pros of library
- More recent and actively maintained project (last commit in 2023)
- Implements a complete library management system, showcasing DDD in a real-world scenario
- Uses modern Java frameworks like Spring Boot and JPA
Cons of library
- Less comprehensive in terms of DDD patterns and concepts covered
- Focuses on a single domain, potentially limiting its applicability to other contexts
- Smaller community and fewer stars on GitHub
Code Comparison
IDDD_Samples (Aggregate Root):
public class Product extends ConcurrencySafeEntity {
private ProductId productId;
private String name;
private String description;
private Money price;
// ...
}
library (Aggregate Root):
@Aggregate
public class Book {
@AggregateId
private BookId bookId;
private BookType type;
private Title title;
private Author author;
// ...
}
Both examples demonstrate the use of Aggregate Roots, but library uses more modern Java annotations and a more focused domain model.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
These are the sample Bounded Contexts from the book "Implementing Domain-Driven Design" by Vaughn Vernon:
http://vaughnvernon.co/?page_id=168
The models and surrounding architectural mechanisms may be in various states of flux as the are refined over time. Some tests may be incomplete. The code is not meant to be a reflection of a production quality work, but rather as a set of reference projects for the book.
Points of Interest
The iddd_agilepm project uses a key-value store as its underlying persistence mechanism, and in particular is LevelDB. Actually the LevelDB in use is a pure Java implementation: https://github.com/dain/leveldb
Currently iddd_agilepm doesn't employ a container of any kind (such as Spring).
The iddd_collaboration project uses Event Sourcing and CQRS. It purposely avoids the use of an object-relational mapper, showing that a simple JDBC-based query engine and DTO matter can be used instead. This technique does have its limitations, but it is meant to be small and fast and require no configuration or annotations. It is not meant to be perfect.
It may be helpful to make one additional mental note on the iddd_collaboration CQRS implementation. To keep the example simple it persists the Event Sourced write model and the CQRS read model in one thread. Since two different stores are used--LevelDB for the Event Journal and MySQL for the read model--there may be very slight opportunities for inconsistency, but not much. The idea was to keep the two models as close to consistent as possible without using the same data storage (and transaction) for both. Two different storage mechanisms were used purposely to demonstrate that they can be separate.
The iddd_identityaccess project uses object-relational mapping (Hibernate), but so as not to leave it "boring" it provides a RESTful client interface and even publishes Domain-Event notifications via REST (logs) and RabbitMQ.
Finally the iddd_common project provides a number of reusable components. This is not an attempt to be a framework, but just leverages reuse to the degree that code copying doesn't liter each project. This is not a recommendation, but it did work well and save a considerable amount of work while producing the samples.
Usage
Requires
- Java 7 (8+ does not work)
- MySQL Client + Server
- RabbitMQ
Setup (with Docker)
To make it easy to run the tests and it requirements,
the startContainers.sh
script is provided. Which
will start a:
- MySQL Server container
- RabbitMQ Server container
- RabbitMQ Management container
If the mysql
command is available, which is the mysql client,
also the required SQL scripts will be imported into the MySQL
Server.
If you use the startContainers.sh
script, you don't need
MySQL Server and RabbitMQ installed locally. Instead,
Docker needs to be installed as the script will start
MySQL and RabbitMQ in Docker containers.
Build
You can build the project by running:
./gradlew build
This automatically downloads Gradle and builds the project, including running the tests.
The Gradle build using Maven repositories was provided by Michael Andrews (Github michaelajr and Twitter @MichaelAJr). Thanks much!
I hope you benefit from the samples.
Vaughn Vernon Author: Implementing Domain-Driven Design Twitter: @VaughnVernon http://vaughnvernon.co/
Top Related Projects
Full Modular Monolith application with Domain-Driven Design approach.
Clean Architecture Solution Template: A starting point for Clean Architecture with ASP.NET Core
Cross-platform .NET sample microservices and container based application that runs on Linux Windows and macOS. Powered by .NET 7, Docker Containers and Azure Kubernetes Services. Supports Visual Studio, VS for Mac and CLI based environments with Docker CLI, dotnet CLI, VS Code or any other code editor. Moved to https://github.com/dotnet/eShop.
A comprehensive Domain-Driven Design example with problem space strategic analysis and various tactical patterns.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot