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.
:::
| Interface | Source of truth | Notes |
|---|---|---|
| REST | apis/openapi.yaml | The 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). |
| Events | apis/asyncapi.yaml | Two published topics and three consumed ones; summarised on the event catalogue, every field on Domain events. |
| MCP | ADR 0008, internal/adapters/inbound/mcp | cmd/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. |
| A2A | ADR 0011, internal/adapters/inbound/a2a | cmd/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
| Tag | Endpoint | Operation id | Success | Notes |
|---|---|---|---|---|
| Lane schedules | POST /lane-schedules | defineLaneSchedule | 201 created, 200 slots replaced | Body laneId, slots[1..100]; lane must be known |
| Lane schedules | POST /lane-schedules/{laneId}/retirements | retireLaneSchedule | 200 | Idempotent on a RETIRED schedule |
| Departures | GET /departures | listDepartures | 200 {items,nextCursor} | Filters origin, destination, from, to; limit (1..500, default 100) and cursor; ordered by cutoffAt, then departureId |
| Departures | GET /departures/{departureId} | getDeparture | 200 | 404 not-found |
| Departures | POST /departures/{departureId}/cancellations | cancelDeparture | 200 | Body reason; rebooks the assignments booked on it |
| Departures | PUT /departures/{departureId}/capacity | changeDepartureCapacity | 200 | Idempotent by method, no key; body capacityPackages; not below the booked count |
| Loads | POST /loads | openLoad | 201 | Body departureId; one load per departure |
| Loads | POST /loads/{loadId}/packages | addPackageToLoad | 200 | Body trackingNumber (max 64 characters) |
| Loads | POST /loads/{loadId}/closures | closeLoad | 200 | OPEN to CLOSED |
| Loads | POST /loads/{loadId}/dispatches | dispatchLoad | 200 | CLOSED to DEPARTED |
| Loads | POST /loads/{loadId}/receipts | receiveLoad | 200 | DEPARTED to ARRIVED |
| Health | GET /healthz, GET /readyz | none (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+jsonwithtype = 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-reusedandinternal-error. Statuses and remedies are on Troubleshooting. Idempotency-Key. Required on every POST (400 idempotency-key-requiredwhen absent,idempotency-key-invalidunless 1 to 128 printable ASCII characters); the key is global, not per route.PUTis idempotent by method and takes none. The same key with the same method, path and body replays the first stored response withIdempotency-Replayed: truefor 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 is409 idempotency-key-reusedwhile 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:MMtimes: cutoff and departure in the time zone of the lane's origin node, arrival in the zone of its destination node. - Paging.
GET /departuresis keyset-paged by(cutoffAt, departureId):limit(1..500, default 100) and the opaquecursor, answered as{items,nextCursor}(nextCursoris absent on the last page; repeat the filters on every page). An invalidlimitis400 invalid-limit, an undecodable cursor400 invalid-cursor, any other query parameter400 unknown-query-parameter. MCP and A2A keep their ownlimit(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
TestNoAuthMiddlewareReintroducedfails CI if auth middleware returns underinternal/adapters/inbound. - Events are CloudEvents 1.0, structured mode; the contract is dispatched on the full
type, deduplicated onid, and unknown types are ignored by consumers.
Discrepancies between spec and code
apis/openapi.yamllists no/healthzand/readyz; the code serves both (internal/adapters/inbound/http/server.go).- The AsyncAPI server block names
kafka.retail-network.internal:9092as an example host; the real broker comes fromKAFKA_BROKERS(platform brokerlocalhost:9092from the host).