Use Cases
Every use case is a method of usecases.Yard (internal/application/usecases), one per REST route,
MCP write tool or Kafka event it serves. This page has one section per command of the five
aggregates (YardVisit, Trailer, YardMove, YardCheck, YardPolicy): where a command is
executed inside a larger use case (RecordArrival, StartMoving, ArriveAt, Depart run inside
CheckInVisit, ClaimNextMove, CompleteMove and CheckOutVisit) the section says so. The runtime
sequence of the significant ones is on Sequence Diagrams. Reads
(ListVisits, GetVisit, ListTrailers, GetTrailer, ListMoves, GetYardBoard,
GetYardPolicy) are query methods in queries.go and checks_policy.go: they read the
repositories and views and raise nothing.
| Section | Yard method (file) | Trigger |
|---|---|---|
| CheckInVisit | CheckInVisit (gate_checkin.go) | POST /visits |
| RejectAtGate | RejectAtGate (gate_checkin.go) | POST /visit-rejections |
| CheckOutVisit | CheckOutVisit (gate_checkout.go) | POST /visits/{visitId}/check-outs |
| StartDoorWork, CompleteDoorWork | StartDoorWork, CompleteDoorWork (doors.go) | POST /trailers/{trailerId}/door-work-starts, …/door-work-completions; CompleteDoorWork also from ReceiptClosed |
| SecureTrailer, ReleaseTrailerSecuring | SecureTrailer, ReleaseTrailerSecuring (doors.go) | POST /trailers/{trailerId}/securings, …/securing-releases (ADR 0013) |
| OpenInspection, RecordInspectionItem, CompleteInspection | OpenInspection, RecordInspectionItem, CompleteInspection (inspections.go) | POST /trailers/{trailerId}/inspections, PUT /inspections/{inspectionId}/items/{itemCode}, POST /inspections/{inspectionId}/completions (ADR 0015) |
| RecordSeal, PlaceHold, ReleaseHold | RecordSeal, PlaceHold, ReleaseHold (doors.go) | POST /trailers/{trailerId}/seals, …/holds, …/hold-releases |
| DwellSweep | SweepDwell (checks_policy.go) | POST /dwell-sweeps (CronJob) |
| RequestMove, ClaimNextMove, CompleteMove, CancelMove | RequestMove, ClaimNextMove, CompleteMove, CancelMove (moves.go) | POST /moves, /moves/claims, /moves/{moveId}/completions, /moves/{moveId}/cancellations |
| ExpireLease | SweepMoveLeases (moves.go) | POST /move-lease-sweeps (CronJob) |
| OpenYardCheck, RecordObservation, CloseYardCheck | OpenYardCheck, RecordObservation, CloseYardCheck (checks_policy.go) | POST /yard-checks, …/observations, …/closures |
| DeclareYardPolicy | DeclareYardPolicy (checks_policy.go) | PUT /sites/{siteId}/yard-policy |
| ClassifyTrailer | ClassifyTrailer (doors.go) | POST /trailers/{trailerId}/classifications |
| Event-driven reactions | ApplyZone, ApplySlot, DecommissionSlot, ApplyAppointment, ScheduleClosure, LiftClosure, RegisterAsn, CancelAsn, OpenReceipt, CloseReceipt (consumers.go) | the three Kafka consumers |
Source: internal/application/usecases/*.go, internal/adapters/inbound/http/server.go, internal/adapters/inbound/mcp/tools_write.go.
Conventions for every use case
-
One transaction. The aggregate changes, their outbox rows and (for a Kafka-driven use case) the inbox row commit together. A use case that touches two aggregates (
ClaimNextMove: move and trailer;CompleteMove: move and trailer;CheckInVisit: visit, trailers and first move) does so in one unit of work, as the model'sTrailer.notesstates forStartMovingandArriveAt. -
Errors are
application/problem+json. The model assigns an HTTP status only to four generic errors:Error HTTP Problem typeslugErrNotFound404 not-foundErrIllegalTransition409 illegal-transitionErrConcurrentModification409 concurrent-modificationErrValidation422 validation -
Domain errors (
ErrLocationOccupied,ErrAppointmentRequired, ...) have a name in the model and, at first, no status. As built (decision D-10, service ADR 0002): a conflict with current state (occupancy, ownership, release, an open check) is 409; a value-object or reference rule (ErrInvalidCarrier,ErrUnknownLocation,ErrUnexplainedDestination) is 422; a malformed request is 400. The problemtypeslug is the kebab case of the name withoutErr(ErrLocationOccupiedbecomeslocation-occupied). Errors added as built:ErrNoFreeSpot(409),ErrTrailerNotOnHold(409),ErrLeaseNotExpired,ErrStalePolicy(412precondition-failed). -
Idempotency. Every state-changing
POSTandPUTtakes anIdempotency-Keyheader; a replay with the same key returns the first response (idempotency_keys) when that response is final for the request: a success, or a refusal whose problem type is FINAL or OUTCOME. A RETRYABLE refusal (concurrent-modification,visit-already-open,no-claimable-move, ...) is not stored and the same key runs again (ADR 0019); sweeps are naturally idempotent. Mutable aggregates carry aversion; aGETof one aggregate returns a weak ETag of it,PUT /sites/{siteId}/yard-policyhonoursIf-Match, and a staleIf-MatchisErrStalePolicy(412precondition-failed). Every Kafka consumer is idempotent on the CloudEventsid(inbox). -
Kafka-driven errors have no HTTP status. A policy refusal is logged and counted, the event is marked processed, and nothing is retried; an infrastructure failure rolls back and the message is redelivered.
-
Where the model was silent the flow first said proposed or this page's reading and named the gap. The decisions that closed the gaps (Y-1 to Y-14, X1 to X7; see the Model Gap Register) are now stated in the flows; what remains marked this page's reading is a detail the service does not state.
YardVisit
CheckInVisit
- Actor / trigger: gate clerk or kiosk (a camera or ANPR adapter issues the same command).
- Inbound adapter: REST
POST /visits. Body (OpenAPIcheckInVisit):siteId,carrier,carrierScac?,tractorPlate,driverRef?,purpose,appointmentId?,trailers(the trailers in). - Preconditions: none. A site with no declared
YardPolicyanswers the defaults (require_appointmentfalse,seal_mismatch_actionFLAG,lease_seconds300). - Main flow:
- Read the site's
YardPolicy(require_appointment,holding_spot_codes,parking_zone_ids,seal_mismatch_action). - Validate the carrier; refuse a second
CHECKED_INvisit for the plate. - A named appointment must be in this site's
AppointmentViewcopy and cover exactly one trailer of the visit, otherwiseErrUnknownAppointment(an appointment of another site is unknown here). If the site requires appointments, the visit must name aBOOKEDone (ErrAppointmentRequired); on a site that does not, a named appointment that is notBOOKED(cancelled, no-show) is dropped and the visit is a walk-in. - Create
YardVisitinCHECKED_IN. - For each trailer brought in,
RecordArrival(below). SealCheckAtGate: compare a recorded seal with the appointment'sexpected_seal_number; a match ends the sealVERIFIED, a mismatch ends itMISMATCHand raisesSealExceptionRaised, and underREJECTthe visit is recordedREJECTEDinstead, withVisitRejected(SEAL_MISMATCH)and aSealExceptionRaisedthat has no trailer (decision Y-5).DirectOnCheckInandVisitingDriverMove: for each trailer in, create the first move,CLAIMED, performerVISITING_DRIVER, no lease. Destination: a door when the appointment's door is free, not closed and flow-compatible (reasonTO_DOOR); the holding spot when it is a walk-in or the arrival is earlier than the tolerance (TO_HOLDING: the first free spot ofholding_spot_codesin order, and when the holding spots are all taken the first free spot of the parking zones); otherwise the first free spot of the parking zones by location code. Only when no spot at all is free is the refusalErrNoFreeSpot. A trailer that declares a hazard class or a temperature-control need is offered only the spots its rule allows (ADR 0014): a HAZMAT spot, or a REEFER_PLUG spot where the site has any.- Save and write
VisitCheckedInto the outbox, one transaction.
- Read the site's
| Error | HTTP | Problem type slug |
|---|---|---|
ErrInvalidCarrier | 422 | invalid-carrier |
ErrVisitAlreadyOpen | 409 | visit-already-open |
ErrUnknownAppointment (not in this site's local copy, or the visit does not bring exactly one trailer) | 422 | unknown-appointment |
ErrAppointmentRequired | 409 | appointment-required |
ErrTrailerAlreadyOnSite (from RecordArrival) | 409 | trailer-already-on-site |
ErrSealClassTooLow (site minimumSealClass; ADR 0012) | 409 | seal-class-too-low |
ErrCarrierSuspended (carrier suspended in dock-scheduling and the site policy suspendedCarrierAction is REJECT; the REJECTED visit is committed first and stored with the answer under the Idempotency-Key; ADR 0016) | 409 | carrier-suspended |
ErrDestinationReserved (first move) | 409 | destination-reserved |
ErrInvalidUnitNumber (ISO 6346 check; ADR 0012) | 422 | invalid-unit-number |
ErrInvalidSealClass (ADR 0012) | 422 | invalid-seal-class |
ErrInvalidHazmatClass (ADR 0014) | 422 | invalid-hazmat-class |
ErrInvalidUNNumber (ADR 0014) | 422 | invalid-un-number |
ErrPlacementRuleViolated (a trailer with a hazard class at a site with no HAZMAT spot; ADR 0014) | 409 | placement-rule-violated |
ErrValidation | 422 | validation |
- Events emitted:
VisitCheckedIn;SealExceptionRaisedwhen the seal mismatches;VisitRejectedunderREJECT; analytics move events for the first move. - Idempotency:
Idempotency-Key;ErrVisitAlreadyOpenis the natural second guard. - Settled gaps: the arrival tolerance comes from the appointment copy (X1); a move to a plain spot has the
reason
TO_SPOT(Y-4); with no free spot the check-in fails withErrNoFreeSpot(Y-12); the first move has no origin, it comes from the gate (Y-1). A walk-in or an arrival earlier than the tolerance goes to the first free holding spot of the policy, or to the first free spot when none is declared (assumption A17).
RejectAtGate
- Actor / trigger: gate clerk or kiosk, when a visit must not enter.
- Inbound adapter: REST
POST /visit-rejections. Body (OpenAPIrejectAtGate):siteId,carrier,carrierScac?,tractorPlate,appointmentId?,reason(aRejectionReason). - Preconditions: none (the rejected visit never became
CHECKED_IN). - Main flow:
- Validate the carrier and the reason.
- Create
YardVisitinREJECTED; no trailer is recorded on site. - Save and write
VisitRejectedto the outbox, one transaction.
| Error | HTTP | Problem type slug |
|---|---|---|
ErrInvalidCarrier | 422 | invalid-carrier |
ErrValidation (unknown reason) | 422 | validation |
- Events emitted:
VisitRejected(consumed bydock-scheduling, which cancels the appointment withTURNED_AWAY, and byexception-management). - Idempotency:
Idempotency-Key. - Settled gap: a refused
CheckInVisitcreates nothing,RejectAtGateis the one command that records a rejection, and theREJECTseal outcome uses it (decision Y-5).
CheckOutVisit
- Actor / trigger: gate clerk or kiosk.
- Inbound adapter: REST
POST /visits/{visitId}/check-outs. Body (OpenAPIcheckOutVisit):trailersOut, naming only the trailer ids (decision Y-9). - Preconditions: the visit is
CHECKED_IN. - Main flow:
- Load the visit and the trailers it takes out.
- Every trailer is on site and released: no open move, and either
PARKEDorDOCKEDwith door workDONE(a live visit leaves from its door; decision Y-2). - Every
LOADEDtrailer taken out of aLIVE_LOADorPICKUPvisit carries a seal (ErrSealRequired). Departfor each trailer taken out (decision Y-6).- Transition
CHECKED_IN → CHECKED_OUT, computeon_site_minutes. - Save and write
VisitCheckedOut(analytics) and, per trailer,TrailerDeparted(integration and analytics since ADR 0010) andTrailerUndocked(when it left a door), one transaction.
| Error | HTTP | Problem type slug |
|---|---|---|
ErrTrailerNotReleased | 409 | trailer-not-released |
ErrSealRequired | 409 | seal-required |
ErrDoorWorkOpen (from Depart; not reached through this route: a DOCKED trailer with door work not DONE is not released and trailer-not-released answers first) | 409 | door-work-open |
ErrIllegalTransition (the visit is not CHECKED_IN) | 409 | illegal-transition |
ErrNotFound | 404 | not-found |
ErrConcurrentModification | 409 | concurrent-modification |
- Events emitted:
VisitCheckedOut(analytics only),TrailerDeparted(integration, read byoutbound-shipping),TrailerUndocked. - Idempotency:
Idempotency-Key: a repeat under the same key replays the first answer; the same call under a new key on a visit alreadyCHECKED_OUTis409 illegal-transition.
Trailer
RecordArrival
- Actor / trigger:
CheckInVisit, once per trailer in. No route of its own. - Inbound adapter: internal (called by the visit use case).
- Preconditions: the natural key
(scac, number)is not already on site. - Main flow:
- Create
TrailerwithUnitNumber,TrailerKind,LoadState,Contents(asn_numbersfrom the appointment andAsnContentView, oroutbound_ref),SealandArrivedAt(the dwell clock start). - The trailer is created
IN_MOVEtogether with its first move, createdCLAIMED(decision Y-1);appointment_idis set from the visit. - Save.
- Create
| Error | HTTP | Problem type slug |
|---|---|---|
ErrTrailerAlreadyOnSite | 409 | trailer-already-on-site |
ErrValidation | 422 | validation |
- Events emitted: none of its own (
VisitCheckedIncarries the trailers). - Idempotency: the natural key; the visit's
Idempotency-Key.
StartMoving
- Actor / trigger: the
ClaimNextMoveuse case (and, for a visiting driver's move, its creation), in the same unit of work. Not an inbound message. - Preconditions: the trailer is
PARKEDorDOCKED. - Main flow:
- Transition to
IN_MOVE; the place (spot or door) is released (decision Y-8). - When it left a door: raise
TrailerUndocked(decision Y-6).
- Transition to
| Error | HTTP | Problem type slug |
|---|---|---|
ErrIllegalTransition | 409 | illegal-transition |
ErrTrailerStillSecured (a DOCKED trailer that is secured; ADR 0013) | 409 | trailer-still-secured |
- Events emitted:
TrailerUndockedwhen leaving a door (reading). - Idempotency: none of its own; the claim's.
ArriveAt
- Actor / trigger: the
CompleteMoveuse case, in the same unit of work. - Preconditions: the trailer is
IN_MOVE. - Main flow:
- The location is a known, active slot of the trailer's site (
LocationView). - For a door: not under a closure (
DoorClosureView), flow allows the trailer's direction (LocationView.dockFlow), the trailer is not on hold. Occupancy.CheckFreeon the location under a per-location advisory lock (a partial unique index is the backstop).- Transition to
PARKED(spot) orDOCKED(door); at a door,DoorWorkstartsWAITING. - Raise
TrailerParkedorTrailerDocked.
- The location is a known, active slot of the trailer's site (
| Error | HTTP | Problem type slug |
|---|---|---|
ErrUnknownLocation | 422 | unknown-location |
ErrDoorClosed | 409 | door-closed |
ErrDoorFlowMismatch | 409 | door-flow-mismatch |
ErrTrailerOnHold | 409 | trailer-on-hold |
ErrLocationOccupied | 409 | location-occupied |
ErrIllegalTransition | 409 | illegal-transition |
- Events emitted:
TrailerParked(analytics) orTrailerDocked(integration). - Idempotency: the completion's.
- Settled gaps: the destination is also validated when the move is requested, and an occupied location
at arrival is refused with the move staying
CLAIMED(decision Y-8); anEMPTYtrailer is unconstrained by door flow unless the visit purpose isLIVE_LOADorPICKUP(decision Y-9).
StartDoorWork
- Actor / trigger: dock operator (floor client).
- Inbound adapter: REST
POST /trailers/{trailerId}/door-work-starts. - Preconditions: the trailer is
DOCKEDand its door work isWAITING. - Main flow:
- Load the trailer.
- Under the site policy
requireSecuringBeforeDoorWork(default off) the trailer must be secured (ADR 0013);AutoCompleteUnloaddoes not use this check. - Set
DoorWorktoIN_PROGRESS. - Save and write
DoorWorkStarted(started_at) to the outbox. The driver wait KPI is arrival to this instant.
| Error | HTTP | Problem type slug |
|---|---|---|
ErrNotFound | 404 | not-found |
ErrIllegalTransition (not DOCKED) | 409 | illegal-transition |
ErrTrailerOnHold | 409 | trailer-on-hold |
ErrTrailerNotSecured (policy on and the trailer is not secured; ADR 0013) | 409 | trailer-not-secured |
ErrConcurrentModification | 409 | concurrent-modification |
- Events emitted:
DoorWorkStarted(analytics only). - Idempotency:
Idempotency-Key: a repeat under the same key replays the first answer; door work alreadyIN_PROGRESS(orDONE) under a new key is409 illegal-transition, onlyWAITINGstarts. A held trailer's door work does not start (ErrTrailerOnHold).
SecureTrailer
- Actor / trigger: dock operator (floor client); MCP
secure_trailerbehind an approval. - Inbound adapter: REST
POST /trailers/{trailerId}/securings(bodymethodRESTRAINTorWHEEL_CHOCKS,securerRef?). - Preconditions: the trailer is
DOCKEDand has no open move. - Main flow:
- Load the trailer.
- Record
securedBy,securedAtandsecurerRef. The same method again is a no-op (nothing saved or raised). - Save and write
TrailerSecuredto the outbox.
| Error | HTTP | Problem type slug |
|---|---|---|
ErrIllegalTransition (not DOCKED, or secured another way) | 409 | illegal-transition |
ErrTrailerHasOpenMove | 409 | trailer-has-open-move |
ErrValidation (method) | 422 | validation |
- Events emitted:
TrailerSecured(integration, ADR 0013). - Idempotency:
Idempotency-Key; the same method is returned unchanged.
ReleaseTrailerSecuring
- Actor / trigger: dock operator (floor client); MCP
release_securingbehind an approval. - Inbound adapter: REST
POST /trailers/{trailerId}/securing-releases. - Preconditions: the trailer is secured and its door work is not
IN_PROGRESS. - Main flow:
- Clear
securedBy,securedAtandsecurerRef. - Save and write
TrailerSecuringReleased. - Run
ClearDoorAfterWork(aDROPtrailer whose door work is done gets itsFROM_DOORmove, which was withheld while it was secured).
- Clear
| Error | HTTP | Problem type slug |
|---|---|---|
ErrTrailerNotSecured | 409 | trailer-not-secured |
ErrDoorWorkOpen (door work IN_PROGRESS) | 409 | door-work-open |
- Events emitted:
TrailerSecuringReleased(integration, ADR 0013). - Idempotency:
Idempotency-Key.
OpenInspection, RecordInspectionItem, CompleteInspection
- Actor / trigger: inspector (floor client); MCP
open_inspection,record_inspection_item,complete_inspectionbehind an approval. - Inbound adapter: REST
POST /trailers/{trailerId}/inspections(templateId,gate, optionaltemplateVersion,visitId,performerRef),PUT /inspections/{inspectionId}/items/{itemCode}(result,note?,evidenceRefs?),POST /inspections/{inspectionId}/completions(conditionGrade?). Templates:GET /inspection-templates[/{id}[/versions/{n}]],PUT /inspection-templates/{id}/versions/{n}. - Main flow: open snapshots the template version into a new
OPENinspection (one open per trailer, template and gate); each record replaces one item's result; completion needs every required item answered, endsPASSEDorFAILEDand, in the same unit of work, holds the trailer when it failed and the trailer carries no hold. - Gates:
RequestMoveto a door and the move of a check-in (PRE_DOCK),StartDoorWorkon a trailer that is being loaded (PRE_LOAD) andCheckOutVisittaking a trailer (PRE_DEPARTURE) ask the site policyrequiredInspections;AutoCompleteUnloadasks nothing.
| Error | HTTP | Problem type slug |
|---|---|---|
ErrInspectionRequired / ErrInspectionFailed (at a gate) | 409 | inspection-required / inspection-failed |
ErrInspectionClosed, ErrRequiredItemPending, ErrInspectionAlreadyOpen | 409 | inspection-closed, required-item-pending, inspection-already-open |
ErrUnknownItem, ErrNotApplicableNotAllowed, ErrUnknownTemplate | 422 | unknown-item, not-applicable-not-allowed, unknown-template |
ErrTemplateVersionImmutable, ErrTemplateIsBuiltIn | 409 | template-version-immutable, template-is-built-in |
- Events emitted:
InspectionCompletedand, when failed,InspectionFailedthenTrailerHeld(ADR 0015). - Idempotency:
Idempotency-Key; the version of the inspection is the ETag.
CompleteDoorWork
- Actor / trigger: dock operator; policy
AutoCompleteUnloadonReceiptClosed. - Inbound adapter: REST
POST /trailers/{trailerId}/door-work-completions(body: the resultingloadState, optional); Kafka consumer ofwarehouse.inbound-receiving.eventsfor the policy. - Preconditions: the trailer is
DOCKED. - Main flow:
- Load the trailer with its
version. - Set
DoorWorktoDONEand record theload_state(EMPTYfor the policy). - Save and write
DoorWorkCompletedto the outbox. ClearDoorAfterWork: aDROPtrailer gets aHOSTLERmoveFROM_DOORto a free spot (RequestMove); aLIVEtrailer stays until its visit checks out. How the trailer knows it is a drop is the visit's purpose.
- Load the trailer with its
| Error | HTTP | Problem type slug |
|---|---|---|
ErrNotFound | 404 | not-found |
ErrIllegalTransition (not DOCKED, or door work not IN_PROGRESS) | 409 | illegal-transition |
ErrConcurrentModification | 409 | concurrent-modification |
- Events emitted:
DoorWorkCompleted(integration since 2026-11-09, read byoutbound-shipping). - Idempotency:
Idempotency-Key, inbox for the policy; a repeat under the same key replays the first answer, completingDONEwork under a new key is409 illegal-transition. - Settled gap:
AutoCompleteUnloadjoins throughreceipt_idfromReceiptOpenedand completes door work (fromWAITINGorIN_PROGRESS) once every ASN on the trailer has a closed receipt (decision Y-7).
RecordSeal
- Actor / trigger: yard supervisor.
- Inbound adapter: REST
POST /trailers/{trailerId}/seals(body: seal number). - Preconditions: the trailer is on site.
- Main flow:
- Set
Seal{number, INTACT}(orAPPLIED), with the optional ISO 17712 class; a class below the site'sminimum_seal_classisErrSealClassTooLow(409seal-class-too-low), an unknown oneErrInvalidSealClass(422invalid-seal-class). - Save with the version check. Recording a seal compares nothing: the expected seal of the appointment is compared
only at check-in (
SealCheckAtGateinCheckInVisit, decision Y-13, assumption A9; ADR 0012), so a seal recorded here staysINTACTorAPPLIEDwhatever the appointment expected.
- Set
| Error | HTTP | Problem type slug |
|---|---|---|
ErrNotFound | 404 | not-found |
ErrValidation | 422 | validation |
ErrIllegalTransition (DEPARTED) | 409 | illegal-transition |
ErrConcurrentModification | 409 | concurrent-modification |
- Events emitted: none (
SealExceptionRaisedcomes only from the check-in). - Idempotency:
Idempotency-Key.
BreakSeal
- Actor / trigger:
RecordSealwith stateBROKEN(POST /trailers/{trailerId}/seals); no route of its own. - Inbound adapter: the seal route (body:
state,sealNumber?). - Preconditions: the trailer is on site.
- Main flow: set
Seal.statetoBROKEN, place aSEAL_BROKENhold and save (decision Y-6, assumption A10). - Errors:
ErrNotFound,ErrIllegalTransition. - Events emitted:
TrailerHeld(analytics only). - Idempotency: a seal already
BROKEN, or a trailer with no seal, is409 illegal-transitionunder a new key.
PlaceHold
- Actor / trigger: yard supervisor.
- Inbound adapter: REST
POST /trailers/{trailerId}/holds(body:reason, aHoldReason). - Preconditions: the trailer is on site and not already held.
- Main flow:
- Set
Hold{reason}. - Save and write
TrailerHeldto the outbox. A held trailer cannot be docked (ErrTrailerOnHold); a hold on an alreadyDOCKEDtrailer is allowed and door work then waits for the release (decision Y-13).
- Set
| Error | HTTP | Problem type slug |
|---|---|---|
ErrNotFound | 404 | not-found |
ErrValidation (unknown reason) | 422 | validation |
ErrTrailerOnHold (already held) | 409 | trailer-on-hold |
ErrIllegalTransition (DEPARTED) | 409 | illegal-transition |
ErrConcurrentModification | 409 | concurrent-modification |
- Events emitted:
TrailerHeld(analytics only). - Idempotency:
Idempotency-Key.
ReleaseHold
- Actor / trigger: yard supervisor.
- Inbound adapter: REST
POST /trailers/{trailerId}/hold-releases. - Preconditions: the trailer is on hold.
- Main flow: clear the hold; save; write
TrailerHoldReleased.
| Error | HTTP | Problem type slug |
|---|---|---|
ErrNotFound | 404 | not-found |
ErrTrailerNotOnHold (not held) | 409 | trailer-not-on-hold |
ErrConcurrentModification | 409 | concurrent-modification |
- Events emitted:
TrailerHoldReleased(analytics only). - Idempotency:
Idempotency-Key: a repeat under the same key replays the first answer; releasing a trailer that is not held under a new key is409 trailer-not-on-hold.
RecordLoadState
- Actor / trigger:
DoorWorkCompletedcarries aload_state, andAutoCompleteUnloadsetsEMPTY. - Inbound adapter: none of its own; the door-work completion body takes an optional
loadState. - Main flow: set
LoadState(EMPTY,LOADEDorPARTIAL); save. It is a step ofCompleteDoorWork. - Errors:
ErrNotFound,ErrValidation. - Events emitted: none of its own.
- Idempotency: setting the same value is a no-op.
Depart
- Actor / trigger:
CheckOutVisitcalls it for each trailer taken out. - Inbound adapter: none of its own (no route).
- Preconditions: the trailer is
PARKEDorDOCKED; ifDOCKED, its door work isDONE. - Main flow:
- Transition to
DEPARTED; computedwell_minutesfromArrivedAt. - Save; write
TrailerDepartedand, when it left a door,TrailerUndocked.
- Transition to
| Error | HTTP | Problem type slug |
|---|---|---|
ErrDoorWorkOpen | 409 | door-work-open |
ErrTrailerStillSecured (a DOCKED trailer that is still secured; ADR 0013) | 409 | trailer-still-secured |
ErrIllegalTransition (IN_MOVE or already DEPARTED) | 409 | illegal-transition |
- Events emitted:
TrailerDeparted(analytics),TrailerUndocked(integration, for a trailer leaving a door; reading). - Idempotency: the visit's.
DwellSweep
- Actor / trigger: scheduler (cron), policy
DwellSweep. - Inbound adapter: REST
POST /dwell-sweeps. - Preconditions: none.
- Main flow:
- For each trailer on site, compare its dwell (now minus
ArrivedAt) with thedwell_threshold_minutesof itsTrailerKindin the site'sYardPolicy. - For each trailer whose dwell has reached its threshold (dwell is at or above it: the alert fires AT the
threshold) and has not been reported for it, write
TrailerDwellExceeded(dwell_minutes,threshold_minutes,location_code). - Return the count raised.
- For each trailer on site, compare its dwell (now minus
| Error | HTTP | Problem type slug |
|---|---|---|
a missing threshold for a kind (no Err...) | — | skipped, logged |
- Events emitted:
TrailerDwellExceeded(consumed byexception-management). - Idempotency: once per trailer and threshold crossing, so a rerun raises nothing new;
the marker is
dwell_alerted_aton the trailer (decision Y-13). A kind without a threshold is never alerted.
YardMove
RequestMove
- Actor / trigger: yard supervisor; policies
DirectOnCheckIn,CallToDoor,ClearDoorAfterWork. - Inbound adapter: REST
POST /moves(body, OpenAPIrequestMove:trailerId,to,reason?,priorityBand?,dueBy?); the policies call the use case in-process. - Preconditions: the trailer is on site and not
IN_MOVEwith another move. - Main flow:
- Load the trailer;
from_locationis its current place. - Refuse if the trailer has another
REQUESTEDorCLAIMEDmove. - Under the destination's advisory lock: the destination is free
(
Occupancy.CheckFree) and no other open move names it; reserve it. 3a. For a yard spot, a trailer that carries a hazard class or needs temperature control must meet its placement rule (ErrPlacementRuleViolated, 409placement-rule-violated, ADR 0014); a door is exempt. - Create
YardMoveinREQUESTED, performerHOSTLER. - Save and write
YardMoveRequestedto the outbox.
- Load the trailer;
| Error | HTTP | Problem type slug |
|---|---|---|
ErrTrailerHasOpenMove | 409 | trailer-has-open-move |
ErrTrailerStillSecured (the trailer is secured at its door; ADR 0013) | 409 | trailer-still-secured |
ErrDestinationReserved | 409 | destination-reserved |
ErrPlacementRuleViolated (ADR 0014) | 409 | placement-rule-violated |
ErrNotFound (trailer) | 404 | not-found |
ErrValidation | 422 | validation |
- Events emitted:
YardMoveRequested(analytics only). - Idempotency:
Idempotency-Key; the open-move invariant is the guard. - Settled gap: the destination (known slot, closure, flow, hold) is validated at request and again at arrival
(decision Y-8). A missing
reasonis derived:TO_DOORfor a door,FROM_DOORfor a spot when the trailer isDOCKED,RELOCATEotherwise (assumption A6).
ClaimNextMove
- Actor / trigger: hostler (floor client).
- Inbound adapter: REST
POST /moves/claims(body, OpenAPIclaimNextMove:siteId,hostlerRef). - Preconditions: the hostler holds no
CLAIMEDmove. - Main flow:
- Refuse if the hostler already holds a
CLAIMEDmove. - Pick the next
REQUESTEDHOSTLERmove of the site: lowest priority band, then earliestdue_by(none last), then request time (decision Y-11), skipping rows locked by another claim. - Transition
REQUESTED → CLAIMEDwithLease{hostler_ref, expires_at}, whereexpires_at= now plus the site'slease_seconds. Trailer.StartMovingin the same unit of work.- Save and write
YardMoveClaimed.
- Refuse if the hostler already holds a
| Error | HTTP | Problem type slug |
|---|---|---|
ErrHostlerBusy | 409 | hostler-busy |
ErrConcurrentModification (another hostler won) | 409 | concurrent-modification |
| no move available | 404 | no-claimable-move |
ErrValidation | 422 | validation |
- Events emitted:
YardMoveClaimed(analytics only). - Idempotency:
Idempotency-Key; a replay returns the same claim.
CompleteMove
- Actor / trigger: the lease-holding hostler; for a
VISITING_DRIVERmove the dock operator or gate clerk (same route; decision Y-3). - Inbound adapter: REST
POST /moves/{moveId}/completions(body, OpenAPIcompleteMove:hostlerRef?,actualLocation?,deviationNote?). - Preconditions: the move is
CLAIMED. - Main flow:
- Load the move with its
version. - Only the lease holder completes it. A
VISITING_DRIVERmove has no lease. - A location other than the destination needs a reason.
Trailer.ArriveAt(actual_location), with its checks andOccupancy.CheckFree, in the same unit of work.- Transition
CLAIMED → COMPLETED; computeduration_seconds. - Save and write
YardMoveCompletedand the trailer'sTrailerParkedorTrailerDocked.
- Load the move with its
| Error | HTTP | Problem type slug |
|---|---|---|
ErrNotLeaseHolder | 409 | not-lease-holder |
ErrUnexplainedDestination | 422 | unexplained-destination |
ErrLocationOccupied, ErrDoorClosed, ErrDoorFlowMismatch, ErrTrailerOnHold, ErrUnknownLocation (from ArriveAt) | 409 / 422 | see ArriveAt |
ErrIllegalTransition (not CLAIMED, for example after lease expiry) | 409 | illegal-transition |
ErrNotFound | 404 | not-found |
ErrConcurrentModification | 409 | concurrent-modification |
- Events emitted:
YardMoveCompleted(analytics),TrailerParkedorTrailerDocked. - Idempotency:
Idempotency-Key: a repeat under the same key replays the first answer; completing aCOMPLETEDmove under a new key is409 illegal-transition.
CancelMove
- Actor / trigger: yard supervisor; policy
NoShowFreesHoldingonDockAppointmentNoShoworDockAppointmentCancelled. - Inbound adapter: REST
POST /moves/{moveId}/cancellations(body:reason); Kafka consumer ofwarehouse.dock-scheduling.eventsfor the policy. - Preconditions: the move is
REQUESTEDorCLAIMED. - Main flow:
- Load the move.
- Transition to
CANCELLED; release the destination reservation. - Save and write
YardMoveCancelled.
| Error | HTTP | Problem type slug |
|---|---|---|
ErrIllegalTransition (COMPLETED or already CANCELLED) | 409 | illegal-transition |
ErrNotFound | 404 | not-found |
ErrConcurrentModification | 409 | concurrent-modification |
- Events emitted:
YardMoveCancelled(analytics only). - Idempotency:
Idempotency-Key, inbox for the policy; a repeat under the same key replays the first answer, cancelling aCANCELLEDmove under a new key is409 illegal-transition. - Settled gaps: cancelling a
CLAIMEDhostler move runsReturnToOriginin the same unit of work, so the trailer goes back where it was (decision Y-1); the policy finds the move through theappointment_idthe move carries (decision X3).
ExpireLease
- Actor / trigger: scheduler (cron), policy
LeaseExpirySweep. - Inbound adapter: REST
POST /move-lease-sweeps. - Preconditions: none.
- Main flow:
- Select
CLAIMEDmoves whoseLease.expires_atis at or before now (the lease expires ATexpires_at). - For each, transition
CLAIMED → REQUESTEDand clear the lease; its destination stays reserved. - Return the count.
- Select
| Error | HTTP | Problem type slug |
|---|---|---|
a move that changed since selection (no Err...) | — | skipped, next sweep |
- Events emitted:
YardMoveLeaseExpired(analytics only, decision Y-10). - Idempotency: rerunning returns the same moves to
REQUESTEDonly once. - Settled gap: the trailer goes back where
StartMovingfound it (ReturnToOrigin, decision Y-1); when that origin has since been taken it staysIN_MOVEand the moveREQUESTED(assumption A16).
YardCheck
OpenYardCheck
- Actor / trigger: yard supervisor.
- Inbound adapter: REST
POST /yard-checks. - Main flow: refuse if the site has an
OPENcheck; createYardCheckinOPEN; save.
| Error | HTTP | Problem type slug |
|---|---|---|
ErrYardCheckOpen | 409 | yard-check-open |
ErrValidation | 422 | validation |
- Events emitted: none (the model lists only
YardCheckClosed). - Idempotency:
Idempotency-Key;ErrYardCheckOpenis the natural guard.
RecordObservation
- Actor / trigger: yard supervisor, walking the yard.
- Inbound adapter: REST
POST /yard-checks/{yardCheckId}/observations(body:location_code,unit_number?). - Preconditions: the check is
OPEN. - Main flow: refuse a location already observed in this check; append the
Observation; save.
| Error | HTTP | Problem type slug |
|---|---|---|
ErrLocationAlreadyObserved | 409 | location-already-observed |
ErrIllegalTransition (CLOSED) | 409 | illegal-transition |
ErrNotFound | 404 | not-found |
ErrValidation | 422 | validation |
- Events emitted: none.
- Idempotency:
Idempotency-Key; the same observation replayed is refused by the invariant.
CloseYardCheck
- Actor / trigger: yard supervisor.
- Inbound adapter: REST
POST /yard-checks/{yardCheckId}/closures. - Preconditions: the check is
OPEN. - Main flow:
- Compare the observations with the trailers the model places at those locations.
- Build the
Discrepancylist:MISSING,UNEXPECTEDorWRONG_LOCATION. The rules are: every observed location is compared with the trailer the model records there; a location not observed isMISSINGwhen the model records a trailer there; an observed unit that differs makes the expected trailerMISSINGand the observed unitWRONG_LOCATION(known elsewhere on site) orUNEXPECTED(unknown). Closing only reports (decision Y-11, assumption A13). - Transition
OPEN → CLOSED. - Save and write
YardCheckClosedwith the discrepancies.
| Error | HTTP | Problem type slug |
|---|---|---|
ErrIllegalTransition (CLOSED) | 409 | illegal-transition |
ErrNotFound | 404 | not-found |
ErrConcurrentModification | 409 | concurrent-modification |
- Events emitted:
YardCheckClosed(consumed byexception-management, one case per discrepancy). - Idempotency:
Idempotency-Key: a repeat under the same key replays the first answer; closing aCLOSEDcheck under a new key is409 illegal-transition.
YardPolicy
DeclareYardPolicy
- Actor / trigger: yard supervisor.
- Inbound adapter: REST
PUT /sites/{siteId}/yard-policy(If-Match for a change). - Main flow:
- Validate: holding spots are known Yard slots of the site (
LocationView); thresholds and lease are positive. - Replace the policy of the site:
require_appointment,holding_spot_codes,parking_zone_ids,dwell_threshold_minutesper kind,lease_seconds,seal_mismatch_action, optionalfree_time_minutes, optionalminimum_seal_class, optionalrequire_securing_before_door_work(default false, ADR 0013), optionalallow_hazmat_on_unclassified_spots(default false, ADR 0014). - Save.
- Validate: holding spots are known Yard slots of the site (
| Error | HTTP | Problem type slug |
|---|---|---|
ErrUnknownLocation | 422 | unknown-location |
ErrValidation | 422 | validation |
ErrStalePolicy (If-Match is not the policy's current version; no If-Match is unconditional) | 412 | precondition-failed |
ErrConcurrentModification | 409 | concurrent-modification |
- Events emitted: none (
YardPolicy.events: []). - Idempotency:
PUTreplaces, and every acceptedPUTraises the policyversionby one, an identical body included (it is not a no-op); a repeat under the sameIdempotency-Keyreplays the first answer.
Event-driven reactions that are not commands
These policies react to a Kafka event and call the use cases above; the projectors update the read models in their own transaction.
| Trigger event | Reaction | Use case called |
|---|---|---|
TrailerUndocked (own) | CallToDoor | RequestMove (HOSTLER, TO_DOOR) |
DoorWorkCompleted (own) | ClearDoorAfterWork | RequestMove (FROM_DOOR) for a DROP trailer |
ReceiptClosed (inbound-receiving) | AutoCompleteUnload | CompleteDoorWork |
DockAppointmentNoShow, DockAppointmentCancelled | NoShowFreesHolding | CancelMove |
DockAppointmentBooked, Rescheduled, Cancelled, NoShow | projector | AppointmentView |
DoorClosureScheduled, DoorClosureLifted | projector | DoorClosureView |
LocationSlotRegistered, LocationSlotDecommissioned, ZoneRegistered | projector | LocationView |
ASNRegistered, ASNCancelled | projector | AsnContentView |
ReceiptOpened, ReceiptClosed | projector | ReceiptAtDoorView |