Below is an example of a Mermaid class diagram representing the core classes for our event-based reservation system to visualize the relationships between the entities, services, and events.
classDiagram
%% Domain Entities
class Customer {
+int Id
+string FullName
+string Email
}
class Resource {
+int Id
+string Name
+string Description
}
class Reservation {
+int Id
+int CustomerId
+int ResourceId
+DateTime StartDate
+DateTime EndDate
+ReservationStatus Status
}
%% Service Layer
class ReservationService {
+CreateReservation(customerId: int, resourceId: int, startDate: DateTime, endDate: DateTime) Reservation
+CancelReservation(reservationId: int) bool
}
%% Domain Events
class ReservationCreatedEvent {
+Guid ReservationId
+DateTime CreatedAt
+int CustomerId
}
class ReservationCancelledEvent {
+Guid ReservationId
+DateTime CancelledAt
+int CustomerId
}
%% Event Handling Component
class ReservationEventHandler {
+Handle(event: ReservationCreatedEvent)
+Handle(event: ReservationCancelledEvent)
}
%% Associations
Customer "1" --o "0..*" Reservation : creates
Resource "1" --o "0..*" Reservation : assigned to
ReservationService ..> ReservationCreatedEvent : publishes
ReservationService ..> ReservationCancelledEvent : publishes
ReservationEventHandler ..> ReservationCreatedEvent : handles
ReservationEventHandler ..> ReservationCancelledEvent : handles
%% Note: ReservationStatus is an enumeration (e.g., Pending, Confirmed, Cancelled)
Explanation
Domain Entities:
- Customer, Resource, and Reservation represent the key data structures of the system. A customer creates reservations, and each reservation is associated with a resource.
Service Layer:
- ReservationService encapsulates the business logic for creating and canceling reservations. It interacts with your domain by publishing events when reservations are created or cancelled.
Domain Events:
- ReservationCreatedEvent and ReservationCancelledEvent are immutable records representing changes in the system state. They are used to notify different parts of your application (or even external systems) about key business events.
Event Handling:
- ReservationEventHandler is responsible for processing incoming events. Wolverine’s conventions will help wire up these handlers with the event message flow.
Associations:
- The diagram shows that each customer may have multiple reservations, each resource is linked to potentially many reservations, and the reservation service publishes events consumed by event handlers.
This diagram provides a clear, object-oriented perspective on your system’s core classes and how they interact via services and events.