Skip to main content

Aggregate Design Canvas

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

Built on develop (merged 2026-11-08) in IQVO/dock-scheduling, released at v0.1.3 (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.3 commit a1a029c in warehouse-infra since 2026-11-16, checked 2026-12-02): dock-scheduling runs its API only (it relays inline); yard-management runs its API and relay. The MCP server (18 tools on develop 096db0a, 14 in v0.1.3) 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 yard-management 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 two aggregate roots: DockAppointment and DockCalendar. Go packages, as built: internal/domain/dockappointment and internal/domain/dockcalendar (the ul code identifiers dockappointment.DockAppointment and dockcalendar.DockCalendar), plus internal/domain/shared for the door code, site id, carrier and SCAC value objects. An appointment id is appt- followed by a lowercase UUID.

Four generic errors from conventions.errors apply to both aggregates and are not repeated per invariant: ErrNotFound (404, not-found), ErrIllegalTransition (409, illegal-transition), ErrConcurrentUpdate (409, concurrent-update) and ErrValidation (422, validation-failed). As built the HTTP status follows decision D-10: 409 for a conflict with state, 422 for a value or reference rule, and the problem slug is the kebab-case of the error name without Err (ErrDoorDoubleBooked is door-double-booked). If-Match mismatch is 412.

DockAppointment​

1. Name​

DockAppointment (dockappointment.DockAppointment), identified by appointmentId.

2. Description​

One booked door window for one carrier visit: direction, door, window, and the ASNs (inbound) or CPT and shipment references (outbound) it covers. Value objects: Direction(INBOUND or OUTBOUND), Window with start and end (half-open), Carrier with name and optional scac, InboundRefs with asn_numbers, OutboundRefs with cpt_id and shipment_refs, ArrivalStatus(EARLY, ON_TIME, LATE) computed against the window with the site's arrival tolerance, Eta with eta_at, reported_at and source, and ExpectedSeal with the seal_number the carrier declares when booking.

3. State Transitions​

Derived from: model.yaml → contexts[dock-scheduling].aggregates[DockAppointment].states, .transitions, .commands.

Omitted: the creation arrow [*] --> BOOKED is BookAppointment (the model also listed ImportLegacyAppointment, removed in dock-scheduling ADR 0011); the model lists the commands but not as transitions, because a transition needs a from-state. ReportEta and ReassignDoor change data and bump the version, not the state (a reassignment is also legal from CHECKED_IN). COMPLETED, CANCELLED and NO_SHOW have no outgoing transition and are terminal (decision D-9: a late carrier books anew). The arrival that is implicit in BOOKED --> COMPLETED is policy OutOfOrderYardFacts.

4. Enforced Invariants​

InvariantEnforced byChecked against
Door code is 1 to 64 characters, with no whitespace, control characters or /ErrInvalidDoorCodethe value object
Carrier name is non-blank and at most 100 characters, scac is 2 to 4 upper-case letters when givenErrInvalidCarrierthe value object
end is after start and end - start is at most MaxWindow (4 h)ErrInvalidWindowthe value object
A booked or rescheduled window does not start before nowErrWindowInPastthe clock
The door is a known, active Dock slot of the siteErrUnknownDoorDoorView
The door's dockFlow allows the direction (Inbound, Outbound or Both)ErrDoorFlowMismatchDoorView
No overlap with another BOOKED or CHECKED_IN appointment on the same doorErrDoorDoubleBookeddomain service DoorSchedule.CheckNoOverlap under a per-door advisory lock
The window is inside the door's operating hours and outside its closuresErrDoorUnavailableDockCalendar
INBOUND covers at least one ASN, each known and not cancelled in the local ASN copyErrUnknownAsnAsnView
OUTBOUND names a cpt_id known in the local CPT copy, or at least one shipment_refErrMissingOutboundRefCutoffView
An ASN sits on only one active native appointment (decision D-12)ErrAsnAlreadyScheduledthe booking transaction, with the asn_claims primary key as the backstop
MarkNoShow only after window_end plus the site's no-show graceErrNoShowTooEarlythe clock and Rules

Seven of the twelve reach outside one instance: the door and flow checks read DoorView, the availability check reads the other aggregate, the ASN and CPT checks read event-fed copies, and the overlap check spans every appointment of a door. This pack's reading is that the use case loads those inputs and passes them to the aggregate or to the domain service; the model fixes that the overlap check is a domain service under a per-door advisory lock; as built a GiST exclusion constraint on (door_code, window) is the database backstop (a losing writer fails with 23P01, mapped to ErrDoorDoubleBooked) and rows whose door was set by a physical fact (door_override) and legacy imports (none can be created since ADR 0011) are exempt from it. ErrDoorDoubleBooked is deliberately not applied by ReassignDoor (policy ActualDoorWins): the physical fact wins, and any later appointment that now overlaps is flagged instead.

