GithubHelp home page GithubHelp logo

jvalduvieco / cqrs-hotel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from luontola/cqrs-hotel

0.0 2.0 0.0 379 KB

Example application about CQRS and Event Sourcing #NoFrameworks

License: Apache License 2.0

Shell 0.06% CSS 2.12% Java 87.76% JavaScript 9.04% PLpgSQL 0.90% HTML 0.12%

cqrs-hotel's Introduction

CQRS Hotel

Example application demonstrating the use of CQRS and Event Sourcing within the domain of hotel reservations. #NoFrameworks

This project is a sandbox for exploring how CQRS+ES affects the design of a system. The hypothesis is that it will lead to a better design than a typical database-centric approach; a design that is easily testable and does not detiorate as features are added. To answer that question, the problem being solved needs to be complex enough.

This project strives to differ from your typical toy examples in that the problem domain is complex enough to warrant all the techniques being used. The solution has been simplified, but the implemented features are production quality.

Project Status

  • technical features
    • event store
    • aggregate roots (write model)
    • projections (read model)
    • process managers
    • GDPR compliance
  • business features
    • making a reservation
    • room allocation
    • payment
    • check-in, check-out
    • changing the departure date
    • changing the room

Getting Started / Codebase Tour

Here are some pointers for where to look first in the code.

The web application's entry point is index.js and the entry points for each page are in routes.js. The UI is a single-page application which uses React and Redux but otherwise tries to avoid frameworks.

The backend application's main method is in Application.java and the entry points for each operation are in ApiController.java. External dependencies are wired with Spring in Application, but the application core is wired in ApiController constructor. See there the command handlers and query handlers which are the entry point to the business logic.

The framework code is in the fi.luontola.cqrshotel.framework package. It contains in-memory and PostgreSQL implementations of the event store (the latter's PL/SQL scripts are in src/main/resources/db/migration), and base classes for aggregate roots and projections. CQRS with event sourcing requires very little infrastructure code, so you can easily write it yourself without external frameworks, which helps to reduce complexity.

To learn how the write models work, read how a reservation is made, starting from SearchForAccommodationCommandHandler and MakeReservationHandler. The handlers contain no business logic. Instead, they delegate to Reservation which does all the work. Read the AggregateRoot base class, including its documentation, to understand how it should be used.

Of particular interest is how easy it is to unit test event sourced business logic. See SearchForAccommodationTest and MakeReservationTest. The given/when/then methods are in the simple AggregateRootTester base class.

To learn how the read models work, read ReservationsView and the base class Projection. Unit testing is again simple: ReservationsViewTest. Unlike aggregate roots, projections can listen to all events in the system; for example CapacityView is based on events from both Rooms and Reservations.

Running

You must have installed Java 8, Maven 3.2.5, Node.js 6.8.0, Yarn 1.0, Docker 1.12 or higher versions of those. The project can be built with the ./build.sh script. Below are the commands for developing this project.

Start the database:

docker-compose up -d db

Start the application:

mvn spring-boot:run

Start the web frontend:

yarn install
yarn start

The application will run at http://localhost:8080/

More Resources

This example was mostly inspired by the following resources.

For more resources visit Awesome Domain-Driven Design. Ask questions at the DDD/CQRS discussion group.

cqrs-hotel's People

Contributors

luontola avatar

Watchers

Joan Valduvieco avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.