Skip to main content

Sequence Diagrams

One UML sequence diagram per command use case of Use Cases, in the hexagonal layout of the built service: inbound adapter → use case → aggregate → repositories and views → outbox (same transaction) → relay → Kafka. The outbox, the relay and Kafka share one lifeline ("outbox and relay to Kafka") to keep each diagram at five participants. alt blocks show error branches, optimistic-concurrency version checks and idempotency (REST Idempotency-Key, Kafka inbox on the CloudEvents id). Every Err... has the status of decision D-10 (409 conflicts, 422 value rules, 404 unknown resources; the complete table is on Use cases). Route parameters are written without braces. The relay publishes to warehouse.dock-scheduling.events for integration events and, as a twin, to warehouse.dock-scheduling.analytics; events marked analytics only go to the analytics topic alone. Both are keyed by the aggregate root id.

1. BookAppointment​

Carrier scheduler, REST POST /appointments.

Source: internal/domain/dockappointment/appointment.go, internal/domain/dockappointment/commands.go, internal/domain/dockappointment/events.go, internal/adapters/outbound/kafka/encoder.go, apis/asyncapi.yaml, internal/adapters/inbound/http/errors.go, internal/application/usecases/facts.go.

Omitted: the per-door lock is released at commit (not drawn). The per-door lock is taken first (internal/application/usecases/book.go); the HTTP statuses are decision D-10. slot_granularity_minutes forces the window start and end onto a grid of whole minutes since the Unix epoch (ErrInvalidWindow, decision D-11), and an ASN already on another active appointment is refused (ErrAsnAlreadyScheduled).

2. RescheduleAppointment​

Carrier scheduler, REST POST /appointments/appointmentId/reschedules.

Source: internal/domain/dockappointment/appointment.go, internal/domain/dockappointment/commands.go, internal/domain/dockappointment/events.go, internal/adapters/outbound/kafka/encoder.go, apis/asyncapi.yaml.

Omitted: the idempotency replay branch (drawn in diagram 1); a reschedule may also change the door (decision D-4); the event then carries previous_door_code.

3. CancelAppointment​

Carrier scheduler, REST POST /appointments/appointmentId/cancellations. The policy CancelWhenAllAsnsCancelled calls the same use case with reason ASN_CANCELLED from the Kafka consumer of ASNCancelled.

Source: internal/domain/dockappointment/appointment.go, internal/domain/dockappointment/commands.go, internal/domain/dockappointment/events.go, internal/application/usecases/facts.go, internal/application/usecases/yard.go, internal/application/usecases/change.go.

Omitted: the inbox check on the policy path (drawn in diagram 5) and the idempotency replay on the REST path (diagram 1). On the policy path there is no HTTP reply: a non-cancellable appointment is skipped.

4. ReportEta​

Carrier scheduler, REST POST /appointments/appointmentId/eta-reports. Policy EtaRisk decides whether the report raises an advisory.

Source: internal/domain/dockappointment/appointment.go, internal/domain/dockappointment/commands.go, internal/domain/dockappointment/events.go, internal/application/usecases/facts.go, internal/application/usecases/yard.go, internal/application/usecases/change.go, internal/adapters/outbound/kafka/encoder.go, apis/asyncapi.yaml.

Omitted: the relay step publishes only when an AtRisk row exists; nothing is rescheduled. BOOKED is the only state that accepts an ETA (assumption A6); a later on-time ETA or a reschedule clears the at-risk flag.

5. RecordArrival​

Policy ArrivalFromGate on VisitCheckedIn naming an appointment_id.

Source: internal/application/usecases/facts.go, internal/application/usecases/yard.go, internal/application/usecases/change.go, internal/adapters/outbound/kafka/encoder.go, apis/asyncapi.yaml.

Omitted: an appointment already CHECKED_IN is left unchanged and counted, so only BOOKED reaches the aggregate. The arrival_status formula is decision X6: EARLY before window_start minus the tolerance, LATE after window_start plus the tolerance, else ON_TIME.

6. ReassignDoor​

Policy ActualDoorWins on TrailerDocked whose door differs from the booked door.

Source: internal/application/usecases/facts.go, internal/application/usecases/yard.go, internal/application/usecases/change.go, internal/adapters/outbound/kafka/encoder.go, apis/asyncapi.yaml.

Omitted: ErrDoorDoubleBooked is deliberately not raised: the physical fact wins. BOOKED and CHECKED_IN accept the command, and a same-door event changes nothing. The reassignment is also written to the integration topic (service ADR 0010), so the closing note's analytics topic is not the only target.

7. RecordDoorRelease​

Policy CompleteOnDoorRelease on TrailerUndocked naming an appointment_id.

Source: internal/domain/dockappointment/appointment.go, internal/domain/dockappointment/commands.go, internal/domain/dockappointment/events.go, internal/application/usecases/facts.go, internal/application/usecases/yard.go, internal/application/usecases/change.go.

Omitted: no DockAppointmentCheckedIn is written for an implicit arrival (the adherence report counts it as ON_TIME); one appointment covers exactly one trailer (decision X3).

8. MarkNoShow​

Scheduler (cron), REST POST /no-show-sweeps, policy NoShowSweep.

Source: internal/domain/dockappointment/appointment.go, internal/domain/dockappointment/commands.go, internal/domain/dockappointment/events.go, internal/application/usecases/facts.go, internal/application/usecases/yard.go, internal/application/usecases/change.go, internal/adapters/outbound/kafka/encoder.go, apis/asyncapi.yaml.

Omitted: the idempotency replay (diagram 1). A rerun selects only what still qualifies.

9. ImportLegacyAppointment (removed)​

The policy LegacyImport (the strangler stage A importer of inbound-receiving's DockAppointment* events) was removed in ADR 0011. The diagram is gone; the number stays so the later diagrams keep theirs.

10. DeclareOperatingHours​

Dock planner, REST PUT /sites/siteId/dock-calendar/operating-hours.

Source: internal/domain/dockcalendar/calendar.go, internal/domain/dockcalendar/events.go.

Omitted: the idempotency replay (diagram 1). The calendar is created lazily with the defaults at first use (decision D-1); new hours that leave an active appointment outside them are refused with ErrHoursConflictWithAppointments (decision D-8), a branch this diagram does not draw.

11. DeclareCalendarSettings​

Dock planner, REST PUT /sites/siteId/dock-calendar/settings.

Source: internal/domain/dockcalendar/calendar.go, internal/domain/dockcalendar/events.go.

Omitted: no outbox row and no relay: the service raises no event for this command (decision D-11 fixes the bounds). The idempotency replay is as in diagram 1.

12. ScheduleDoorClosure​

Dock planner, REST POST /sites/siteId/dock-calendar/closures.

Source: internal/domain/dockcalendar/calendar.go, internal/domain/dockcalendar/events.go, internal/adapters/outbound/kafka/encoder.go, apis/asyncapi.yaml.

Omitted: the idempotency replay (diagram 1). The active appointments are read from another aggregate while the door's advisory lock and the calendar row lock are held, so a booking on that door cannot commit between the read and the save.

13. LiftDoorClosure​

Dock planner, REST POST /sites/siteId/dock-calendar/closures/closureId/lifts.

Source: internal/domain/dockcalendar/calendar.go, internal/domain/dockcalendar/events.go, internal/adapters/outbound/kafka/encoder.go, apis/asyncapi.yaml.

Omitted: the idempotency replay (diagram 1).