Skip to main content

Architecture

dock-scheduling follows the fleet's hexagonal layout: dependencies point inward, the domain imports nothing from the rest of the module, and only cmd/ wires the layers together. The rules are enforced by TestHexagonalArchitecture and its siblings in internal/architecture.

Source: internal/, cmd/, migrations/, analytics/migrations/, charts/dock-scheduling/.

Layout​

LayerPathRole
Domaininternal/domain/dockappointmentDockAppointment aggregate: states, Window, Eta, Arrival, commands (Book, Reschedule, Cancel, ReportEta, arrival, door reassignment, release, no-show), DoorSchedule overlap check and the domain events.
Domaininternal/domain/dockcalendarDockCalendar aggregate (one per site): Settings, operating hours, closures, free/busy availability, the calendar events.
Domaininternal/domain/sharedValue objects: DoorCode, SiteID, Carrier (name and SCAC), Direction, DockFlow.
Applicationinternal/application/usecasesThe Service: commands (book.go, change.go, calendar.go), queries (queries.go), the Kafka-driven fact use cases (facts.go, yard.go), the idempotent write wrapper and the Initiator attribution (initiator.go).
Applicationinternal/application/portsOut ports: AppointmentRepo, CalendarRepo, DoorView, AsnView, CutoffView, ProcessedEvents, IdempotencyStore, EventPublisher, Metrics, IDGen, Clock, UnitOfWork, AdherenceReader, FreshnessReader.
Applicationinternal/application/views, repository, outboxRead models returned to adapters, filters and paging records, and the already-encoded outbox Row/fact types.
Inbound adapterinternal/adapters/inbound/httpchi router for apis/openapi.yaml: handlers, RFC 7807 problems (errors.go), Idempotency-Key middleware, ETag/If-Match, /healthz, /readyz, /metrics; plus the reports router for apis/openapi-reports.yaml. No auth middleware.
Inbound adapterinternal/adapters/inbound/kafkaThe yard, facility, ASN and CPT consumers and the analytics consumer: CloudEvents decode, dispatch on the full type, retry with backoff, dead-letter topic. Decode only; every effect is a use case.
Inbound adapterinternal/adapters/inbound/mcpMCP server (Streamable HTTP): five read tools, four write tools, one resource and prompts, authority levels.
Outbound adapterinternal/adapters/outbound/postgrespgx repositories, unit of work (pgtx), outbox publisher and store, idempotency store, embedded migrations.
Outbound adapterinternal/adapters/outbound/analyticsstoreThe analytical database: writer Projection, read-only Reader, its own migrations.
Outbound adapterinternal/adapters/outbound/outboxThe relay loop that drains the outbox to a handler.
Outbound adapterinternal/adapters/outbound/kafkaCloudEvents encoder (ADR 0004 catalogue), RelaySink, writers (acks=all, no fixed topic), BrokerCheck for /readyz.
Outbound adapterinternal/adapters/outbound/telemetry, systemPrometheus metrics; the production Clock and ID generator.
Outbound adapterinternal/adapters/outbound/memoryIn-memory implementation of every port: a test double. No cmd/ imports it (TestRuntimeBinaryHasNoInMemoryAdapters).
Kafka envelopeinternal/adapters/kafka/cloudeventsThe only place a CloudEvents 1.0 envelope is built or decoded. Repo = "dock-scheduling", Subdomain = "wms", Source = "/warehouse/dock-scheduling".
Supportinternal/bootretry, internal/configBoot retry for the first dials; shared env parsing for the outbox knobs, brokers, drain delay.
Test supportinternal/testing/{kafkatest,pgtest,repocontract}Testcontainers helpers and the repository contract suite run against both the memory and Postgres adapters.
Fitness testsinternal/architectureSource-scanning and dependency tests (see Testing).

Binaries and ports​

All six binaries are built into one image (Dockerfile loops over cmd/*).

BinaryRolePortProbes
cmd/apiREST API, in-process outbox relay and the four Kafka consumers, all always on, on real Postgres and Kafka.HTTP_ADDR, default :8080GET /healthz, GET /readyz (Postgres ping and a Kafka metadata request), GET /metrics
cmd/mcpMCP server, Streamable HTTP, over the same use cases; no relay, no consumer. Serves /mcp and /.MCP_ADDR, default :8090GET /healthz, GET /readyz, GET /metrics
cmd/projectorThe only writer of the analytical database: consumes warehouse.dock-scheduling.analytics; exits non-zero if its consumer stops.ADMIN_ADDR, default :8091GET /healthz, GET /readyz
cmd/reportsRead-only HTTP reader of the analytical database: /reports/schedule-adherence, /reports/freshness.HTTP_ADDR, default :8092GET /healthz, GET /readyz, GET /metrics
cmd/relayOptional stand-alone outbox relay (same loop as the api's). No migrations.ADMIN_ADDR, default :8094GET /healthz
cmd/sweepOne-shot CronJob entrypoint: POSTs /no-show-sweeps with retry, then asks the sidecar to quit.noneexit code

There is no cmd/a2a: this service has no A2A server. Variables per binary are in Configuration; boot and shutdown order in the Runbook.

Container diagram​

Source: cmd/api/main.go, cmd/mcp/main.go, cmd/projector/main.go, cmd/reports/main.go, cmd/relay/main.go, cmd/sweep/main.go, charts/dock-scheduling/templates/.

Data stores​

StoreOwnerContents
Postgres OLTP (DATABASE_URL)cmd/api (writer), cmd/mcp, cmd/relay (outbox only)Aggregates: dock_appointments, asn_claims, dock_calendars, calendar_operating_hours, calendar_closures. Local copies: zones, doors, asns, cutoff_schedules, cutoffs. Plumbing: processed_events (consumer dedupe), outbox, idempotency_keys. Migrations in migrations/, applied at boot by cmd/api and cmd/mcp.
Postgres analytics (ANALYTICS_DATABASE_URL)cmd/projector (the only writer), cmd/reports (read-only)analytics_processed_events, appointment_facts. Migrations in analytics/migrations/, applied by the projector.
Kafka (one broker platform-wide)outbox relay (producer), consumersTopics listed in the Runbook.

Delivery is at-least-once with an atomic effect: every consumer claims the CloudEvents id in processed_events inside the same transaction as its effect, and every aggregate change writes its outbox rows in the same transaction as the aggregate. See ADR 0005, ADR 0006 and ADR 0009.