Skip to main content

Class Diagram

UML class diagrams of the internal/domain/** packages (dockappointment, dockcalendar, shared), then the hexagonal ports and adapters in the Go layout the fleet uses. Type and field names come from the yard design model; method names are the design model's commands. Fields are shown - (unexported), methods +.

In the code: the package names are the design model's. The Go methods of the root are shorter than the command names drawn here (Reschedule, Cancel, ReportEta, MarkAtRisk, RecordArrival, ReassignDoor, RecordDoorRelease, MarkNoShow), booking is a constructor, the state type is State, the per-site Rules value (max window, granularity, arrival tolerance, no-show grace) is passed to the methods that need it, and the repository is AppointmentRepo (diagram 1c). The ports and adapters are in the code in diagram 5; the drawn fields and methods are not a copy of the code.

1. DockAppointment aggregate​

1a. Root and states​

Source: internal/domain/dockappointment/, internal/domain/dockcalendar/, internal/domain/shared/shared.go, internal/application/ports/ports.go, internal/adapters/.

1b. Value objects​

Source: internal/domain/dockappointment/, internal/domain/dockcalendar/, internal/domain/shared/shared.go, internal/application/ports/ports.go, internal/adapters/.

1c. Domain service and repository​

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 error variables (see Aggregate Design Canvas); version handling beyond the field. siteId and provenance are in the event payloads and not in the aggregate's value-object list; they are drawn as fields on this page's reading. Window is the design model's Window with start and end; the fields are named windowStart and windowEnd here to avoid the diagram keyword end. BookAppointment(cmd) stands for the booking inputs (door, direction, window, carrier, references, expected seal). The advisory that ReportEta may raise (DockAppointmentAtRisk) is an event, not a return value. The commands that policies drive (RecordArrival, ReassignDoor, RecordDoorRelease) have no REST route. ListActiveOnDoor and ListBookedEndedBy are repository queries the rules need (the overlap check and the no-show sweep); LockDoor takes the per-door advisory lock for the rest of the unit of work, and Save is guarded by the version the caller loaded. DoorSchedule is the domain service named by ErrDoorDoubleBooked; the checks that need DoorView, AsnView, CutoffView and DockCalendar are in diagram 4.

2. DockCalendar aggregate​

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

Omitted: ErrInvalidOperatingHours, ErrOverlappingClosure and ErrClosureConflictsWithAppointments. activeAppointments is a parameter of ScheduleDoorClosure because the refusal needs the appointments of the door and lists their ids; the two aggregates stay separate (this page's reading). doorCode on OperatingHours is empty for the site default. The design model gives no weekday type and states no bound for the settings.

3. Appointment events and the policies that raise them​

3a. Yard facts and ETA risk​

Source: internal/domain/dockappointment/, internal/domain/dockcalendar/, internal/domain/shared/shared.go, internal/application/ports/ports.go, internal/adapters/.

3b. Booking, cancelling, no-show and import​

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: the CloudEvents envelope (see Domain Events); PickupFromCutoffs (phase 2, names no command or event of its own); OutOfOrderYardFacts, which is a rule on RecordDoorRelease and RecordArrival rather than a source of events. BookAppointment, RescheduleAppointment and CancelAppointment by a carrier raise DockAppointmentBooked, Rescheduled and Cancelled directly, not through a policy; DockAppointmentRescheduled has no policy at all. The LegacyImport policy that once raised DockAppointmentBooked was removed (ADR 0011).

4. Read models and the checks that use them​

Source: internal/domain/dockappointment/appointment.go, internal/domain/dockappointment/commands.go, internal/domain/dockappointment/events.go, internal/adapters/inbound/kafka/yard_consumer.go, internal/adapters/inbound/kafka/facility_consumer.go, internal/adapters/inbound/kafka/asn_consumer.go, internal/adapters/inbound/kafka/cutoff_consumer.go, internal/application/ports/ports.go, migrations/0001_dock_scheduling.up.sql.

Reading the diagram: an arrow into DockAppointment is a check a booking makes against that copy, and the Err... listed in the source box is the refusal. DoorAvailabilityView is built from DockAppointment and DockCalendar state; AdherenceReport is built from the appointment events on the analytics topic.

Omitted: the projectors that fill DoorView, AsnView and CutoffView (shown in the ports view below). DockCalendar is an aggregate of this context, not a copy; it is drawn here because a booking reads it. The cancelled flag of an ASN is this page's reading of how ASNCancelled is stored.

5. Hexagonal ports and adapters​

5a. Inbound adapters, use cases and domain​

Source: internal/domain/dockappointment/, internal/domain/dockcalendar/, internal/domain/shared/shared.go, internal/application/ports/ports.go, internal/adapters/.

5b. Ports and outbound adapters​

Source: internal/application/usecases/facts.go, internal/application/usecases/yard.go, internal/application/usecases/change.go, internal/adapters/inbound/kafka/yard_consumer.go, internal/adapters/inbound/kafka/facility_consumer.go, internal/adapters/inbound/kafka/asn_consumer.go, internal/adapters/inbound/kafka/cutoff_consumer.go, internal/application/ports/ports.go, migrations/0001_dock_scheduling.up.sql, internal/adapters/inbound/http/errors.go.

All paths are under internal/. The dashed arrows mean every use case calls ports only: the repository of its aggregate, the event publisher (outbox), the inbox (ProcessedEvents), the unit of work, the clock and the id generator; the per-door advisory lock is AppointmentRepo.LockDoor, and the read-model ports (DoorView, AsnView, CutoffView) are separate interfaces. Report readers (AdherenceReader, FreshnessReader) belong to the reports binary. The http adapter drives the carrier and planner commands and the sweep, which a Kubernetes CronJob calls over REST, so there is no scheduler adapter. The kafka adapter drives the policies (ArrivalFromGate, ActualDoorWins, CompleteOnDoorRelease, CancelWhenAllAsnsCancelled) and the projectors; the AdherenceReport projector reads this context's own analytics topic.

Omitted: the HTTP read path (GET routes read the repositories and DoorAvailabilityView directly); the MCP adapter (internal/adapters/inbound/mcp, fourteen tools: seven L1 reads and seven L3 writes, service ADRs 0007 and 0012), the analytics projector and the report binary. There are no outbound HTTP clients: sync_calls is empty.