Skip to main content

API overview

:::info Implemented by cmd/api, cmd/mcp and cmd/a2a cmd/api serves every REST route below (internal/adapters/inbound/http) on HTTP_ADDR (default :8080). The contracts are apis/openapi.yaml (OpenAPI 3.0.3, version 0.1.0) and apis/asyncapi.yaml (AsyncAPI 3.0.0, version 1.0.0). The router registers exactly the eleven resource paths of the spec plus /healthz and /readyz, which the spec does not list. See the Quickstart for real responses. :::

InterfaceSource of truthNotes
RESTapis/openapi.yamlThe pages under REST are generated from the spec with npm run gen-api-docs; do not edit them by hand. Server named in the spec: http://localhost:8080. Through Kong on the kind cluster: http://localhost:8000/api/linehaul-transportation (prefix stripped).
Eventsapis/asyncapi.yamlTwo published topics and three consumed ones; summarised on the event catalogue, every field on Domain events.
MCPADR 0008, internal/adapters/inbound/mcpcmd/mcp serves Streamable HTTP on /mcp and / (port 8090; Kong /api/mcp/linehaul-transportation, opt-in). Two read-only tools, no write tool: list_departures and get_departure. See MCP tools. No auth, by fleet decision.
A2AADR 0011, internal/adapters/inbound/a2acmd/a2a serves JSON-RPC 2.0 on / and /a2a (port 8093; Kong /api/a2a/linehaul-transportation, opt-in) and the Agent Card at /.well-known/agent-card.json. Two read-only skills, no write skill: list_departures (origin, destination, from, to, limit) and get_departure (departureId). A request is the data part {"skill":"<id>","arguments":{...}} of a SendMessage call; unknown arguments are refused and rejections come back in the message as problems (404 not-found, 422 validation-failed, 400 malformed-request, unknown-skill or invalid-argument, 500 internal-error), never as JSON-RPC errors. No auth, by fleet decision.

Endpoints​

TagEndpointOperation idSuccessNotes
Lane schedulesPOST /lane-schedulesdefineLaneSchedule201 created, 200 slots replacedBody laneId, slots[1..100]; lane must be known
Lane schedulesPOST /lane-schedules/{laneId}/retirementsretireLaneSchedule200Idempotent on a RETIRED schedule
DeparturesGET /departureslistDepartures200 {items,nextCursor}Filters origin, destination, from, to; limit (1..500, default 100) and cursor; ordered by cutoffAt, then departureId
DeparturesGET /departures/{departureId}getDeparture200404 not-found
DeparturesPOST /departures/{departureId}/cancellationscancelDeparture200Body reason; rebooks the assignments booked on it
DeparturesPUT /departures/{departureId}/capacitychangeDepartureCapacity200Idempotent by method, no key; body capacityPackages; not below the booked count
LoadsPOST /loadsopenLoad201Body departureId; one load per departure
LoadsPOST /loads/{loadId}/packagesaddPackageToLoad200Body trackingNumber (max 64 characters)
LoadsPOST /loads/{loadId}/closurescloseLoad200OPEN to CLOSED
LoadsPOST /loads/{loadId}/dispatchesdispatchLoad200CLOSED to DEPARTED
LoadsPOST /loads/{loadId}/receiptsreceiveLoad200DEPARTED to ARRIVED
HealthGET /healthz, GET /readyznone (not in the spec)200/readyz is 503 while draining or when Postgres or Kafka is down; cmd/mcp and cmd/a2a serve /healthz only

Conventions in the contract​

  • Errors are RFC 9457 application/problem+json with type = https://retailnetwork.example/problems/<slug>. The slugs: malformed-request, request-body-too-large, not-found, invalid-departure-times, overlapping-slots, validation-failed, departure-full, lane-closed, departure-closed, package-already-loaded, load-over-capacity, load-already-exists, illegal-transition, concurrent-update, idempotency-key-required, idempotency-key-invalid, idempotency-key-reused and internal-error. Statuses and remedies are on Troubleshooting.
  • Idempotency-Key. Required on every POST (400 idempotency-key-required when absent, idempotency-key-invalid unless 1 to 128 printable ASCII characters); the key is global, not per route. PUT is idempotent by method and takes none. The same key with the same method, path and body replays the first stored response with Idempotency-Replayed: true for 24 hours when it is final for the request (a 2xx, or a refusal that is a function of the request alone: malformed-request, request-body-too-large, invalid-departure-times, overlapping-slots, validation-failed, load-over-capacity, load-already-exists); the same key with a different request is 409 idempotency-key-reused while the key holds a stored answer. 5xx answers are not stored, and neither is a refusal that depends on state another request can change (concurrent-update, departure-closed, departure-full, illegal-transition, lane-closed, not-found, package-already-loaded): the key is released and a retry under it runs again (ADR 0015).
  • Optimistic concurrency. Aggregates carry a version; a write that loses a race is 409 concurrent-update.
  • Time. Every instant is RFC 3339 in UTC. Lane-schedule slots are wall-clock HH:MM times: cutoff and departure in the time zone of the lane's origin node, arrival in the zone of its destination node.
  • Paging. GET /departures is keyset-paged by (cutoffAt, departureId): limit (1..500, default 100) and the opaque cursor, answered as {items,nextCursor} (nextCursor is absent on the last page; repeat the filters on every page). An invalid limit is 400 invalid-limit, an undecodable cursor 400 invalid-cursor, any other query parameter 400 unknown-query-parameter. MCP and A2A keep their own limit (1..1000, default 500).
  • Commands are idempotent by state. Repeating a command that already holds (close of a CLOSED load, cancel of a CANCELLED departure) returns the resource unchanged.
  • Auth: none. The fleet reverted REST, MCP and A2A auth, and TestNoAuthMiddlewareReintroduced fails CI if auth middleware returns under internal/adapters/inbound.
  • Events are CloudEvents 1.0, structured mode; the contract is dispatched on the full type, deduplicated on id, and unknown types are ignored by consumers.

Discrepancies between spec and code​

  • apis/openapi.yaml lists no /healthz and /readyz; the code serves both (internal/adapters/inbound/http/server.go).
  • The AsyncAPI server block names kafka.retail-network.internal:9092 as an example host; the real broker comes from KAFKA_BROKERS (platform broker localhost:9092 from the host).