Domain-Driven Design – Starting with a Library Application

Architecturedomain-driven-design

I want to design an online book reader. The first step is describing all the use cases which I have listed below:

  1. I should be able to search a book by title.
  2. I should be able to borrow a book.
  3. I should be able to bookmark a borrowed book.
  4. The system should allow one user per book at a time.
  5. The system should allow to add a new book.
  6. The system should allow to delete an existing book.

That said, I know now I need some Service Objects which would operate on Entities / Value Objects to get the thing done. I am deferring the database design / decision for now as its not considered a good practice. For the similar reasons Delivery mechanisms too is deferred.

After some reading I came to the conclusion that I would need the following:

Services (Algorithms without any states, depends on entities / values)

  1. SearchBook (Takes a title and gives the result back)
  2. BorrowService (Checks if a book can be borrowed)
  3. Member service (Enroll/Unroll members in a library)

Entities (real world mutable objects with unique ID)

  1. Library
  2. Book (ISBN number as a UID)
  3. User (Email as UID, it can be author or reader)

Associations

An author can have many books under his name, a user can only borrow one book at a time. A library can hold many books at a time, it can have many members too.

Notes

  1. For simplicity there will be only single library / store.
  2. No two users can read the same book at a time.

Questions

  1. I am not able to find any value object till now or I am not able to recognize / find it?
  2. I have followed Clean Architecture for some time and helped to build a toy project before. What is the difference between this and DDD?
  3. Am I on the right track?

Best Answer

Did you consider the Book "Implementing Domain Driven Design" by "Vaugh Vernon"? It gives a view on the concepts behind DDD from an implementation perspective with lots of really good real-live examples.

Regarding your explicit questions:

Clean Architecture, as stated by Maciej ChaƂapuk, is orthogonal to DDD. It is a very sound and solid concept to structure your system and gives room for domain modelling concepts like DDD.

I would not put too much thought into the explicit structure of this bounded context. Try to write a very broad acceptance test of a basic use case against the outer system boundary. Try to implement it with the fewest possible interactors while keeping a reasonable separation between the created components. Write Unit Tests if applicable.

I prefer this outside-in approach ("Growing Object Oriented Software, guided by Tests" is a good reference here), since it drives a domain model that is less gold plated and more fitting to the actual use cases.

Related Topic