5. Corrective Policies​

  • ArrivalFromGate: on VisitCheckedIn naming an appointment, RecordArrival with arrival_status computed from the window and the arrival tolerance; an unknown or terminal appointment is ignored and counted.
  • ActualDoorWins: on TrailerDocked whose door differs from the booked door, ReassignDoor without the overlap refusal; any later appointment now overlapping on the new door gets DockAppointmentAtRisk.
  • CompleteOnDoorRelease: on TrailerUndocked naming an appointment, RecordDoorRelease.
  • OutOfOrderYardFacts: a door release applied to a BOOKED appointment completes it and records the arrival as implicit (BOOKED to COMPLETED); a late VisitCheckedIn for a COMPLETED appointment is ignored; any yard fact for a CANCELLED or NO_SHOW appointment is ignored and counted.
  • NoShowSweep: POST /no-show-sweeps marks BOOKED appointments past window_end plus the no-show grace as NO_SHOW (cron, idempotent).
  • EtaRisk: ReportEta with eta_at later than window_start plus the arrival tolerance raises DockAppointmentAtRisk once per ETA report.
  • CancelWhenAllAsnsCancelled: on ASNCancelled, an INBOUND BOOKED appointment whose ASNs are all cancelled is cancelled with reason ASN_CANCELLED.
  • CancelOnVisitRejected: on VisitRejected naming a BOOKED appointment, CancelAppointment with reason TURNED_AWAY; any other state is ignored and counted (X2).
  • PickupFromCutoffs (phase 2): on CPTScheduleChanged, keep one OUTBOUND appointment per cutoff and operating day on a 7-day horizon, on the door the site's PickupDoorRule names for the ship_method, window [cutoff - pickup_lead, cutoff). PickupDoorRule and pickup_lead are not defined elsewhere in the model. As built (decision D-3) only the schedule is stored; no appointment is created from it and there is no PickupDoorRule.
  • LegacyImport (strangler stage A): removed in dock-scheduling ADR 0011. It consumed inbound-receiving DockAppointment* events and imported each appointment once (provenance legacy-import); the provenance value stays as a historical, published enum value.

6. Handled Commands​

CommandIssued byState change
BookAppointmentCarrier scheduler, REST POST /appointmentscreates BOOKED
RescheduleAppointmentCarrier scheduler or dock planner, REST POST /appointments/{appointmentId}/reschedulesBOOKED to BOOKED (window and/or door)
CancelAppointmentCarrier scheduler or dock planner (reasons CARRIER_REQUEST, SITE_REQUEST), REST POST /appointments/{appointmentId}/cancellations; policies CancelWhenAllAsnsCancelled, CancelOnVisitRejectedBOOKED or CHECKED_IN to CANCELLED
ReportEtaCarrier scheduler, REST POST /appointments/{appointmentId}/eta-reportsnone (stores Eta, bumps the version)
RecordArrivalpolicy ArrivalFromGate (no REST route)BOOKED to CHECKED_IN
ReassignDoorpolicy ActualDoorWins (no REST route)none (changes the door; from BOOKED or CHECKED_IN)
RecordDoorReleasepolicy CompleteOnDoorRelease (no REST route)CHECKED_IN or BOOKED to COMPLETED
MarkNoShowScheduler (cron), REST POST /no-show-sweepsBOOKED to NO_SHOW

7. Created Events​

EventRaised whenTopicFull CloudEvents type
DockAppointmentBookedBookAppointment succeeds.eventscom.warehouse.wms.dock-scheduling.dockappointment.DockAppointmentBooked
DockAppointmentRescheduledRescheduleAppointment succeeds.eventscom.warehouse.wms.dock-scheduling.dockappointment.DockAppointmentRescheduled
DockAppointmentCancelledCancelAppointment succeeds.eventscom.warehouse.wms.dock-scheduling.dockappointment.DockAppointmentCancelled
DockAppointmentNoShowMarkNoShow succeeds.eventscom.warehouse.wms.dock-scheduling.dockappointment.DockAppointmentNoShow
DockAppointmentCheckedInRecordArrival succeeds.analytics onlycom.warehouse.wms.dock-scheduling.dockappointment.DockAppointmentCheckedIn
DockAppointmentDoorReassignedReassignDoor succeeds.events and .analytics (ADR 0010)com.warehouse.wms.dock-scheduling.dockappointment.DockAppointmentDoorReassigned
DockAppointmentCompletedRecordDoorRelease succeeds.analytics onlycom.warehouse.wms.dock-scheduling.dockappointment.DockAppointmentCompleted
DockAppointmentAtRiskReportEta under policy EtaRisk (cause LATE_ETA), or ReassignDoor under ActualDoorWins for the overlapped appointment (cause DOOR_REASSIGNED_OVERLAP).analytics onlycom.warehouse.wms.dock-scheduling.dockappointment.DockAppointmentAtRisk

