spring-modulith-with-ddd
spring-modulith-with-ddd copied to clipboard
Modular Monolith architecture demonstration with Spring Modulith and DDD
Building Modular Monolith Applications with Spring Modulith and Domain Driven Design
This repository showcases a Modular Monolith implementation of borrowing books in a library with Spring Boot, Spring Modulith and Domain Driven Design principles.
The code is explained in a series of blog posts.
- Building Modular Monolith Applications with Spring Boot and Domain Driven Design - First attempt at building a Modular Monolith code with only Spring Boot and DDD (does not use Spring Modulith). The code is available in branch part-1-ddd-solution.
- Improving Modular Monolith Applications with Spring Modulith - In this blog, we rethink the domain model and apply eventual consistency with Spring Modulith to make the application easier to test, self-documenting and more maintainable. The code is available in branch part-2-spring-modulith.
-
Adopting Domain-First Thinking in Modular Monolith with Hexagonal Architecture - In this blog, we re-implement the Borrow module with Hexagonal instead of Layered architecture. We demonstrate how absolutely no changes were needed in the Catalog module even though they are part of the same monolith code base. The code is available in branch part-3-hexagonal-architecture and
main
. - TBA - Authentication and Authorization
Project Requirements
- JDK 21
- Spring Boot 3.2
The Business Problem
- The library consists of thousands of books. There can be multiple copies of the same book.
- Before being included in the library, every book receives a barcode stamped at the back or one of the end pages. This barcode number uniquely identifies the book.
- A patron of the library can make a request to place a book on hold by either locating the book in the library or directly going to the circulation desk and ask for a book by title. If book is available, the patron can proceed to checkout (collect) the book.
- The book is checked out for a fixed period of 2 weeks.
- To check in (return) the book, the patron can go to the circulation desk or drop it in the drop zone.
Bounded Contexts
Run the application
Run the application with the command: mvn spring-boot:run
.
Swagger REST API Docs
Access the Swagger UI at http://localhost:8080/swagger-ui.html
Examples
Add book to Library
curl -X POST -H Content-Type:application/json http://localhost:8080/catalog/books \
-d '{"title":"Sapiens","catalogNumber":"12345","isbn":"9780062316097","author":"Yuval Noah Harari"}' | jq
Response:
{
"id": 1,
"title": "Sapiens",
"catalogNumber": {
"barcode": "12345"
},
"isbn": "9780062316097",
"author": {
"name": "Yuval Noah Harari"
}
}
Place a book on hold (start the borrowing process)
curl -X POST -H Content-Type:application/json http://localhost:8080/borrow/holds \
-d '{"barcode": "12345", "patronId": "018dd2f7-b241-7d27-be99-45fb3f145ddf"}' | jq
Response:
{
"id": "8c8702af-9363-4953-94a5-2ddfa5aea631",
"bookBarcode": "12345",
"patronId": "018dd2f7-b241-7d27-be99-45fb3f145ddf",
"dateOfHold": "2024-02-22"
}