/3pigs-ddd

DDD & Clean Architecture on the example of The Three Little Pigs

Primary LanguageJava

The Three Little Pigs with DDD and clean architecture

My tech talk, fairy tale sources: 1, 2, 3, 4.

Java 17, Groovy + Spock, Kotlin, Maven, Spring

Web app

App starts as an ordinary web app for

spring.main.web-application-type=servlet

Available operations:

  1. Build house: POST localhost:8080/houses
     {
         "owner": "VERY_LAZY"
     }
    Possible values for owner:
    • VERY_LAZY
    • LAZY
    • NOT_LAZY
    • NOT_LAZY_ANYMORE
  2. Verify the house state: GET localhost:8080/houses/{id}
  3. Blow house down: DELETE localhost:8080/houses/{id}

There is a dedicated Postman collection with all these operations already defined: adapters/src/main/resources/3Pigs.postman_collection.json

Console app

When

spring.main.web-application-type=none

app prints the whole story in the console.


EventStorming

An example.

Big Picture

Big Picture

Design Level - commands, rules & actors

Design Level rules

Design Level - naming aggregates

Design Level aggregates

Possible improvements

  • House could have mechanisms for rebuilding
  • Story can be extended - currently there is nothing about wolf climbing through the chimney and pigs lighting the fire
    • New House method, e.g. litFire
    • New BigBadWolfService method, e.g. comeDownTheChimneyOf
    • Event, e.g. WolfStartedClimbing instead of WolfResignedFromAttacking, new event from House, e.g. WolfEscaped (when burns in the fireplace)
    • WolfStartedClimbing should call both litFire and comeDownTheChimneyOf in a proper order
    • WolfEscaped should result in knowledge sharing
  • Full Event Sourcing - House can be built just from events, no snapshots in the current form