Use Cases
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).
One section per command in contexts[dock-scheduling].aggregates[*].commands
(12 commands: eight on DockAppointment, four on DockCalendar; ImportLegacyAppointment, the thirteenth, was removed in dock-scheduling ADR 0011). Package
(as built): internal/application/usecases. The runtime sequence of each is on
Sequence Diagrams. Reads
(GET /appointments, GET /appointments/{appointmentId},
GET /doors/{doorCode}/availability, GET /sites/{siteId}/dock-calendar,
GET /reports/schedule-adherence, GET /reports/freshness) are not use cases: the HTTP
adapter reads the repositories and read models directly, and the two report routes are served by
the separate reports binary from the analytics database.
Conventions for every use case
- One transaction. The aggregate change, its outbox rows and (for a Kafka-driven use case) the inbox row commit together.
- Errors are
application/problem+json. The model fixes four generic errors with status and problem slug (conventions.errors); every otherErr...below has the status of decision D-10 (409 for a conflict with state, 422 for a value or reference rule) and the kebab-case of its name as slug (service ADR 0002):
| Error | HTTP | Problem slug | Source |
|---|---|---|---|
ErrNotFound | 404 | not-found | model |
ErrIllegalTransition | 409 | illegal-transition | model |
ErrConcurrentUpdate | 409 | concurrent-update | model |
ErrValidation | 422 | validation-failed | model |
ErrInvalidDoorCode, ErrInvalidCarrier, ErrInvalidWindow, ErrInvalidOperatingHours | 422 | invalid-door-code, invalid-carrier, invalid-window, invalid-operating-hours | service |
ErrWindowInPast, ErrUnknownDoor, ErrDoorFlowMismatch, ErrUnknownAsn, ErrMissingOutboundRef | 422 | window-in-past, unknown-door, door-flow-mismatch, unknown-asn, missing-outbound-ref | service |
ErrDoorDoubleBooked, ErrDoorUnavailable, ErrOverlappingClosure, ErrClosureConflictsWithAppointments | 409 | door-double-booked, door-unavailable, overlapping-closure, closure-conflicts-with-appointments | service |
ErrAsnAlreadyScheduled, ErrHoursConflictWithAppointments, ErrNoShowTooEarly, ErrClosureAlreadyLifted | 409 | asn-already-scheduled, hours-conflict-with-appointments, no-show-too-early, closure-already-lifted | service (added as built) |
ErrUnknownClosure | 404 | unknown-closure | service |
ErrInvalidSettings, ErrInvalidClosure, ErrInvalidReason, ErrInvalidEta, ErrDuplicateAsn, ErrInvalidRefs | 422 | the kebab-case of the name | service |
- Idempotency. Every state-changing
POSTandPUTtakes anIdempotency-Keyheader; a replay with the same key returns the first response. Every Kafka consumer is idempotent on the CloudEventsid(inbox). Mutable aggregates carry aversionexposed as an ETag and checked withIf-Match(ErrConcurrentUpdateon a lost race,412on anIf-Matchmismatch). As built the ETag is the weakW/"<version>",If-Matchis honoured on reschedule and cancel and is optional (no428), creatingPOSTs require theIdempotency-Keyand a replay answers byte-identically withIdempotency-Replayed: true;PUTis idempotent by method. - Kafka-driven use cases have no HTTP status. A domain refusal that the model calls "ignored and counted" is counted and the event is marked processed; an infrastructure failure rolls back and the message is redelivered.
- Order of checks in a booking is this pack's reading (the service does not state it): cheap value-object checks first, then the event-fed copies, then the calendar, and the per-door lock last so that it is held for the shortest time.
- Request and response bodies are not in the model; fields named below come from the event payloads and value objects.
BookAppointment
- Actor / trigger: carrier scheduler (carrier portal).
- Inbound adapter: REST
POST /appointments. - Preconditions: none on the aggregate; the door, ASN and CPT copies must already hold the facts the booking cites.
- Main flow:
- Validate the value objects: door code (
ErrInvalidDoorCode), carrier (ErrInvalidCarrier), window (ErrInvalidWindow), start not before now (ErrWindowInPast). - Look the door up in
DoorView: a known, active Dock slot (ErrUnknownDoor). The door's zone gives thesite_id. - Check the direction against the door's
dockFlow(ErrDoorFlowMismatch). - Load the site's
DockCalendar; the window must be inside the door's operating hours and outside its closures (ErrDoorUnavailable). INBOUND: every ASN is inAsnViewand not cancelled (ErrUnknownAsn).OUTBOUND: thecpt_idis inCutoffView, or at least oneshipment_refis given (ErrMissingOutboundRef).- Take the per-door advisory lock and run
DoorSchedule.CheckNoOverlapagainst the door'sBOOKEDandCHECKED_INappointments (ErrDoorDoubleBooked). - Create the appointment in
BOOKEDwithversion1, save it and writeDockAppointmentBookedto the outbox, in one transaction. - Return the appointment with its ETag.
- Validate the value objects: door code (
- Errors:
ErrInvalidDoorCode,ErrInvalidCarrier,ErrInvalidWindow,ErrWindowInPast,ErrUnknownDoor,ErrDoorFlowMismatch,ErrDoorUnavailable,ErrUnknownAsn,ErrMissingOutboundRef,ErrDoorDoubleBooked,ErrValidation. - Events emitted:
DockAppointmentBooked. - Idempotency:
Idempotency-Key; the overlap check and the insert run under the same per-door lock.
RescheduleAppointment
- Actor / trigger: carrier scheduler.
- Inbound adapter: REST
POST /appointments/{appointmentId}/reschedules,If-Matchwith the appointmentversion. - Preconditions: the appointment is
BOOKED. - Main flow:
- Load the appointment; refuse if not
BOOKED(ErrIllegalTransition). - Validate the new window, and the new door when one is given, as in
BookAppointmentsteps 1, 3 and 4: a reschedule may change the door and the window (decision D-4). - Under the per-door lock, run
DoorSchedule.CheckNoOverlapfor the new window, ignoring this appointment (ErrDoorDoubleBooked). - Keep the state
BOOKED; store the new window and the previous one; save with the version check and writeDockAppointmentRescheduled(previous_window_start,previous_window_end,previous_door_code,arrival_tolerance_minutes), one transaction.
- Load the appointment; refuse if not
- Errors:
ErrNotFound,ErrIllegalTransition,ErrConcurrentUpdate,ErrInvalidWindow,ErrWindowInPast,ErrDoorFlowMismatch,ErrDoorUnavailable,ErrDoorDoubleBooked. - Events emitted:
DockAppointmentRescheduled. - Idempotency:
Idempotency-KeyandIf-Match.
CancelAppointment
- Actor / trigger: carrier scheduler; policy
CancelWhenAllAsnsCancelledonASNCancelled(reasonASN_CANCELLED); policyCancelOnVisitRejectedonVisitRejected(reasonTURNED_AWAY). The REST route acceptsCARRIER_REQUESTandSITE_REQUEST, the latter for the dock planner (decisions D-5, X2). - Inbound adapter: REST
POST /appointments/{appointmentId}/cancellationswith aCancellationReason; Kafka consumer ofwarehouse.inbound-receiving.eventsfor the policy. - Preconditions: the appointment is
BOOKEDorCHECKED_IN. - Main flow:
- Load the appointment; refuse if not
BOOKEDorCHECKED_IN(ErrIllegalTransition). - Transition to
CANCELLEDwith the reason. - Save with the version check and write
DockAppointmentCancelled(reason), one transaction. - Policy path: for each
INBOUNDBOOKEDappointment of the cancelled ASN whose ASNs are now all cancelled, run steps 2 and 3.
- Load the appointment; refuse if not
- Errors:
ErrNotFound,ErrIllegalTransition,ErrConcurrentUpdate,ErrValidation(a reason outside the list). - Events emitted:
DockAppointmentCancelled. - Idempotency:
Idempotency-KeyandIf-Match; inbox on the Kafka path.
ReportEta
- Actor / trigger: carrier scheduler (later, possibly a
transport-visibilityfeed). - Inbound adapter: REST
POST /appointments/{appointmentId}/eta-reports. - Preconditions: the appointment exists. The model does not name the
states that accept an ETA; this pack's reading is
BOOKEDonly. - Main flow:
- Load the appointment with its
version. - Store
Eta(eta_at,reported_at,source). - If
eta_atis later thanwindow_startplus the arrival tolerance, writeDockAppointmentAtRiskwith causeLATE_ETA(policyEtaRisk), once per ETA report. - Save with the version check, one transaction. Nothing is rescheduled.
- Load the appointment with its
- Errors:
ErrNotFound,ErrIllegalTransition,ErrConcurrentUpdate,ErrValidation. - Events emitted:
DockAppointmentAtRiskwhen the ETA is late; none otherwise. - Idempotency:
Idempotency-Key; oneAtRiskper ETA report.
RecordArrival
- Actor / trigger: policy
ArrivalFromGateonVisitCheckedInnaming anappointment_id. There is no REST route: arrival is a physical fact owned byyard-management. - Inbound adapter: Kafka consumer of
warehouse.yard-management.events(typecom.warehouse.wms.yard-management.yardvisit.VisitCheckedIn). - Preconditions: the appointment is
BOOKED. - Main flow:
- Insert the CloudEvents
idinto the inbox; if present, stop. - Load the appointment. Unknown or terminal (
COMPLETED,CANCELLED,NO_SHOW): ignore and count. A lateVisitCheckedInfor aCOMPLETEDappointment is also ignored. - Compute
ArrivalStatusfromarrived_at, the window and the site's arrival tolerance (EARLY beforewindow_startminus the tolerance, LATE afterwindow_startplus the tolerance, else ON_TIME; decision X6). - Transition
BOOKEDtoCHECKED_IN; save with the version check and writeDockAppointmentCheckedIn(checked_in_at,arrival_status,visit_id) to the analytics topic, one transaction.
- Insert the CloudEvents
- Errors: none returned; refusals are counted. An appointment already
CHECKED_INis left unchanged and counted. - Events emitted:
DockAppointmentCheckedIn(analytics only). - Idempotency: inbox on the CloudEvents
id.
ReassignDoor
- Actor / trigger: policy
ActualDoorWinsonTrailerDockedwhosedoor_codediffers from the booked door. No REST route. - Inbound adapter: Kafka consumer of
warehouse.yard-management.events(typecom.warehouse.wms.yard-management.trailer.TrailerDocked). - Preconditions: the appointment is active:
BOOKEDandCHECKED_INaccept the command (the model lists both as self-transitions). - Main flow:
- Inbox check on the CloudEvents
id. - Load the appointment by
appointment_id; if the door equals the booked door, stop (the model names no reaction). - Change the door without the overlap refusal: the physical fact wins.
- Find later appointments that now overlap on the new door; each gets
DockAppointmentAtRiskwith causeDOOR_REASSIGNED_OVERLAP. - Save with the version check and write
DockAppointmentDoorReassigned(from_door_code,to_door_code), one transaction.
- Inbox check on the CloudEvents
- Errors: none returned; a
CANCELLEDorNO_SHOWappointment is ignored and counted. - Events emitted:
DockAppointmentDoorReassigned(integration and analytics, service ADR 0010:inbound-receivingreads it) and, per overlapped appointment,DockAppointmentAtRisk(analytics only). - Idempotency: inbox; a second
TrailerDockedfor the same door changes nothing.
RecordDoorRelease
- Actor / trigger: policy
CompleteOnDoorReleaseonTrailerUndockednaming anappointment_id. No REST route. - Inbound adapter: Kafka consumer of
warehouse.yard-management.events(typecom.warehouse.wms.yard-management.trailer.TrailerUndocked). - Preconditions: the appointment is
CHECKED_IN, orBOOKED(policyOutOfOrderYardFacts). - Main flow:
- Inbox check on the CloudEvents
id. - Load the appointment.
CANCELLEDorNO_SHOW: ignore and count. - From
BOOKED, record the arrival as implicit and complete it (BOOKEDtoCOMPLETED); fromCHECKED_IN, complete it. - Save with the version check and write
DockAppointmentCompleted(completed_at), one transaction.
- Inbox check on the CloudEvents
- Errors: none returned.
- Events emitted:
DockAppointmentCompleted(analytics only). NoDockAppointmentCheckedInis raised for an implicit arrival; the adherence report counts it asON_TIMEand the metricdock_scheduling_implicit_arrivals_totalcounts it. - Idempotency: inbox; an appointment already
COMPLETEDis not completed twice. One appointment covers exactly one trailer (decision X3).
MarkNoShow
- Actor / trigger: scheduler (cron), policy
NoShowSweep. - Inbound adapter: REST
POST /no-show-sweeps. - Preconditions: none; the sweep selects what qualifies.
- Main flow:
- Select
BOOKEDappointments withwindow_endplus the site's no-show grace before now. - For each, transition
BOOKEDtoNO_SHOW, save with the version check and writeDockAppointmentNoShow, one transaction per appointment. A version conflict leaves the appointment for the next sweep. - Return how many were marked (this pack's reading; the response body is not in the model; the answer lists the ids).
- Select
- Errors:
ErrConcurrentUpdateper appointment is absorbed by the sweep; no other. - Events emitted:
DockAppointmentNoShow, one per appointment. - Idempotency:
Idempotency-Key; a rerun marks only what still qualifies, so it is idempotent by construction.
DeclareOperatingHours
- Actor / trigger: dock planner.
- Inbound adapter: REST
PUT /sites/{siteId}/dock-calendar/operating-hours. - Preconditions: none.
- Main flow:
- Validate every row:
opens_at < closes_at(ErrInvalidOperatingHours). - Store the hours for the door, or as the site default, with weekday and
time zone;
PUTreplaces the whole set of rows of the site (assumption A7: a door with rows of its own uses only those, a door with none uses the site default rows, no rows at all means open 24x7; at most one row per door and weekday;closes_atmay be24:00). - Save with the version check and write
DoorOperatingHoursDeclared(site_id,door_code,operating_hours,version), one transaction.
- Validate every row:
- Errors:
ErrInvalidOperatingHours,ErrConcurrentUpdate,ErrValidation,ErrHoursConflictWithAppointments(409, lists the ids) when an active appointment would fall outside the new hours (decision D-8). - Events emitted:
DoorOperatingHoursDeclared(analytics only). - Idempotency:
Idempotency-Key;PUTwith the same body is a no-op.
DeclareCalendarSettings
- Actor / trigger: dock planner.
- Inbound adapter: REST
PUT /sites/{siteId}/dock-calendar/settings. - Preconditions: none.
- Main flow:
- Validate
max_window_minutes,slot_granularity_minutes,arrival_tolerance_minutesandno_show_grace_minutes(ErrValidation; the defaults are 240, 15, 15 and 60;max_window_minutescan only lower the 4 h hard cap; the window grid is whole minutes since the Unix epoch). - Store the settings and save with the version check.
- Validate
- Errors:
ErrValidation,ErrConcurrentUpdate. - Events emitted: none; the new tolerance reaches
yard-managementon the nextBookedorRescheduledevent (arrival_tolerance_minutes, decision X1). - Idempotency:
Idempotency-Key;PUTwith the same body is a no-op.
ScheduleDoorClosure
- Actor / trigger: dock planner.
- Inbound adapter: REST
POST /sites/{siteId}/dock-calendar/closures. - Preconditions: none on the calendar.
- Main flow:
- Validate the closure (
door_code,from,to,reason). - Refuse if it overlaps another closure of the same door
(
ErrOverlappingClosure). - Refuse if it covers an active appointment of the door; the refusal lists
the appointment ids (
ErrClosureConflictsWithAppointments). - Add the closure with a new
closure_id; save with the version check and writeDoorClosureScheduled, one transaction.
- Validate the closure (
- Errors:
ErrOverlappingClosure,ErrClosureConflictsWithAppointments,ErrConcurrentUpdate,ErrValidation. - Events emitted:
DoorClosureScheduled(consumed byyard-management). - Idempotency:
Idempotency-Key. The appointments check is a read, not a lock; a booking that lands between the check and the commit is possible (this pack's reading of the model's two separate aggregates).
LiftDoorClosure
- Actor / trigger: dock planner.
- Inbound adapter: REST
POST /sites/{siteId}/dock-calendar/closures/{closureId}/lifts. - Preconditions: the closure exists on the site's calendar.
- Main flow:
- Find the closure by
closure_id(ErrNotFoundif absent). - Remove it; save with the version check and write
DoorClosureLifted, one transaction.
- Find the closure by
- Errors:
ErrNotFound,ErrConcurrentUpdate. - Events emitted:
DoorClosureLifted(consumed byyard-management). - Idempotency:
Idempotency-Key; a replay returns the first response.
Agent surfaces: which use cases the MCP tools and the A2A skills call
As built on develop 096db0a (read 2026-12-02; internal/adapters/inbound/mcp/tools*.go
and internal/adapters/inbound/a2a/server.go, service ADRs 0007, 0012, 0015 and 0016).
REST and the two agent adapters call the same use cases. The MCP server has 18
tools (8 L1, 2 L2, 8 L3; 14 in v0.1.3) and the A2A agent two skills; nothing on either
surface records an arrival, a door release, a calendar change or the sweep. An L2 tool
returns a proposal and changes nothing; an L3 tool or skill is a write: the human
approval is held by the caller, every write takes an idempotencyKey, and the facts an
agent write raises carry initiated_by (via mcp or a2a, proposal_id,
approved_by, agent_id; service ADR 0016). The use cases the model has no command for
are marked; they are described in the service's ADRs named here.
| Surface | Tool or skill | Level | Use case called | REST twin |
|---|---|---|---|---|
| MCP | book_appointment | L3 | BookAppointment | POST /appointments |
| MCP | reschedule_appointment | L3 | RescheduleAppointment | POST /appointments/{appointmentId}/reschedules |
| MCP | cancel_appointment | L3 | CancelAppointment | POST /appointments/{appointmentId}/cancellations |
| MCP | report_eta | L3 | ReportEta | POST /appointments/{appointmentId}/eta-reports |
| MCP | propose_reschedule_plan | L2 | ProposeReschedulePlan (no model command, ADR 0016): one stored plan for the BOOKED appointments of a door and window, a RESCHEDULE or UNPLACED row per appointment, valid one hour | none |
| MCP | propose_late_arrival_actions | L2 | ProposeLateArrivalActions (no model command, ADR 0016): one stored plan under the site's opt-in late-arrival policy, a RESCHEDULE or MARK_NO_SHOW row per late appointment | none |
| MCP | apply_reschedule_plan | L3 | ApplyReschedulePlan (no model command, ADR 0016): RescheduleAppointment per RESCHEDULE row and MarkNoShow per MARK_NO_SHOW row, once per plan after a person approved it | none |
| MCP | register_carrier, suspend_carrier, reinstate_carrier | L3 | RegisterCarrier, SuspendCarrier, ReinstateCarrier (no model command, ADR 0012) | PUT /carriers/{scac}, POST /carriers/{scac}/suspensions, POST /carriers/{scac}/reinstatements |
| MCP | list_appointments, get_appointment, get_door_availability, get_dock_calendar, list_at_risk_appointments, list_carriers, get_carrier, get_dock_briefing | L1 | ListAppointments, GetAppointment, GetDoorAvailability, GetDockCalendar, ListAtRisk, ListCarriers, GetCarrier, GetDockBriefing (ADR 0016) | the GET routes; the briefing has none |
| A2A | appointment_options | L1 | GetDockCalendar, GetCarrier, ListAppointments, GetDoorAvailability | none (the read half of the plan_dock_booking prompt) |
| A2A | book_or_reschedule_appointment | L3 | BookAppointment (operation=book) or RescheduleAppointment (operation=reschedule) | the MCP twins book_appointment, reschedule_appointment |