Skip to main content

Aggregate Design Canvas

As built

Derived from network/model/model.yaml. This context's service is built; the model carries its as-built contracts, and identifiers (Err... names, routes, CloudEvents types) are the names the service uses.

Following the ddd-crew Aggregate Design Canvas v1.1. The model has three aggregate roots: Departure, LaneSchedule and Load. Proposed Go packages: internal/domain/departure, internal/domain/schedule, internal/domain/load (from the ul code identifiers departure.Departure, schedule.LaneSchedule, load.Load).

Departure​

1. Name​

Departure (departure.Departure), identified by departureId.

2. Description​

One scheduled trip on one lane: cutoff, departure, arrival and package capacity. A PICKUP departure starts at a vendor node. Value objects: DepartureKind(PICKUP|LINEHAUL|AIR), Capacity{packages, booked}, Times{cutoffAt, departsAt, arrivesAt}. It is the unit delivery-promise puts on a witness path and order-sourcing names as pickupDepartureId.

3. State Transitions​

Derived from: model.yaml → contexts[linehaul-transportation].aggregates[Departure].states, .transitions, .commands.

Omitted: the creation arrow [*] --> SCHEDULED is ScheduleDeparture, which the model lists as a command but not as a transition (a transition needs a from-state). BookCapacity and ReleaseCapacity are not transitions. ARRIVED and CANCELLED have no outgoing transition in the model, so they are drawn as terminal.

4. Enforced Invariants​

InvariantEnforced by
cutoffAt <= departsAt < arrivesAtErrInvalidDepartureTimes
booked <= capacityErrDepartureFull
The lane is OPEN when schedulingErrLaneClosed (checked against LaneView)
No booking after cutoffAtErrDepartureClosed

