Skip to main content

API conventions

This service was built to Richardson maturity level 2 and RFC 7807 from the first commit, rather than migrating to them later as the four sibling services did historically.

Resource nouns, correct verbs​

Every path is a resource collection or a member of one. Two verb-suffixed action endpoints exist and both are deliberate:

  • POST /locations/{locationCode}/decommissionings — a genuine domain command on a single slot, not a CRUD update. Forcing it into PATCH {"status":"Decommissioned"} would misrepresent a one-way state transition as a field assignment.
  • POST /location-imports — a collection-level action scoped to the /locations resource, rather than dangling off an unscoped /admin/... path.

No unscoped RPC-style endpoint exists in this service.

Every 201 carries a resolvable Location​

HTTP/1.1 201 Created
Content-Type: application/json
Location: /zones/WH1-STOR-AMB

Four single-resource GETs exist specifically so that every Location header points at something that actually has a representation:

EndpointExists so that this Location resolves
GET /zones/{zoneId}POST /sites/{siteCode}/zones
GET /zones/{zoneId}/aisles/{aisleCode}POST /zones/{zoneId}/aisles
GET /location-types/{name}POST /location-types
GET /placement-rules/{ruleId}POST /placement-rules

A Location with no GET behind it is not maturity level 2.

Two exceptions in the current code

The geometry-era create endpoints do not yet meet this rule. POST /sites/{siteCode}/structures sets Location: /sites/{siteCode}/structures/{id}, but no route serves a single fixed structure (use GET /sites/{siteCode}/structures). POST /zones/{zoneId}/cross-aisles returns 201 with no Location header.

Status codes​

CodeWhen
200Successful read, or a bulk-import report
201Resource created — always with Location
204Successful action with no body (decommission)
400Malformed input: bad JSON, a location code that is not seven [A-Z0-9] segments, a missing required identifier, a resource-creation POST missing its required Idempotency-Key header
404The named site/zone/aisle/slot/type/rule does not exist
409State conflict: a code already taken, a parent that exists but is not Active, a slot already decommissioned
422Semantically invalid: non-positive capacity, unknown enum value, PlacementRule violation

The 409/422 split is the one worth internalising:

  • 409 means the world is in a state that forbids this — the code is taken, or the parent zone has been decommissioned. Retrying the identical request will keep failing until something else changes.
  • 422 means this request is internally wrong — a negative capacity, an unknown temperature class, a location type that is not legal in that zone. The caller has to change the request.

POST /location-imports answers 200, not 201: a bulk import is a partial-success report over many rows, not the creation of one addressable resource, so there is no single Location to hand back.

Idempotency-Key on every POST​

Every POST — /sites, /sites/{siteCode}/zones, /sites/{siteCode}/structures, /zones/{zoneId}/aisles, /zones/{zoneId}/cross-aisles, /location-types, /placement-rules, /locations, /location-imports and /locations/{locationCode}/decommissionings — requires a caller-supplied Idempotency-Key header (1-128 printable ASCII characters), always (ADR-0019, ADR 0039, ADR 0044). The middleware is Postgres-backed and always on; there is no database-less run that skips the check. The key is global and the request fingerprint is method + path + SHA-256 of the body. PUT takes no key.

OutcomeStatus
Header missing400 (idempotency-key-required)
Header not 1-128 printable ASCII400 (idempotency-key-invalid)
Fresh keythe real response; a 2xx and a FINAL refusal are stored verbatim
Same key, same request, answer storedthe original response, replayed with Idempotency-Replayed: true, handler not re-run
Same key, same request, first answer was RETRYABLE or a 5xxnothing was stored: the key is released and the request executes again
Same key, different method, path or body, answer stored409 (idempotency-key-reused)
Same key, different request, first answer was releaseda new request: it executes

Every problem type has a replay class declared on its catalogue entry (ADR-0046): FINAL (a function of the request alone, or a refusal that can never become false: validation, a code that is already taken, a decommissioned structure) is stored and replayed; RETRYABLE (a concurrent-modification, a *-not-found parent that may be registered a moment later, placement-rule-violated, cross-aisle-aisle-mismatch, the role-dependent location checks, the travel-graph refusals) is not stored, so a client that did the right thing and retried under the same key gets the retry executed. OUTCOME (the command committed state and then refused) exists in the vocabulary; no problem type of this service declares it. Nothing retries by itself: a released refusal means only that the same key may be tried again by whoever sent it.

RFC 7807 problem details​

Every error response — from the first commit, with no bespoke {"error": "..."} predecessor — is Content-Type: application/problem+json:

{
"type": "https://errors.facility-layout.warehouse-systems.dev/site-not-found",
"title": "Site not found",
"status": 404,
"detail": "site not found",
"instance": "/sites/NOPE"
}
MemberMeaning here
typeA stable URI identifying the error category. One per distinct category; it is an identifier, not a page that has to resolve.
titleA fixed human string for the category. Never varies for a given type.
statusMirrors the HTTP status code.
detailThe dynamic, request-specific message — this is where the violated rule gets named.
instanceThe request path.

The mapping is a single table in the HTTP adapter (internal/adapters/inbound/http/errors.go) keyed off typed domain errors with errors.Is. The domain never knows an HTTP status code exists.

The problem type catalogue​

