API overview
:::info Implemented by cmd/api, cmd/mcp and cmd/a2a
cmd/api serves every REST route below (internal/adapters/inbound/http/server.go)
on HTTP_ADDR (default :8080). The contracts are apis/openapi.yaml and
apis/asyncapi.yaml, pinned by
ADR 0001 and
ADR 0004. The router
registers exactly the nine business routes of the spec plus /healthz and
/readyz; no route exists in the code that the spec does not list. Real
responses are in the Quickstart.
:::
| Interface | Source of truth | Notes |
|---|---|---|
| REST | apis/openapi.yaml (OpenAPI 3.0.3, version 0.1.0) | 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 in the kind cluster the base path is /api/customer-ordering (prefix stripped). |
| Events | apis/asyncapi.yaml (AsyncAPI 3.0.0, version 1.0.0) | Summarised on the event catalogue; every field on Domain events. |
| MCP | ADR 0005, internal/adapters/inbound/mcp | cmd/mcp serves Streamable HTTP on /mcp and / (MCP_ADDR, default :8090; through Kong /api/mcp/customer-ordering). Three read-only tools, no write tool: get_order, get_order_tracking, get_ship_to (see MCP tools). No auth, by fleet decision. |
| A2A | ADR 0008, internal/adapters/inbound/a2a | cmd/a2a serves JSON-RPC 2.0 on / and /a2a (A2A_ADDR, default :8093; through Kong /api/a2a/customer-ordering) and the Agent Card at /.well-known/agent-card.json, which advertises A2A_AGENT_URL. Two read-only skills, no write skill: get_order and get_order_tracking (argument orderId). A skill request is the first message part, {"skill": "...", "arguments": {"orderId": "..."}}, and unknown fields are rejected. Streaming is off. No auth, by fleet decision. |
cmd/mcp and cmd/a2a also answer GET /healthz ({"status":"ok"}); they
have no /readyz.
Endpoints
| Tag | Endpoint | Operation id | Success |
|---|---|---|---|
| Checkout | POST /checkout | placeOrder | 201, the order in state PLACED with one promise per group; 409 offer-not-quotable carries fresh offers |
| Orders | GET /orders?shopperId=&limit=&cursor= | listOrdersByShopper | 200, one page {items, nextCursor} newest first; 404 not-found for an unknown shopper; 400 invalid-limit / invalid-cursor / unknown-query-parameter |
| Orders | GET /orders/{orderId} | getOrder | 200, status, shopper, destination postal prefix, lines, groups with promises; never the address |
| Orders | GET /orders/{orderId}/tracking | getOrderTracking | 200, per group: window, lock and ship times, signals, verdict, packages, outcomes |
| Orders | POST /orders/{orderId}/cancellations | cancelOrder | 200, the order with its groups in CANCELLATION_REQUESTED; 409 cancel-after-lock when no group can be requested |
| Ship-To | GET /orders/{orderId}/ship-to | getShipTo | 200, the synthetic address, Cache-Control: no-store |
| Shoppers | POST /shoppers | registerShopper | 201, the shopper with generated ids; 409 shopper-exists |
| Shoppers | GET /shoppers?email= | findShopperByEmail | 200, the profile; 404 not-found when no e-mail matches |
| Shoppers | GET /shoppers/{shopperId} | getShopper | 200, the profile with savedAddresses[] |
| Shoppers | POST /shoppers/{shopperId}/addresses | addSavedAddress | 201, the saved address; 422 too-many-addresses past 20 |
| reports | GET /reports/ordering-performance?from=&to= | getOrderingPerformanceReport | 200, per UTC day (snake_case): orders placed and cancelled, consolidated-tier, pickup-point and split-shipment orders, the split share, shopper notices decided by kind (at most 5, the rest in shopper_notices_other), plus freshness; 400 invalid-report-range. Served by cmd/co-reports on :8092 from the analytical database (ADR 0018); not on cmd/api |
| reports | GET /reports/freshness | getReportFreshness | 200, as_of and lag_seconds of the analytics projection (both null before the first event) |
| Operations | GET /healthz, GET /readyz | getHealth, getReadiness | 200 / 200, or 503 while shutting down or when Postgres or Kafka does not answer (Runbook) |
Exact status codes, bodies and schemas of every route are in the generated REST pages of this section.
Conventions in the contract
Idempotency-Key. Required on the four POST routes (/checkout,/orders/{orderId}/cancellations,/shoppers,/shoppers/{shopperId}/addresses), 1 to 128 printable ASCII characters; absent is400 idempotency-key-required, malformed is400 idempotency-key-invalid. The key is global. A success and a refusal that is final for the request are stored for 24 hours, committed with the order and its outbox rows, and replayed withIdempotency-Replayed: true; the same key with a different method, path or body is409 idempotency-key-reused. A refusal that a retry could pass (concurrent-update,not-found,validation-failed,cancel-after-lock,promise-capacity-exhausted,book-closed,group-spans-nodes,promise-destination-mismatch,illegal-transition) and a 5xx are not stored: the key is released, so a retry with the same key runs again and another body under it is a new request (ADR 0019). On/checkoutthe order id is derived from the key, so a retry after a timeout reuses the same promises (Runbook).- Paging.
GET /ordersis keyset-paged and answers{items, nextCursor}(nextCursoris absent on the last page):limitdefaults to 100 with a maximum of 500,cursoris the opaquenextCursorof the previous page. A badlimitis400 invalid-limit, an undecodable cursor400 invalid-cursorand any other query parameter (the retiredafter,offset,nextToken) is400 unknown-query-parameter.GET /orders/{orderId}/trackingandGET /shoppers?email=are single-resource views (x-pagination-exempt: view). - Errors are RFC 9457
application/problem+jsonwithtype = /problems/<slug>(internal/adapters/inbound/http/errors.go). The slugs:malformed-request(400),idempotency-key-required(400),idempotency-key-invalid(400),invalid-limit(400),invalid-cursor(400),unknown-query-parameter(400),idempotency-key-reused(409),not-found(404),offer-not-quotable(409),promise-capacity-exhausted(409),book-closed(409),status-regression(409),cancel-after-lock(409),shopper-exists(409),concurrent-update(409),illegal-transition(409),group-spans-nodes(422),line-without-promise(422),promise-destination-mismatch(422),too-many-addresses(422),validation-failed(422),delivery-promise-unavailable(503) andinternal-error(500). Causes and remedies are on Troubleshooting; the use cases that raise them are on Use cases. - JSON. camelCase, instants in RFC 3339 UTC, enums in UPPER_SNAKE, optional
fields omitted when absent (never
null), arrays always present. A NUL character (U+0000) in the path, the query or a body is a uniform client error (internal/adapters/inbound/http/nul.go). - Auth: none. The fleet removed REST, MCP and A2A authentication on
2026-09-11 and
TestNoAuthMiddlewareReintroducedfails the build if auth middleware returns. Consequently the "restricted" ship-to route is restricted by documentation and network placement, not by a check: the spec namesshipping-and-trackingas its only caller and the route is the only one that returns the address. - PII. The ship-to address is synthetic and appears only on
GET /orders/{orderId}/ship-to, in the checkout request and the saved-address routes; no order read and no event carries it. Events carry the destination postal prefix only.