Skip to content

Me learning Java with CQRS, DDD and event sourcing

Notifications You must be signed in to change notification settings

ricklancee/hotelreview

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Learning Java

This is a project to teach myself Java, figure out CQRS and learn more about DDD. The goal of this project is to create an application that is written in domain driven and test driven styles. The goal of the project architecture will be Onion architecture with CQRS and refactored to event sourcing. I will incrementally refactor code supported by tests trying to commit this as cleanly as possible.

Something I like to do is update different bounded context and read models through something like Kafka to ensure eventual consistency. Seperate out the presentation logic from domain logic so that the domain will be lightweight and fully unit tested.

Note: I'm not trying to create a quick and dirty side project; this will be written to be as "production ready" as it can be.

Events

Hotel 
 - HotelWasCreated
 - HotelNameWasChanged
 - HotelAddressWasChanged

Project scratches

This is a dump of information not necessarily documentation

Goals post reviews, add hotels, make some dashboard stuff.

Hotel

Events, commands & actors:

Review domain:
RegisterHotel
HotelRegisterd
HotelManager

PostReview
GuestPlacedAReview
    -> triggers e-mail telling hotel manager a review was placed.
Guest

PostReview
GuestPlacedADraftReview
    -> triggers e-mail telling moderator a review was placed.
Guest

ModerateReview
ReviewModerated
    -> triggers e-mail telling guest review was approved.
    -> changes the review state
Moderator

Invariants:

  1. A review must be approved by a moderator if the reviewer has less than 4 reviews.

Identity Access Domain

User:
    UserRegistered
    UserEmailVerified
    UserPasswordChanged
    UserPassword
    UserProfileUpdated

Domain objects:

Hotel
    Name
    Country
    Address

Review
    hotelId
    authorId
    date
    positives
    negatives
    isDraft --> maybe a DraftReview would be better
    score

Reviewer
    Name
    Nationality
    amountOfReviewsPosted --> used for validation of invariant 1
    ---
    postReview(hotelId, reviewDetails)

Pseudo code:

DomainService: postReview
reviever = reviewerRepo.getById(...)
events = eventStore.getEventsForAggregateId(id)
reviewer.loadFromHistory(events)
loadFromHistory(evts)
e in evts
apply(e)

    Reviewer.postReview(hotelId)
        // protect invariants
        apply(new ReviewWasPosted(...))

    Reviewer.when(ReviewWasPosted)
        // update aggregate state
        amountOfReviewsPosted++

    revieverRepo.save(reviewer)
        eventStore.saveEvents(reviewer.events)
            // project aggregate version against concurrency conflicts
        publisher.publishEvents(reviewer.events)

Data

Simulating around 500k events with data from: https://www.kaggle.com/jiashenliu/515k-hotel-reviews-data-in-europe

References:

Docs:

About

Me learning Java with CQRS, DDD and event sourcing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages