Study how real DDD business rules are modeled before starting your own project.
Use the hexagonal architecture layout as a template for isolating business logic from Spring and databases.
See how Event Storming outputs become bounded contexts and aggregates in working Java code.
Learn how ArchUnit enforces architectural boundaries automatically in a test suite.
Requires Java, Maven, and a running PostgreSQL database, primary value is reading the code rather than running the app.
ddd-by-examples/library is a Java project that serves as a teaching example for a software design approach called Domain-Driven Design, or DDD. Rather than showing abstract patterns in isolation, it works through a real-world scenario: a public library system where patrons browse a catalogue, place holds on books, check them out, and return them. The goal is to show how the theory of DDD maps to actual code. The library domain has real rules built in. Regular patrons can hold up to five books at once, researcher patrons have no limit and can also access restricted books. Holds can be open-ended (active until checkout) or closed-ended (they expire after a set number of days if not completed). A patron with more than two overdue checkouts at a given branch cannot place new holds at that same branch. These rules were not invented to make the code look interesting, they represent the kind of business constraints a real library system would enforce. The design process itself is documented. The team started with a technique called Event Storming: a group session where participants map out everything that happens in a system before writing any code. That exercise produced a map of bounded contexts, which are distinct areas of the system that each have their own logic and language. The lending context is the most complex one and uses a full domain model with hexagonal architecture to keep business logic isolated from the Spring framework, databases, and other infrastructure. Simpler contexts use plain CRUD-style code where the complexity does not justify more structure. The project also demonstrates patterns like aggregates, domain events, and a separation of read and write models (CQRS). ArchUnit, a library that enforces architectural rules automatically during testing, is used to verify that the code stays within its intended structure. The full README is longer than what was shown.
← ddd-by-examples on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.