Skip to content

CQRS and Event Sourcing-Based Hotel Management System

Published:

Table of contents

Open Table of contents

Description

This project demonstrates how to build an app that uses CQRS (Command Query Responsibility Segregation) and Event Sourcing patterns using Kotlin, Ktor, Akka, and Cassandra.
It implements hotel reservation management functionality with separate commands for creating, updating, and deleting reservations, along with querying operations to fetch individual or all reservations.

Source code can be found on GitHub.

Actors interaction

Running locally

  1. Clone the repository
git clone https://github.com/martishin/cqrs-akka-kotlin-example.git
cd cqrs-akka-kotlin-example
  1. Start the Cassandra database
docker-compose up cassandra
  1. Build and run the application
./gradlew run
  1. The server will be available at http://localhost:8080.

Making API Requests

You can interact with the system using the following curl commands. You can also execute these REST calls using Postman.

curl -X POST http://localhost:8080/reservations \
  -H "Content-Type: application/json" \
  -d '{
    "guestId": "guest123",
    "startDate": "2023-11-01",
    "endDate": "2023-11-05",
    "roomNumber": 101
  }'
curl -X PUT http://localhost:8080/reservations/{confirmationNumber} \
  -H "Content-Type: application/json" \
  -d '{
    "startDate": "2023-12-01",
    "endDate": "2023-12-05",
    "roomNumber": 102
  }'
  1. Delete the reservation
curl -X DELETE http://localhost:8080/reservations/{confirmationNumber}
  1. Get all reservations
curl -X GET http://localhost:8080/reservations
  1. Get the reservation
curl -X GET http://localhost:8080/reservations/{confirmationNumber}

Testing

Run tests

./gradlew test

Technologies Used