type slugStatusTitle
site-not-found404Site not found
zone-not-found404Zone not found
aisle-not-found404Aisle not found
location-slot-not-found404Location slot not found
location-type-not-found404Location type not found
placement-rule-not-found404Placement rule not found
duplicate-site-code409A site with this code already exists
duplicate-zone409A zone with this area and zone code already exists in this site
duplicate-aisle409An aisle with this code already exists in this zone
duplicate-location-type409A location type with this name already exists
duplicate-placement-rule409A placement rule with this id already exists
duplicate-location-code409A location slot with this code already exists
duplicate-fixed-structure409A fixed structure with this id already exists
duplicate-cross-aisle409A cross-aisle between these aisles at this bay already exists
site-not-active409Site is not active
zone-not-active409Zone is not active
aisle-not-active409Aisle is not active
already-decommissioned409This structure is already decommissioned
placement-rule-violated422Location type is not legal in this zone
invalid-max-weight422Capacity max weight must be greater than zero
invalid-max-volume422Capacity max volume must be greater than zero
unknown-temperature-class422Unknown temperature class
unknown-direction422Unknown aisle direction
unknown-status422Unknown lifecycle status
unknown-placement-effect422Unknown placement rule effect
empty-zone-predicate422Placement rule predicate constrains nothing
unknown-location-role422Unknown location role
unknown-dock-flow422Unknown dock flow
unknown-activity422Unknown work center activity
dock-flow-required422A Dock location requires a dockFlow
work-center-activities-required422A WorkCenter location requires at least one activity
functional-attributes-not-allowed422dockFlow and activities may only be set on a Dock or WorkCenter location
negative-sequence-hint422Aisle sequence hint must not be negative
zone-mismatch422Zone attributes do not match the location code's zone
invalid-z422Z coordinate must not be negative
invalid-dimensions422Width, depth, and height must all be greater than zero
negative-pick-sequence422Pick sequence must not be negative
unknown-fixed-structure-kind422Unknown fixed structure kind
empty-fixed-structure-footprint422Fixed structure requires a real footprint
cross-aisle-same-aisle422Cross-aisle must connect two distinct aisles
cross-aisle-aisle-mismatch422Cross-aisle aisles must both belong to the named zone
no-route-between-zones422No route: the two locations are in different zones
no-route422No route exists between these two waypoints
unknown-travel-waypoint422The travel graph has no waypoint for this aisle/bay
invalid-pitch422Bay pitch and level pitch must both be greater than zero
malformed-request-body400The request body is not valid JSON
malformed-location-code400Malformed location code
invalid-site-code400Invalid site code
empty-site-name400Site name must not be empty
invalid-zone-code400Invalid area or zone code
invalid-aisle-code400Invalid aisle code
invalid-location-type400Invalid location type
empty-placement-rule-id400Placement rule id must not be empty
missing-location-code400Location code is required
empty-fixed-structure-id400Fixed structure requires an id
empty-fixed-structure-site-code400Fixed structure must be scoped to a site code
empty-fixed-structure-label400Fixed structure requires a label
empty-fixed-structure-kind400Fixed structure requires a kind
empty-cross-aisle-zone-id400Cross-aisle must be scoped to a zone id
empty-cross-aisle-from-aisle400Cross-aisle requires a from-aisle code
empty-cross-aisle-to-aisle400Cross-aisle requires a to-aisle code
empty-cross-aisle-bay400Cross-aisle requires a bay
empty-import400Facility layout import must contain at least one row
idempotency-key-required400A resource-creation POST was missing its required Idempotency-Key header
idempotency-key-reused409The same Idempotency-Key was reused with a different method, path or body
concurrent-modification409The resource was modified by another writer; re-fetch and retry (ADR 0025)
segment-endpoints-not-real422Centreline endpoints must both be real points
segment-start-end-equal422Centreline start and end must differ
missing-geometry-field400Geometry coordinates and dimensions must be numbers, not null
missing-sequence-hint400Aisle sequenceHint is required
invalid-layout-format400Layout format must be json or svg (GET /sites/{siteCode}/layout?format=)
invalid-report-query400The report query is malformed or missing a required parameter (cmd/facility-reports only)
report-store-error500The report could not be served (cmd/facility-reports only)
internal-error500An unexpected internal error occurred

All type values are prefixed with https://errors.facility-layout.warehouse-systems.dev/.

Two worked errors​

Unknown site:

curl -i localhost:8080/sites/NOPE
HTTP/1.1 404 Not Found
Content-Type: application/problem+json

{"type":"https://errors.facility-layout.warehouse-systems.dev/site-not-found","title":"Site not found","status":404,"detail":"site not found","instance":"/sites/NOPE"}

Duplicate location code:

curl -i -X POST localhost:8080/locations -H 'Content-Type: application/json' \
-d '{"locationCode":"WH1-STOR-AMB-A07-03-02-B","locationType":"PalletRack"}'
HTTP/1.1 409 Conflict
Content-Type: application/problem+json

{"type":"https://errors.facility-layout.warehouse-systems.dev/duplicate-location-code","title":"A location slot with this code already exists","status":409,"detail":"a location slot with this code already exists","instance":"/locations"}

DTOs never leak domain structs​

Request and response bodies are defined in the HTTP adapter (internal/adapters/inbound/http/dto.go) and mapped explicitly. No domain aggregate is serialized directly — the aggregates have unexported fields, so it is not even possible by accident.