Skip to main content

Aggregate design canvas

Following the ddd-crew Aggregate Design Canvas (v1.1). Source: internal/domain/departure/departure.go, types.go, events.go; internal/domain/schedule/schedule.go; internal/domain/load/load.go, events.go; internal/domain/volume/volume.go, events.go; internal/application/usecases; ADR 0002. Local read models (NodeView, LaneView) are not aggregates: they are replaced as a whole from consumed events.

Departure​

SectionContent
NameDeparture (root id departureId, a deterministic dep-<hash> of lane, kind, cutoff and generation)
DescriptionOne concrete trip on a lane with a cutoff, a departure and an arrival instant and a package capacity
StateSCHEDULED, CLOSED, DEPARTED, ARRIVED, CANCELLED
State transitionsSCHEDULED -> CLOSED (a load is closed), CLOSED -> DEPARTED (a load is dispatched), DEPARTED -> ARRIVED (a load is received), SCHEDULED -> CANCELLED
Enforced invariantscutoffAt <= departsAt < arrivesAt; 0 <= booked <= capacity (also a CHECK on departures); booking only while SCHEDULED and not after cutoffAt; capacity never below the booked count; a lane must be OPEN to schedule a departure
CommandsSchedule (horizon roll, pickup planning), Book, Release, ChangeCapacity, Close, RecordDeparture, RecordArrival, Cancel
Events raisedDepartureScheduled, DepartureCapacityChanged (booking, release on a SCHEDULED departure, capacity change), DepartureCancelled, DepartureDeparted, DepartureArrived
ErrorsErrInvalidDepartureTimes, ErrDepartureFull, ErrLaneClosed, ErrDepartureClosed, illegal transition
Correlation and concurrencyOptimistic: version is checked on save; a lost race is ErrConcurrentUpdate (409). Bookings inside one transaction share a working set so a departure keeps one version line. A release on a CANCELLED departure raises no event
SizeOne row in departures; a 14-day horizon is generated ahead of every ACTIVE schedule and vendor node

LaneSchedule​

SectionContent
NameLaneSchedule (root id laneId)
DescriptionThe weekly template of one lane: 1 to 100 slots
StateACTIVE, RETIRED; ACTIVE -> RETIRED
Enforced invariantsSlots of one weekday do not overlap; each slot has cutoff <= departs (HH:mm), capacity >= 1; a RETIRED schedule cannot be redefined
CommandsDefine (create), Redefine (replace the slots of an ACTIVE schedule), Retire
Events raisednone (the departures it generates raise DepartureScheduled)
Concurrencyversion; slots are one JSONB array, always read and written whole

Load​

SectionContent
NameLoad (root id loadId, load-<uuid>)
DescriptionThe tracking numbers consolidated on one departure at its origin node
StateOPEN, CLOSED, DEPARTED, ARRIVED; OPEN -> CLOSED -> DEPARTED -> ARRIVED
Enforced invariantsA departure has at most one load (unique loads.departure_id); a tracking number is on at most one OPEN or CLOSED load (partial unique index); package count at most the departure capacity; the departure must be SCHEDULED to open, add to or close the load; 1 to 64 character tracking numbers
CommandsOpen, AddPackage, Close, Dispatch, Receive
Events raisedLoadClosed, LoadDeparted, LoadArrived
ErrorsErrPackageAlreadyLoaded, ErrLoadOverCapacity, ErrLoadAlreadyExists, illegal transition
Concurrencyversion checked on save; the load and its departure change in one transaction (withLoad)

ExpectedVolume​

SectionContent
NameExpectedVolume (root id assignmentId)
DescriptionThe local record of one fulfillment assignment: its node, planned pickup departure, the departure it is booked on and its tracking numbers
StateUNKNOWN (only labels seen), RELEASED, BOOKED, FAILED, CANCELLED
CommandsRelease, Reassign, Cancel, Lock, Book, Rebook, Fail, AddTracking, RemoveTracking
Events raisedBookingMoved, BookingFailed (reasons DEPARTURE_CANCELLED, DEPARTURE_CLOSED, DEPARTURE_FULL, DEPARTURE_UNKNOWN)
Enforced invariantsValid order, node and departure ids; group number >= 1; at most 1000 tracking numbers; one booking per assignment (the lock books once)
Concurrencyversion; every event from order-sourcing and shipping-and-tracking is claimed in processed_events, so a redelivery changes nothing

Policies​

PolicyTriggerCommand
HorizonRollboot, then every GENERATE_INTERVALGenerateDepartures
PickupFromCutoffsnode and lane events; the horizon rollschedule missing pickups, cancel stale unbooked ones
BookOnLockFulfillmentLockedBook on the pickup departure, else rebook or fail