.events is warehouse.dock-scheduling.events (each such event is also written to the analytics topic as a twin) and .analytics is warehouse.dock-scheduling.analytics. Every event except DockAppointmentAtRisk carries the aggregate version; Booked and Rescheduled also carry arrival_tolerance_minutes, and Rescheduled carries previous_door_code.

8. Throughput​

Estimate (from the model): medium (bookings and ETA reports). Per-door contention is bounded by the per-door advisory lock; version backs the optimistic-concurrency check (ErrConcurrentUpdate).

9. Size​

Estimate (from the model): doors × appointments per day × horizon (14 days), plus history. The model uses the 14-day figure only in this estimate; as built there is no booking horizon (decision D-11), only the window length and slot granularity are bounded.

DockCalendar​

1. Name​

DockCalendar (dockcalendar.DockCalendar), identified by siteId.

2. Description​

The per-site door calendar settings that every booking is checked against. Value objects: OperatingHours with door_code (or the site default), weekday, opens_at, closes_at and timezone; Closure with closure_id, door_code, from, to and reason; Settings with max_window_minutes (240, a site may lower it, never raise it), slot_granularity_minutes (15), arrival_tolerance_minutes (15) and no_show_grace_minutes (60).

3. State Transitions​

Derived from: model.yaml → contexts[dock-scheduling].aggregates[DockCalendar].states, .transitions (empty), .commands.

Omitted: the calendar is created lazily, with the defaults, the first time a booking or a calendar command needs it (decision D-1); a site with no operating-hours rows is open 24x7. The self-loop is drawn only to show that commands change the contents, not the state.

4. Enforced Invariants​

InvariantEnforced by
opens_at < closes_at for every operating-hours rowErrInvalidOperatingHours
Closures do not overlap on one doorErrOverlappingClosure
A closure may not cover an active appointment of that door (the refusal lists the appointment ids)ErrClosureConflictsWithAppointments
New operating hours may not leave an active appointment of a door outside them (the refusal lists the appointment ids, decision D-8)ErrHoursConflictWithAppointments

The third reaches into DockAppointment (an active appointment is BOOKED or CHECKED_IN); the two aggregates are saved in separate transactions, so this pack's reading is that the use case reads the appointments of the door and the check is a point-in-time refusal, not a guarantee against a concurrent booking.

5. Corrective Policies​

None of the model's policies reacts to the calendar. A change of operating hours that would strand an active appointment is refused (ErrHoursConflictWithAppointments, D-8), and a decommissioned door only blocks new bookings: existing appointments are left untouched (D-7).

6. Handled Commands​

CommandIssued by
DeclareOperatingHoursDock planner, REST PUT /sites/{siteId}/dock-calendar/operating-hours (replaces the whole set of rows of the site)
DeclareCalendarSettingsDock planner, REST PUT /sites/{siteId}/dock-calendar/settings
ScheduleDoorClosureDock planner, REST POST /sites/{siteId}/dock-calendar/closures
LiftDoorClosureDock planner, REST POST /sites/{siteId}/dock-calendar/closures/{closureId}/lifts

7. Created Events​

EventRaised whenTopicFull CloudEvents type
DoorOperatingHoursDeclaredDeclareOperatingHours succeeds.analytics onlycom.warehouse.wms.dock-scheduling.dockcalendar.DoorOperatingHoursDeclared
DoorClosureScheduledScheduleDoorClosure succeeds.eventscom.warehouse.wms.dock-scheduling.dockcalendar.DoorClosureScheduled
DoorClosureLiftedLiftDoorClosure succeeds.eventscom.warehouse.wms.dock-scheduling.dockcalendar.DoorClosureLifted

DeclareCalendarSettings raises no event, as modelled.

8. Throughput​

Estimate (from the model): low. Planner edits only; reads on every booking.

9. Size​

Estimate (from the model): one per site, with its operating-hours rows and closures.

Read models​

Read modelSourceUsed forWhy it is not an aggregate
DoorViewfacility-layout LocationSlotRegistered (role Dock, dockFlow), LocationSlotDecommissioned, ZoneRegistered (zoneId to siteCode)ErrUnknownDoor, ErrDoorFlowMismatch, the site of a doorA copy of facility-layout's slots; this context changes nothing in it and enforces no rule on it.
AsnViewinbound-receiving ASNRegistered, ASNCancelledErrUnknownAsn; policy CancelWhenAllAsnsCancelledA copy of inbound-receiving's ASNs.
CutoffViewprocess-path-management CPTScheduleChangedErrMissingOutboundRef; policy PickupFromCutoffs (phase 2)A copy of the fleet's CPT schedule.
DoorAvailabilityViewown DockAppointment and DockCalendar stateGetDoorAvailability: free windows per doorA projection of this context's own aggregates; it decides nothing (booking is checked on the aggregate).
AdherenceReportown events on the analytics topicGET /reports/schedule-adherence: on-time, early, late and no-show share per site and carrierA projection of facts already recorded; it enforces nothing.

Derived from: model.yaml → contexts[dock-scheduling].read_models.