Skip to main content

Aggregate Design Canvas

Built, released at v0.1.4, applied to k3s (reduced footprint); MCP and A2A built, not deployed

Built on develop (merged 2026-11-08) in IQVO/yard-management, released at v0.1.4 (first release v0.1.0 on 2026-11-09; applied to the k3s cluster on 2026-11-10 at v0.1.2 in a reduced footprint, and the image pinned to the v0.1.4 commit 44d605e in warehouse-infra since 2026-11-18, checked 2026-12-02): yard-management switches on its API and relay (at the check the relay was 1/1 and the API 0/1 Pending on the NotReady agent node k3s-agent2); dock-scheduling runs its API only (it relays inline). The MCP server (25 tools on develop 3bcfc22, 21 in v0.1.4) is registered in warehouse-infra but switched off until the cluster has room; the A2A agent (two skills) is built on develop (2026-12-02), not released and not deployed (the chart carries it off by default and warehouse-infra has no a2a block); the analytics projectors, report services and sweeps are registered but switched off, so the KPI reports of ADR 0011 are released, not yet served. The page still derives from yard/model/model.yaml; where the as-built service differs, the model and this page say so (see the as-built notes).

Following the ddd-crew Aggregate Design Canvas v1.1. The model has five aggregate roots: YardVisit, Trailer, YardMove, YardCheck and YardPolicy. Go packages, as built: internal/domain/yardvisit, trailer, yardmove, yardcheck, yardpolicy, plus shared (ids, Location, TrailerKind, LoadState, Purpose, SCAC). Ids are <prefix>-<uuid>: visit-, trl-, mv-, yck-; the policy is keyed by the site code. The aggregates are pure Go: Snapshot() and Restore() are the persistence boundary and Restore re-validates.

Common to all: every mutable aggregate carries an optimistic-concurrency version (starts at 1, +1 per accepted change; ETag / If-Match on REST), and errors are ErrNotFound (404), ErrIllegalTransition (409), ErrConcurrentUpdate (409) and ErrValidation (422) plus the domain errors named below. As built the status of a domain error is 409 for a conflict with state, 422 for a value or reference rule and 400 for a malformed request; the problem slug is the kebab-case of the Err name.

YardVisit​

1. Name​

YardVisit (yardvisit.Visit), identified by visitId.

2. Description​

One tractor and driver passing the gate, from check-in to check-out, with the trailers it brings and takes. Value objects: Carrier{name, scac?}, TractorPlate, DriverRef (opaque, no PII), Purpose(DROP|LIVE_UNLOAD|LIVE_LOAD|PICKUP|BOBTAIL), AppointmentRef?, TrailersIn[], TrailersOut[].

3. State Transitions​

Derived from: model.yaml → contexts[yard-management].aggregates[YardVisit].states, .transitions, .commands.

Omitted: the model's only transition is CHECKED_IN → CHECKED_OUT. The two creation arrows are CheckInVisit and RejectAtGate (a command that creates the aggregate has no from-state). A refused CheckInVisit creates nothing; RejectAtGate is the command that records a REJECTED visit (decision Y-5).

4. Enforced Invariants​

InvariantEnforced by
Carrier name non-blank, at most 100 characters; scac 2..4 upper-case letters when givenErrInvalidCarrier
At most one CHECKED_IN visit per tractor plate per siteErrVisitAlreadyOpen
When the site requires appointments, the named appointment is BOOKED for this site in the local copyErrAppointmentRequired
Every trailer taken out is on site and released (not DOCKED, no open move)ErrTrailerNotReleased
Every LOADED trailer taken out on an OUTBOUND purpose carries a sealErrSealRequired

The last two read Trailer and YardMove state, so they cross the aggregate boundary; the use case loads the trailers and checks them in one unit of work. The outbound purposes are LIVE_LOAD and PICKUP (decision Y-9), and a trailer is released when it has no open move and is either PARKED or DOCKED with door work DONE, so a live visit leaves from the door (decision Y-2).

