Skip to content

Commit 1c80150

Browse files
🏗️ refactor(architecture): move events from write slices packages to dedicated one for between slices contracts (#20)
Change caused by LinkedIn discussion: https://www.linkedin.com/feed/update/urn:li:activity:7295062961356771328?commentUrn=urn%3Ali%3Acomment%3A%28activity%3A7295062961356771328%2C7295089102633263104%29&dashCommentUrn=urn%3Ali%3Afsd_comment%3A%287295089102633263104%2Curn%3Ali%3Aactivity%3A7295062961356771328%29 I've given it more thought recently, and indeed events extracted from slices can be more flexible (to do not couple them to their sourced command slice, but treat as API between slices). Especially in cases where the same event can be triggered by two different commands (although this doesn't happen very frequently). I have a case in the project, where I think I should refactor handling the `RecruitCreature`. It should result in two events `CreatureRecruited` and `AvailableCreaturesChanged` instead of just the first one. Then in event handlers to reduce available creatures, I will just handle `AvailableCreaturesChanged` instead of both. What I would potentially modify is to extract the events separately, as a contract (system backbone) between slices, while keeping the rest as it was. The Aggregate and Commands would stay in the write package, as they're only shared between write slices. Rest API, external consumers and commands will be also in the same package, do not spread one slice through "layers" like "domain/application". Of course, everything I mean in the scope of a single Bounded Context.
1 parent e8c0aa3 commit 1c80150

37 files changed

Lines changed: 54 additions & 64 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ Aggregates:
9494

9595
The project follows a Screaming Architecture pattern organized around vertical slices that mirror Event Modeling concepts.
9696

97-
![ScreamingArchitecture](docs/images/ScreamingArchitecture.png)
97+
![ScreamingArchitecture](docs/images/ScreamingArchitectureEvents.png)
9898

9999
The package structure screams the capabilities of the system by making explicit: commands available to users, events that capture what happened, queries for retrieving information, business rules, and system automations.
100100
This architecture makes it immediately obvious what the system can do, what rules govern those actions, and how different parts of the system interact through events.
101101

102-
Each module is structured into three distinct types of slices:
102+
Each module is structured into three distinct types of slices (packages `write`, `read`, `automation`) and there are events (package `events`) between them, which are a system backbone - a contract between all other parts:
103103

104104
### Write Slices
105105
Contains commands that represent user intentions, defines business rules through aggregates, produces domain events, and enforces invariants (e.g., RecruitCreature command → CreatureRecruited event, with RecruitCreaturesNotExceedAvailableCreatures rule).
-87.8 KB
Binary file not shown.
100 KB
Loading

src/main/java/com/dddheroes/heroesofddd/armies/write/addcreature/CreatureAddedToArmy.java renamed to src/main/java/com/dddheroes/heroesofddd/armies/events/CreatureAddedToArmy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.dddheroes.heroesofddd.armies.write.addcreature;
1+
package com.dddheroes.heroesofddd.armies.events;
22

33
import com.dddheroes.heroesofddd.armies.write.ArmyEvent;
44
import com.dddheroes.heroesofddd.shared.Amount;

src/main/java/com/dddheroes/heroesofddd/armies/write/removecreature/CreatureRemovedFromArmy.java renamed to src/main/java/com/dddheroes/heroesofddd/armies/events/CreatureRemovedFromArmy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.dddheroes.heroesofddd.armies.write.removecreature;
1+
package com.dddheroes.heroesofddd.armies.events;
22

33
import com.dddheroes.heroesofddd.armies.write.ArmyEvent;
44
import com.dddheroes.heroesofddd.shared.Amount;

‎src/main/java/com/dddheroes/heroesofddd/armies/write/Army.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.dddheroes.heroesofddd.armies.write;
22

33
import com.dddheroes.heroesofddd.armies.write.addcreature.AddCreatureToArmy;
4-
import com.dddheroes.heroesofddd.armies.write.addcreature.CreatureAddedToArmy;
4+
import com.dddheroes.heroesofddd.armies.events.CreatureAddedToArmy;
55
import com.dddheroes.heroesofddd.armies.write.addcreature.CanHaveMax7CreatureStacksInArmy;
6-
import com.dddheroes.heroesofddd.armies.write.removecreature.CreatureRemovedFromArmy;
6+
import com.dddheroes.heroesofddd.armies.events.CreatureRemovedFromArmy;
77
import com.dddheroes.heroesofddd.armies.write.removecreature.CanRemoveOnlyPresentCreatures;
88
import com.dddheroes.heroesofddd.armies.write.removecreature.RemoveCreatureFromArmy;
99
import com.dddheroes.heroesofddd.shared.Amount;

‎src/main/java/com/dddheroes/heroesofddd/astrologers/automation/whenweekstartedthenproclaimweeksymbol/WhenWeekStartedThenProclaimWeekSymbolProcessor.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import com.dddheroes.heroesofddd.astrologers.write.MonthWeek;
55
import com.dddheroes.heroesofddd.astrologers.write.proclaimweeksymbol.ProclaimWeekSymbol;
6-
import com.dddheroes.heroesofddd.calendar.write.startday.DayStarted;
6+
import com.dddheroes.heroesofddd.calendar.events.DayStarted;
77
import com.dddheroes.heroesofddd.shared.GameMetaData;
88
import org.axonframework.commandhandling.gateway.CommandGateway;
99
import org.axonframework.config.ProcessingGroup;

‎src/main/java/com/dddheroes/heroesofddd/astrologers/automation/whenweeksymbolproclaimedthenincreasedwellingavailablecreatures/WhenWeekSymbolProclaimedThenIncreaseDwellingAvailableCreaturesProcessor.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.dddheroes.heroesofddd.astrologers.automation.whenweeksymbolproclaimedthenincreasedwellingavailablecreatures;
22

3-
import com.dddheroes.heroesofddd.astrologers.write.proclaimweeksymbol.WeekSymbolProclaimed;
4-
import com.dddheroes.heroesofddd.creaturerecruitment.write.builddwelling.DwellingBuilt;
3+
import com.dddheroes.heroesofddd.astrologers.events.WeekSymbolProclaimed;
4+
import com.dddheroes.heroesofddd.creaturerecruitment.events.DwellingBuilt;
55
import com.dddheroes.heroesofddd.creaturerecruitment.write.changeavailablecreatures.IncreaseAvailableCreatures;
66
import com.dddheroes.heroesofddd.shared.GameMetaData;
77
import org.axonframework.commandhandling.gateway.CommandGateway;

src/main/java/com/dddheroes/heroesofddd/astrologers/write/proclaimweeksymbol/WeekSymbolProclaimed.java renamed to src/main/java/com/dddheroes/heroesofddd/astrologers/events/WeekSymbolProclaimed.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.dddheroes.heroesofddd.astrologers.write.proclaimweeksymbol;
1+
package com.dddheroes.heroesofddd.astrologers.events;
22

33
import com.dddheroes.heroesofddd.astrologers.write.AstrologersEvent;
44
import com.dddheroes.heroesofddd.astrologers.write.AstrologersId;

‎src/main/java/com/dddheroes/heroesofddd/astrologers/write/Astrologers.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.dddheroes.heroesofddd.astrologers.write.proclaimweeksymbol.OnlyOneSymbolPerWeek;
44
import com.dddheroes.heroesofddd.astrologers.write.proclaimweeksymbol.ProclaimWeekSymbol;
5-
import com.dddheroes.heroesofddd.astrologers.write.proclaimweeksymbol.WeekSymbolProclaimed;
5+
import com.dddheroes.heroesofddd.astrologers.events.WeekSymbolProclaimed;
66
import org.axonframework.commandhandling.CommandHandler;
77
import org.axonframework.eventsourcing.EventSourcingHandler;
88
import org.axonframework.modelling.command.AggregateCreationPolicy;

0 commit comments

Comments
 (0)