5. Corrective Policies​

  • PickupFromCutoffs (this context): on NodeOperationalProfileDeclared, (re)generate PICKUP departures for every cutoff of the horizon; on NodeSuspended or NodeRetired, cancel future pickups (CancelDeparture).
  • BookOnLock (this context): on FulfillmentLocked, book one package on the pickup departure (BookCapacity). FulfillmentCancelled and reassignment release nothing: they happen only before the lock and update the expected volume only (ADR 0002 A16, A28). A lock that carries consolidatedInto (a follower of a merged release) books nothing (FollowerLockBooksNothing): the carrier's lock books the one package that ships.
  • HorizonRoll (this context): nightly GenerateDepartures keeps a 14-day horizon.
  • RepromiseOnRisk (delivery-promise, a neighbour's reaction): a cancelled departure on a witness path makes delivery-promise recompute and RevisePromise.
  • The model names no corrective reaction to LaneClosed for departures already scheduled on that lane; ErrLaneClosed only guards new scheduling.

6. Handled Commands​

CommandIssued by
ScheduleDepartureGenerateDepartures (lane schedules), PickupFromCutoffs
BookCapacityBookOnLock on FulfillmentLocked
ReleaseCapacitythe rebooking inside CancelDeparture only (ADR 0002 A15, A28)
CloseDeparturedriven by CloseLoad (ADR 0002 A21)
RecordDeparturedriven by DispatchLoad (ADR 0002 A21)
RecordArrivaldriven by ReceiveLoad (ADR 0002 A21)
CancelDepartureNetwork-ops planner, REST POST /departures/{departureId}/cancellations; PickupFromCutoffs on NodeSuspended / NodeRetired

7. Created Events​

EventRaised whenFull CloudEvents type
DepartureScheduledScheduleDeparture succeedscom.retailnetwork.logistics.linehaul-transportation.departure.DepartureScheduled
DepartureCapacityChangedBookCapacity succeeds, or a rebooking onto the target departurecom.retailnetwork.logistics.linehaul-transportation.departure.DepartureCapacityChanged
DepartureCancelledCancelDeparture succeedscom.retailnetwork.logistics.linehaul-transportation.departure.DepartureCancelled
DepartureDepartedRecordDeparture succeedscom.retailnetwork.logistics.linehaul-transportation.departure.DepartureDeparted
DepartureArrivedRecordArrival succeedscom.retailnetwork.logistics.linehaul-transportation.departure.DepartureArrived

CloseDeparture raises no event in the model.

8. Throughput​

Estimate (from the model): high on capacity changes. One BookCapacity per locked shipment group lands on one pickup departure, so a popular vendor cutoff is a contended row. Proposed: optimistic concurrency on a version column, retried by the consumer.

9. Size​

Estimate (from the model): lanes × trips per day × horizon (14 days). Each instance is small: a handful of scalars, no child collection. Lifetime: from scheduling (up to 14 days ahead) to arrival; about 2 to 4 events per instance (scheduled, N capacity changes, departed, arrived, or cancelled).

LaneSchedule​

1. Name​

LaneSchedule (schedule.LaneSchedule), identified by laneId (one per lane).

2. Description​

The weekly template that generates departures for one lane, or the node cutoffs for a pickup lane. The model does not list its slot fields; the proposed slot shape (day of week, local cutoff, departure and arrival times, package capacity) mirrors Departure.Times and Departure.Capacity.

3. State Transitions​

Derived from: model.yaml → contexts[linehaul-transportation].aggregates[LaneSchedule].states, .transitions, .commands.

Omitted: the creation arrow is DefineLaneSchedule (a command, not a model transition). Whether DefineLaneSchedule on an ACTIVE schedule replaces its slots is not stated.

4. Enforced Invariants​

InvariantEnforced by
Template slots do not overlap on the same laneErrOverlappingSlots

5. Corrective Policies​

  • HorizonRoll: nightly GenerateDepartures turns every ACTIVE template into departures up to 14 days ahead.
  • The model does not say what happens to already generated departures when a schedule is retired.

6. Handled Commands​

CommandIssued by
DefineLaneScheduleNetwork-ops planner, REST POST /lane-schedules
RetireLaneScheduleREST POST /lane-schedules/{laneId}/retirements (no inbound row names the actor)
GenerateDeparturesScheduler, policy HorizonRoll

7. Created Events​

None (events: []). Its effect is visible through the DepartureScheduled events of the departures it generates.

8. Throughput​

Estimate: low. Planner edits, plus one nightly generation read.

9. Size​

Estimate: one per lane; a weekly template of a few slots.

Load​

1. Name​

Load (load.Load), identified by loadId.

2. Description​

The packages physically consolidated onto one departure at its origin node (for example at a sortation centre, onto a departure to a delivery station). It holds the departureId and the list of tracking numbers.

3. State Transitions​

Derived from: model.yaml → contexts[linehaul-transportation].aggregates[Load].states, .transitions, .commands.

Omitted: the creation arrow is OpenLoad (a command, not a model transition). The model has no cancellation for a load.

4. Enforced Invariants​

InvariantEnforced by
A package is on at most one OPEN or CLOSED loadErrPackageAlreadyLoaded
Package count <= departure capacityErrLoadOverCapacity

Both invariants reach outside one Load instance: the first spans every load, the second reads the departure's capacity. Proposed enforcement: a unique index on the tracking number of packages on non-departed loads, and a capacity snapshot copied from Departure into the load at OpenLoad.

5. Corrective Policies​

  • InductOnArrival (last-mile-delivery, a neighbour's reaction): on LoadArrived at a delivery station it inducts every package into the earliest eligible wave.
  • HandoverOnFirstScan (shipping-and-tracking): the first PICKUP-load departure scan at the vendor node is the handover instant.

6. Handled Commands​

CommandIssued by
OpenLoadOperators, REST POST /loads
AddPackageOperators, REST POST /loads/{loadId}/packages
CloseLoadOperators, REST POST /loads/{loadId}/closures
DispatchLoadOperators, REST POST /loads/{loadId}/dispatches
ReceiveLoadOperators, REST POST /loads/{loadId}/receipts

7. Created Events​

EventRaised whenFull CloudEvents type
LoadClosedCloseLoad succeedscom.retailnetwork.logistics.linehaul-transportation.load.LoadClosed
LoadDepartedDispatchLoad succeedscom.retailnetwork.logistics.linehaul-transportation.load.LoadDeparted
LoadArrivedReceiveLoad succeedscom.retailnetwork.logistics.linehaul-transportation.load.LoadArrived

OpenLoad and AddPackage raise no event.

8. Throughput​

Estimate (from the model): high, per package add. One AddPackage per scanned package; operators on the same load contend on one row.

9. Size​

Estimate (from the model): one per departure. Up to the departure's capacity in tracking numbers; three events per instance.

Read models​

Read modelSource eventsUsed forWhy it is not an aggregate
NodeProfileViewnode-topology NodeRegistered, NodeOperationalProfileDeclared, NodeActivated, NodeSuspended, NodeRetiredNode type, operator, status, time zone, operating hours, holidays and cutoffs for PickupFromCutoffsA local copy of node-topology's Node; this context never changes it and enforces no rule on it.
LaneViewnode-topology LaneOpened, LaneClosedErrLaneClosed check, origin and destination of a lane, modeA copy of node-topology's Lane; the lane's own invariants live there.
ExpectedVolumeVieworder-sourcing FulfillmentReleasedToNode, FulfillmentReassigned, FulfillmentLocked, FulfillmentCancelled; shipping-and-tracking LabelIssuedWhich assignments and tracking numbers are heading for which pickup departure; a follower lock writes no rowA projection of other contexts' facts; it decides nothing. Booking is done on Departure.

Derived from: model.yaml → contexts[linehaul-transportation].read_models.