5. Corrective Policies​

  • DirectOnCheckIn (this context): at CheckInVisit, a trailer with an appointment whose door is free, not closed and flow-compatible gets a VISITING_DRIVER move TO_DOOR; otherwise a move to the first free spot of the site's parking zones (by location code; nearest-to-door is phase 2); a walk-in or an arrival earlier than the tolerance goes TO_HOLDING.
  • VisitingDriverMove (this context): the first move of a trailer from the gate is created CLAIMED with performer VISITING_DRIVER (no lease).
  • SealCheckAtGate (this context): a recorded seal that differs from the appointment's expected_seal_number raises SealExceptionRaised; REJECT policy also rejects the visit.
  • ArrivalFromGate (dock-scheduling, a neighbour's reaction): on VisitCheckedIn naming an appointment, it records the arrival.

6. Handled Commands​

CommandIssued by
CheckInVisitGate clerk or kiosk, REST POST /visits
RejectAtGateGate clerk or kiosk, REST POST /visit-rejections
CheckOutVisitGate clerk or kiosk, REST POST /visits/{visitId}/check-outs

7. Created Events​

EventRaised whenFull CloudEvents type
VisitCheckedInCheckInVisit succeedscom.warehouse.wms.yard-management.yardvisit.VisitCheckedIn
VisitRejectedRejectAtGate succeeds (also the REJECT seal outcome)com.warehouse.wms.yard-management.yardvisit.VisitRejected
VisitCheckedOutCheckOutVisit succeedscom.warehouse.wms.yard-management.yardvisit.VisitCheckedOut (analytics only)

8. Throughput​

Estimate (from the model): medium (gate events). One check-in and one check-out per visit, no contended row.

9. Size​

Estimate (from the model): visits/day × retention. Each instance is small: scalars plus the in and out trailer lists. About two events per visit (one for a rejected visit).

Trailer​

1. Name​

Trailer (trailer.Trailer), identified by trailerId.

2. Description​

A towable unit on site (trailer, or container on a chassis): where it is, what it holds, its seal and hold. Value objects: TrailerKind(DRY_VAN|REEFER|FLATBED|CONTAINER), UnitNumber{carrier_scac, number} (natural key on site), LoadState(EMPTY|LOADED|PARTIAL), Contents{asn_numbers[] inbound, outbound_ref?}, Seal{number, state INTACT|BROKEN|NONE}, Hold{reason}, Location{kind SPOT|DOOR, code}, DoorWork(WAITING|IN_PROGRESS|DONE) (only while DOCKED), ArrivedAt (the dwell clock start).

StartMoving and ArriveAt are invoked only by the YardMove use cases (claim and complete), in the same unit of work as the move, the fleet precedent of closing a receipt together with its ASN.

3. State Transitions​

Derived from: model.yaml → contexts[yard-management].aggregates[Trailer].states, .transitions, .invariants, .notes.

Omitted: the creation arrow. RecordArrival creates the trailer IN_MOVE together with its first move, created CLAIMED (decision Y-1). A move that is cancelled or whose lease expires after the claim brings the trailer back through ReturnToOrigin (IN_MOVE to PARKED or DOCKED, where StartMoving found it) in the same unit of work; if that origin has since been taken the trailer stays IN_MOVE and the move REQUESTED. ArriveAt to a spot or a door is one command with two target states; the label says which. RecordSeal, BreakSeal, PlaceHold, ReleaseHold and RecordLoadState do not change the state.

Door work (the three values and the commands, as built):

WAITING → DONE is real: AutoCompleteUnload may complete door work that was never started, once every ASN on the trailer has a closed receipt (decision Y-7); CompleteDoorWork by an operator requires IN_PROGRESS (assumption A11).

4. Enforced Invariants​

InvariantEnforced by
A spot or door holds at most one trailer (domain service Occupancy.CheckFree under a per-location advisory lock, plus a partial unique index)ErrLocationOccupied
The location is a known, active Yard or Dock slot of the trailer's siteErrUnknownLocation
A door under a closure takes no trailerErrDoorClosed
A LOADED inbound trailer docks only at an Inbound or Both door, an outbound one only at an Outbound or Both doorErrDoorFlowMismatch
A trailer on hold is not dockedErrTrailerOnHold
A DOCKED trailer departs only when its door work is DONEErrDoorWorkOpen
The natural key (scac, number) is unique among trailers on siteErrTrailerAlreadyOnSite

The first three and the fourth read other state (other trailers, the LocationView, the DoorClosureView, the door's dockFlow); the use case passes those in. See Occupancy across aggregates.

5. Corrective Policies​

  • CallToDoor (this context): on TrailerUndocked, the next BOOKED or CHECKED_IN appointment of that door whose trailer is PARKED gets a HOSTLER move TO_DOOR, due_by = window_start, priority by window_start.
  • AutoCompleteUnload (this context): on inbound-receiving ReceiptClosed for a receipt opened on an appointment whose trailer is DOCKED, CompleteDoorWork and set load_state EMPTY.
  • ClearDoorAfterWork (this context): on DoorWorkCompleted, a DROP trailer gets a HOSTLER move FROM_DOOR to a free spot; a LIVE trailer stays until its visit checks out.
  • SealCheckAtGate (this context): see YardVisit.
  • DwellSweep (this context): POST /dwell-sweeps raises TrailerDwellExceeded once per trailer and threshold crossing.
  • ActualDoorWins (dock-scheduling, a neighbour's reaction): on TrailerDocked at a door other than the booked one, it reassigns the door.
  • CompleteOnDoorRelease (dock-scheduling): on TrailerUndocked naming an appointment, it completes the appointment.

6. Handled Commands​

CommandIssued by
RecordArrivalCheckInVisit (one per trailer in TrailersIn, and one appointment covers exactly one trailer); no route of its own
StartMovingClaimNextMove use case, same unit of work as the claim
ArriveAtCompleteMove use case, same unit of work as the completion
StartDoorWorkDock operator, REST POST /trailers/{trailerId}/door-work-starts
CompleteDoorWorkDock operator, REST POST /trailers/{trailerId}/door-work-completions; AutoCompleteUnload
RecordSealYard supervisor, REST POST /trailers/{trailerId}/seals
BreakSealRecordSeal with state BROKEN, which also places a SEAL_BROKEN hold (decision Y-6); no route of its own
PlaceHoldYard supervisor, REST POST /trailers/{trailerId}/holds
ReleaseHoldYard supervisor, REST POST /trailers/{trailerId}/hold-releases
RecordLoadStateAutoCompleteUnload sets EMPTY; no route of its own
DepartCheckOutVisit for each trailer taken out (it raises TrailerUndocked first when the trailer is DOCKED)

7. Created Events​

EventRaised whenFull CloudEvents type
TrailerParkedArriveAt a spot (also ReturnToOrigin to a spot)com.warehouse.wms.yard-management.trailer.TrailerParked
TrailerDockedArriveAt a door (also ReturnToOrigin to a door)com.warehouse.wms.yard-management.trailer.TrailerDocked
DoorWorkStartedStartDoorWork succeedscom.warehouse.wms.yard-management.trailer.DoorWorkStarted
DoorWorkCompletedCompleteDoorWork succeedscom.warehouse.wms.yard-management.trailer.DoorWorkCompleted
TrailerUndockedthe trailer leaves a door: StartMoving or Depart from DOCKED (decision Y-6)com.warehouse.wms.yard-management.trailer.TrailerUndocked
TrailerDepartedDepart succeedscom.warehouse.wms.yard-management.trailer.TrailerDeparted
SealExceptionRaisedSealCheckAtGate finds a mismatchcom.warehouse.wms.yard-management.trailer.SealExceptionRaised
TrailerHeldPlaceHold succeedscom.warehouse.wms.yard-management.trailer.TrailerHeld
TrailerHoldReleasedReleaseHold succeedscom.warehouse.wms.yard-management.trailer.TrailerHoldReleased
TrailerDwellExceededDwellSweep crosses a thresholdcom.warehouse.wms.yard-management.trailer.TrailerDwellExceeded

RecordArrival, RecordSeal, BreakSeal and RecordLoadState raise no event of their own in the model.

8. Throughput​

Estimate (from the model): high (every move and door step). Two trailer writes per move (claim, complete), plus door-work steps. The contended resource is a location: one door wanted by two moves. As built: per-location advisory lock, partial unique index as backstop (uq_trailers_one_per_location, uq_trailers_unit_on_site), optimistic concurrency on version.

9. Size​

Estimate (from the model): trailers on site (hundreds per site) plus history. Each instance is small. The model gives no event count; this pack's estimate for one dock cycle is about six (parked, docked, door work started, door work completed, undocked, departed, plus a parked or docked and an undocked per extra move).

YardMove​

1. Name​

YardMove (yardmove.Move), identified by moveId.

2. Description​

One instruction to take a trailer from where it is to a spot, a door or the gate, done by a hostler or by the visiting driver. Value objects: Performer(HOSTLER|VISITING_DRIVER), From/To Location{kind, code}, Priority{band 1..9, due_by}, Reason(TO_DOOR|FROM_DOOR|RELOCATE|TO_HOLDING), Lease{hostler_ref, expires_at}.

3. State Transitions​

Derived from: model.yaml → contexts[yard-management].aggregates[YardMove].states, .transitions, .commands, .policies[VisitingDriverMove].

Omitted: the creation arrow into REQUESTED is RequestMove. The arrow into CLAIMED comes from the policy text ("created CLAIMED with performer VISITING_DRIVER") and is not in transitions. A CLAIMED visiting-driver move has no lease, so it can neither expire nor be cancelled; the dock operator or gate clerk completes it through the same completion route (decisions Y-1, Y-3).

4. Enforced Invariants​

InvariantEnforced by
A trailer has at most one REQUESTED or CLAIMED moveErrTrailerHasOpenMove
No two open moves share a destination, and the destination is free when requestedErrDestinationReserved
A hostler holds at most one CLAIMED moveErrHostlerBusy
Only the lease holder completes a CLAIMED moveErrNotLeaseHolder
Completion records the actual location; a location other than the destination needs a reasonErrUnexplainedDestination

The first, second and third span moves (and, for "free", trailers). Enforcement as built: partial unique indexes on open moves per trailer, per destination and per hostler (uq_yard_moves_one_open_per_trailer, uq_yard_moves_open_destination, uq_yard_moves_one_claim_per_hostler), and Occupancy.CheckFree for "the destination is free". See Occupancy across aggregates.

5. Corrective Policies​

  • CallToDoor, ClearDoorAfterWork, DirectOnCheckIn (this context): create moves (see Trailer and YardVisit).
  • LeaseExpirySweep (this context): POST /move-lease-sweeps returns expired CLAIMED moves to REQUESTED.
  • NoShowFreesHolding (this context): on DockAppointmentNoShow or DockAppointmentCancelled, an open TO_DOOR move for that appointment is cancelled. A move carries the appointment_id of its appointment (decision X3), which is how the policy finds it.
  • VisitingDriverMove (this context): the first move from the gate is created CLAIMED, performer VISITING_DRIVER, no lease; the dock operator or gate clerk completes it. Departures leave from a spot or, for a live visit, from the door; there is no move to the gate.

6. Handled Commands​

CommandIssued by
RequestMoveYard supervisor, REST POST /moves; policies DirectOnCheckIn, CallToDoor, ClearDoorAfterWork
ClaimNextMoveHostler, REST POST /moves/claims
CompleteMoveHostler, REST POST /moves/{moveId}/completions; dock operator or gate clerk for a VISITING_DRIVER move (same route, decision Y-3)
CancelMoveYard supervisor, REST POST /moves/{moveId}/cancellations; policy NoShowFreesHolding
ExpireLeaseScheduler (cron), REST POST /move-lease-sweeps

7. Created Events​

EventRaised whenFull CloudEvents type
YardMoveRequestedRequestMove succeeds (also the first move at the gate)com.warehouse.wms.yard-management.yardmove.YardMoveRequested
YardMoveClaimedClaimNextMove succeedscom.warehouse.wms.yard-management.yardmove.YardMoveClaimed
YardMoveLeaseExpiredExpireLease succeedscom.warehouse.wms.yard-management.yardmove.YardMoveLeaseExpired
YardMoveCompletedCompleteMove succeedscom.warehouse.wms.yard-management.yardmove.YardMoveCompleted
YardMoveCancelledCancelMove succeedscom.warehouse.wms.yard-management.yardmove.YardMoveCancelled

All five are analytics only. YardMoveLeaseExpired is new as built (decision Y-10); the type strings above replace the earlier MoveRequested style, which was never the contract.

8. Throughput​

Estimate (from the model): high. Hostlers poll ClaimNextMove; two hostlers may reach for the same move, and two requests may name one destination. As built, the claim is ordered by lowest priority band, then earliest due_by (none last), then request time (decision Y-11, assumption A14), with a unique index of one CLAIMED move per hostler as the backstop and optimistic concurrency on version.

9. Size​

Estimate (from the model): moves/day × retention. Small; at most four events per instance (requested, claimed, completed or cancelled), plus any lease expiry, which raises none.

YardCheck​

1. Name​

YardCheck (yardcheck.Check), identified by yardCheckId.

2. Description​

A yard audit: walk the spots and doors, record what is really there, reconcile with the model. Value objects: Observation{location_code, unit_number?}, Discrepancy{kind MISSING|UNEXPECTED|WRONG_LOCATION, location_code, trailer_id?, unit_number?}.

3. State Transitions​

Derived from: model.yaml → contexts[yard-management].aggregates[YardCheck].states, .transitions, .commands.

Omitted: the creation arrow is OpenYardCheck (a command, not a model transition).

4. Enforced Invariants​

InvariantEnforced by
At most one OPEN yard check per siteErrYardCheckOpen
A location is observed at most once per checkErrLocationAlreadyObserved

5. Corrective Policies​

None in the model. Closing computes the discrepancies and publishes them; no command applies a discrepancy to a Trailer: closing only reports (decision Y-11), and a location that was not observed is MISSING when the model records a trailer there. exception-management opens one case per discrepancy (fleet_changes).

6. Handled Commands​

CommandIssued by
OpenYardCheckYard supervisor, REST POST /yard-checks
RecordObservationYard supervisor, REST POST /yard-checks/{yardCheckId}/observations
CloseYardCheckYard supervisor, REST POST /yard-checks/{yardCheckId}/closures

7. Created Events​

EventRaised whenFull CloudEvents type
YardCheckClosedCloseYardCheck succeedscom.warehouse.wms.yard-management.yardcheck.YardCheckClosed

8. Throughput​

Estimate (from the model): low. One check per site per shift; observations arrive as the supervisor walks the yard.

9. Size​

Estimate (from the model): one per site per shift. Up to one observation per location; one event per instance.

YardPolicy​

1. Name​

YardPolicy (yardpolicy.Policy), identified by siteId.

2. Description​

The per-site yard rules every gate and move decision reads. Value objects: require_appointment (bool), holding_spot_codes[], parking_zone_ids[]; dwell_threshold_minutes per TrailerKind, lease_seconds, seal_mismatch_action (FLAG or REJECT); free_time_minutes (detention clock, optional, no default). Defaults as built: require_appointment false, seal_mismatch_action FLAG, lease_seconds 300, no free time and no dwell thresholds (a kind without a threshold is never alerted).

3. State Transitions​

Derived from: model.yaml → contexts[yard-management].aggregates[YardPolicy].states, .transitions (empty).

Omitted: the self-arrow is PUT replacing the settings (If-Match is honoured). A site that never declared a policy answers the defaults above, as version 1.

4. Enforced Invariants​

InvariantEnforced by
Holding spots are known Yard slots of the siteErrUnknownLocation
Thresholds and lease are positiveErrValidation

5. Corrective Policies​

None. Other policies read it: DirectOnCheckIn (holding spots, parking zones, require_appointment), SealCheckAtGate (seal_mismatch_action), DwellSweep (thresholds), the claim use case (lease_seconds).

6. Handled Commands​

CommandIssued by
DeclareYardPolicyYard supervisor, REST PUT /sites/{siteId}/yard-policy

7. Created Events​

None (events: []). Its effect shows in the decisions that read it.

8. Throughput​

Estimate (from the model): low. Supervisor edits; read on every check-in and claim.

9. Size​

Estimate (from the model): one per site.

Occupancy across aggregates​

The business decision "a spot or a door holds at most one trailer" is not inside one aggregate. It spans every Trailer of a site and the open YardMoves that have reserved a destination. The model puts the rule in a domain service, Occupancy.CheckFree, under a per-location advisory lock, with a partial unique index as backstop.

MomentCheckErrorSource
RequestMoveThe destination is free and no other open move names itErrDestinationReservedYardMove invariant
RequestMoveThe trailer has no other open moveErrTrailerHasOpenMoveYardMove invariant
ClaimNextMoveThe hostler holds no other CLAIMED move; the trailer goes IN_MOVE and its origin place is released (decision Y-8, assumption A3)ErrHostlerBusyYardMove invariant
CompleteMove (ArriveAt)Occupancy.CheckFree on the actual location, under the lockErrLocationOccupiedTrailer invariant
CompleteMove (ArriveAt)Known, active slot; door not closed; door flow allows the trailer; trailer not on holdErrUnknownLocation, ErrDoorClosed, ErrDoorFlowMismatch, ErrTrailerOnHoldTrailer invariants
CompleteMoveA location other than the destination needs a reasonErrUnexplainedDestinationYardMove invariant
CheckOutVisitEvery trailer out is released (no open move, and PARKED or DOCKED with door work DONE)ErrTrailerNotReleasedYardVisit invariant

Derived from: model.yaml → contexts[yard-management].aggregates[Trailer].invariants, aggregates[YardMove].invariants, .business_decisions.

Omitted: the origin place is released at StartMoving, the destination was reserved at RequestMove and is validated again at ArriveAt; an occupied location is refused and the move stays CLAIMED (decision Y-8, assumption A3). The model uses two error names for "not free": ErrDestinationReserved when requesting and ErrLocationOccupied when arriving, and the service follows that split.

Read models​

Read modelSource eventsUsed forWhy it is not an aggregate
LocationViewfacility-layout LocationSlotRegistered (role Yard or Dock, dockFlow), LocationSlotDecommissioned, ZoneRegistered (zoneId → siteCode)ErrUnknownLocation, ErrDoorFlowMismatch, the site of a door or spot, free-spot search by location codeA copy of facility-layout's registry; this context enforces no rule on it.
AppointmentViewdock-scheduling DockAppointmentBooked, DockAppointmentRescheduled, DockAppointmentCancelled, DockAppointmentNoShowErrAppointmentRequired, DirectOnCheckIn, CallToDoor, SealCheckAtGate (expected_seal_number), NoShowFreesHoldingA copy of dock-scheduling's appointments; it never changes them. It marks itself CHECKED_IN from the yard's own VisitCheckedIn and USED from its own TrailerUndocked (decision X4).
DoorClosureViewdock-scheduling DoorClosureScheduled, DoorClosureLiftedErrDoorClosed, DirectOnCheckInA copy of dock-scheduling's closures.
AsnContentViewinbound-receiving ASNRegistered, ASNCancelledWhat an inbound trailer holds (Contents.asn_numbers)A projection of another context's ASNs.
ReceiptAtDoorViewinbound-receiving ReceiptOpened (receipt_id, appointment_id, door_code), ReceiptClosedAutoCompleteUnloadA projection of receipts at a door; it decides nothing alone.
YardBoardViewOwn Trailer and YardMove stateThe live spot and door map (GET /sites/{siteId}/yard-board)A read side of this context's own aggregates.
YardKpiReportOwn events on the analytics topicDwell by kind, door utilisation, moves per hostler hour, driver wait (arrival to door work started)A projection of facts; it decides nothing.

Derived from: model.yaml → contexts[yard-management].read_models.