Skip to content

Library Module

The Library module demonstrates Bus Mode (CQRS) with full CRUD operations for book management. It showcases Commands, Queries, Handlers, Domain Events, and Repository implementations.

Domain Layer

Entity: Book

The Book entity uses Value Objects and an enum for status:

  • Title - Book title with validation
  • Author - Author name with validation
  • ISBN - ISBN-10/ISBN-13 format validation
  • BookStatus - Available or Borrowed

Commands (Write Operations)

Command Purpose
CreateBookCommand Create a new book
UpdateBookCommand Update book details
DeleteBookCommand Remove a book
UpdateBookStatusCommand Change book status

Queries (Read Operations)

Query Purpose Cache TTL
ListBooksQuery Get all books 60s
DetailBookQuery Get single book 300s
CreateBookQuery Data for create form -
UpdateBookQuery Data for edit form -

ListBooksQuery and DetailBookQuery implement CacheableQueryInterface for automatic response caching via CachedQueryBus.

Domain Events

  • BookCreatedEvent - When a book is created
  • BookUpdatedEvent - When a book is updated
  • BookDeletedEvent - When a book is deleted

Routes

Method Path Permission
GET /books Public
GET /books/{id} Public
GET/POST /books/create book.create
GET/POST /books/{id}/edit book.update
POST /books/{id}/delete book.delete

Repository Implementations

  • InMemoryBookRepository - For testing
  • SqliteBookRepository - SQLite persistence
  • MysqlBookRepository - MySQL persistence
  • PostgresqlBookRepository - PostgreSQL persistence

See Also