explaingit

ddd-by-examples/library

5,786JavaAudience · developerComplexity · 4/5Setup · moderate

TLDR

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.

Mindmap

mindmap
  root((library DDD))
    What it does
      DDD teaching example
      Real library domain
      Business rules in code
    Architecture
      Hexagonal design
      Bounded contexts
      CQRS read write split
    Tech Stack
      Java
      Spring framework
      ArchUnit tests
    Use cases
      Learn DDD patterns
      Architecture template
      Event Storming output
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Study how real DDD business rules are modeled before starting your own project.

USE CASE 2

Use the hexagonal architecture layout as a template for isolating business logic from Spring and databases.

USE CASE 3

See how Event Storming outputs become bounded contexts and aggregates in working Java code.

USE CASE 4

Learn how ArchUnit enforces architectural boundaries automatically in a test suite.

Tech stack

JavaSpringArchUnitPostgreSQL

Getting it running

Difficulty · moderate Time to first run · 30min

Requires Java, Maven, and a running PostgreSQL database, primary value is reading the code rather than running the app.

In plain English

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.

Copy-paste prompts

Prompt 1
Using ddd-by-examples/library as a reference, design a domain model for my e-commerce system with bounded contexts for orders, inventory, and payments.
Prompt 2
Show me how to implement the Aggregate pattern in Java where a business rule like maximum 5 active holds per patron is enforced inside the aggregate root.
Prompt 3
Write ArchUnit rules that prevent any class in my domain package from importing Spring or database classes.
Prompt 4
Explain how CQRS is applied in ddd-by-examples/library and show me how to add a read model for listing all active holds by patron.
Open on GitHub → Explain another repo

← ddd-by-examples on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.