gitmyhub

library

Java ★ 5.8k updated 3y ago

A comprehensive Domain-Driven Design example with problem space strategic analysis and various tactical patterns.

A Java teaching project that walks through Domain-Driven Design using a real public library system, showing how business rules like patron holds and checkouts map to actual code.

JavaSpringArchUnitPostgreSQLsetup: moderatecomplexity 4/5

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.

Where it fits