Derived from network/model/model.yaml. This context's service is built; the model carries its as-built contracts, and identifiers (Err... names, routes, CloudEvents types) are the names the service uses.
One section per command in the model. Each would live in
internal/application/usecases (proposed). The step-by-step diagrams are on
Sequence Diagrams; payloads are on
Domain Events; the HTTP contract is
apis/node-topology/openapi.yaml.
Reads are not use cases here. GET /nodes/{nodeId} (GetNode),
GET /nodes?type=®ion=&status= (ListNodes), GET /lanes?origin=&destination=
(ListLanes) and GET /service-areas/{postalPrefix} (ResolveServiceArea)
read the repositories directly; an unknown id answers 404.
Triggers at a glance
| Use case | Actor / trigger | Inbound adapter | Event on success |
|---|
RegisterNode | vendor-connectivity (vendor node) or network-ops planner (network node) | REST POST /nodes | NodeRegistered |
DeclareOperationalProfile | vendor-connectivity (declaredBy VENDOR) or network-ops planner (declaredBy NETWORK_OPS) | REST PUT /nodes/{nodeId}/operational-profile | NodeOperationalProfileDeclared |
ActivateNode | network-ops planner | REST POST /nodes/{nodeId}/activations | NodeActivated |
SuspendNode | network-ops planner | REST POST /nodes/{nodeId}/suspensions | NodeSuspended |
RetireNode | network-ops planner | REST POST /nodes/{nodeId}/retirements | NodeRetired |
OpenLane | network-ops planner | REST POST /lanes | LaneOpened |
CloseLane | network-ops planner | REST POST /lanes/{laneId}/closures | LaneClosed |
DeclareLaneCost | network-ops planner | REST POST /lanes/{laneId}/cost-declarations | LaneCostDeclared |
DeclareLaneEmission | network-ops planner | REST POST /lanes/{laneId}/emission-declarations | LaneEmissionDeclared |
AssignServiceArea | network-ops planner | REST PUT /service-areas/{postalPrefix} | ServiceAreaAssigned |
DefineRegion | network-ops planner | REST POST /regions | RegionDefined |
No use case is driven by Kafka: the context consumes no event.
Derived from: model.yaml → contexts[node-topology].aggregates[*].commands,
.inbound, .rest, .publishes.
How every command commits
- The HTTP adapter checks the
Idempotency-Key header. A key already seen
on the same route with the same request replays the stored response;
nothing runs again. Keys are kept for 24 hours in the context's
idempotency_keys table, keyed by (route, key).
- The use case loads the aggregate (and, where an invariant needs it, the
other aggregate it reads), calls the domain method, and saves the
aggregate with an optimistic-concurrency version check.
- In the same Postgres transaction it writes one
outbox_events row with
the CloudEvents envelope, and the idempotency record.
- The outbox relay publishes the row to
retailnetwork.node-topology.events
after commit.
A version conflict at step 2 is retried once by reloading; if it still
conflicts, the call answers 409 and the caller retries. A domain error at
step 2 writes nothing and publishes nothing.
Errors common to every use case
| Error | HTTP | Problem type slug | Note |
|---|
ErrValidation | 422 | validation-failed | The request is well-formed JSON but violates a value-object rule; the adapter rejects it before the use case runs. |
ErrNotFound | 404 | not-found | An addressed aggregate does not exist: an unknown nodeId, laneId or postalPrefix in the path, or an unknown node named in the body. |
ErrIllegalTransition | 409 | illegal-transition | The command is not allowed from the aggregate's current state. Listed per use case below where it applies. |
ErrConcurrentUpdate | 409 | concurrent-update | Optimistic-concurrency version mismatch after one retry; the caller re-reads and retries. |
These four are the shared errors of model conventions.errors, the same in
every context.
Problems are application/problem+json (RFC 9457) with type, title,
status and detail.
RegisterNode
- Actor / trigger:
vendor-connectivity while processing a vendor's
RegisterVendorNode submission (in-org, Customer/Supplier); or the
network-ops planner for a parcel node.
- Inbound adapter: REST
POST /nodes.
- Input:
nodeType, subtype (fulfillment centres only), operator,
vendorRef{vendorId, vendorNodeCode} (vendor nodes), regionId,
timezone, location{postalCode, countryCode, lat, lon}.
- Preconditions: for a vendor node,
vendor-connectivity has already
checked the vendor account (ErrNodeNotOwnedByVendor is its invariant,
not this one).
- Main flow:
- Check the operator against
node_types[nodeType].operator_allowed.
- For a vendor node, check that
(vendorId, vendorNodeCode) is free.
- Derive
NodeCapabilities from the node type (DefaultCapabilitiesByType).
- Check
regionId names a defined Region and, when given, that
subtype is one of the node type's subtypes.
- Create the
Node in PROPOSED with a new nodeId.
- Save, write
NodeRegistered to the outbox, commit.
- Answer
201 with the node.
- Errors:
Err... | HTTP | Problem type slug |
|---|
ErrOperatorNotAllowedForNodeType | 422 | operator-not-allowed-for-node-type |
ErrUnknownRegion | 422 | unknown-region |
ErrSubtypeNotAllowed | 422 | subtype-not-allowed |
ErrVendorNodeCodeTaken | 409 | vendor-node-code-taken |
- Events:
NodeRegistered.
- Idempotency:
Idempotency-Key is required. vendor-connectivity is
expected to send its transactionId as the key, so a re-processed
submission replays the first answer instead of failing on
ErrVendorNodeCodeTaken.
DeclareOperationalProfile
- Actor / trigger:
vendor-connectivity while processing a
DeclareNodeProfile submission (declaredBy VENDOR); or the network-ops
planner for a network node (declaredBy NETWORK_OPS).
- Inbound adapter: REST
PUT /nodes/{nodeId}/operational-profile.
- Input:
profileRevision, timezone, operatingHoursByDay,
holidays[] (ISO dates), handlingTimeMinutes,
cutoffs[{localTime, days?, maxOrders?}],
throughputCap{value, timeUnit, unit}, sortDwellMinutes (sortation
centres and air hubs only), declaredBy. operatingHoursByDay is
{monday … sunday: {start, end}} in HH:mm; a missing day is closed.
timeUnit is HOUR or DAY.
- Preconditions: the node exists and is not
RETIRED.
- Main flow:
- Load the
Node.
- Refuse a revision not above the current one.
- Check every day of every cutoff (
days, default every operating day)
against the operating hours of that day.
- For an
ACTIVE FULFILLMENT_CENTER, check the new revision still has at
least one cutoff and a handlingTime above zero.
- Check
sortDwellMinutes is absent unless the node is a
SORTATION_CENTER or AIR_HUB.
- Append the profile as a new revision with
declaredAt = now; the old
revision is kept unchanged.
- Save, write
NodeOperationalProfileDeclared to the outbox, commit.
- Answer
200 with the node and its current profile.
- Errors:
Err... | HTTP | Problem type slug |
|---|
ErrStaleProfileRevision | 409 | stale-profile-revision |
ErrCutoffOutsideOperatingHours | 422 | cutoff-outside-operating-hours |
ErrSortDwellNotAllowed | 422 | sort-dwell-not-allowed |
ErrIncompleteOperationalProfile | 409 | incomplete-operational-profile |
ErrNodeRetired | 409 | node-retired |
- Events:
NodeOperationalProfileDeclared.
- Idempotency: by
Idempotency-Key, and by the revision itself: the same
revision sent twice with a different key is refused with
ErrStaleProfileRevision, which vendor-connectivity reports as a failed
submission.
ActivateNode
- Actor / trigger: network-ops planner.
- Inbound adapter: REST
POST /nodes/{nodeId}/activations.
- Preconditions: the node is
PROPOSED or SUSPENDED. A
FULFILLMENT_CENTER has a current profile with at least one cutoff and a
handling time above zero.
- Main flow:
- Load the
Node.
- Check completeness of the profile for a fulfillment centre.
- Move to
ACTIVE, record activatedAt.
- Save, write
NodeActivated to the outbox, commit.
- Answer
200 with the node.
- Errors:
Err... | HTTP | Problem type slug |
|---|
ErrIncompleteOperationalProfile | 409 | incomplete-operational-profile |
ErrNodeRetired | 409 | node-retired |
ErrIllegalTransition (node already ACTIVE) | 409 | illegal-transition |
- Events:
NodeActivated.
- Idempotency: by
Idempotency-Key. Without a key replay, a second
activation of an ACTIVE node is refused with ErrIllegalTransition.
SuspendNode
- Actor / trigger: network-ops planner.
- Inbound adapter: REST
POST /nodes/{nodeId}/suspensions.
- Input:
reason.
- Preconditions: the node is
ACTIVE.
- Main flow:
- Load the
Node.
- Move to
SUSPENDED, record reason and suspendedAt.
- Save, write
NodeSuspended to the outbox, commit.
- Answer
200 with the node.
- Errors:
Err... | HTTP | Problem type slug |
|---|
ErrNodeRetired | 409 | node-retired |
ErrIllegalTransition (node PROPOSED or already SUSPENDED) | 409 | illegal-transition |
- Events:
NodeSuspended. Downstream, offer-availability suppresses
the node's listings and linehaul-transportation cancels future pickups.
- Idempotency: by
Idempotency-Key.
RetireNode
- Actor / trigger: network-ops planner.
- Inbound adapter: REST
POST /nodes/{nodeId}/retirements.
- Preconditions: the node is
ACTIVE or SUSPENDED.
- Main flow:
- Load the
Node.
- Move to
RETIRED, record retiredAt.
- Save, write
NodeRetired to the outbox, commit.
- Answer
200 with the node.
- Errors:
Err... | HTTP | Problem type slug |
|---|
ErrNodeRetired | 409 | node-retired |
ErrIllegalTransition (node still PROPOSED) | 409 | illegal-transition |
- Events:
NodeRetired.
- Idempotency: by
Idempotency-Key. Lanes and service areas of the node
are not touched (policy SuspendedEndpointsUnusable): consumers treat them
as unusable while the node is not ACTIVE.
OpenLane
- Actor / trigger: network-ops planner.
- Inbound adapter: REST
POST /lanes.
- Input:
originNodeId, destinationNodeId, mode (GROUND or
AIR), nominalTransitMinutes.
- Preconditions: both nodes exist and are
ACTIVE; no OPEN lane with
the same origin, destination and mode.
- Main flow (as built,
internal/application/usecases/lanes.go and lane.Open):
- Load both
Node aggregates (read only); an unknown node is 404
not-found, before any lane rule runs.
- In
lane.Open, refuse a loop (ErrLaneLoop).
- Check the type pair against
lane_rules.allowed.
- Check both ends are
ACTIVE.
- Create the
Lane in OPEN with a new laneId.
- Check no
OPEN lane exists for the same origin, destination and mode
(ErrDuplicateLane); save (the partial unique index on open lanes guards a concurrent
open), write LaneOpened, commit.
- Answer
201 with the lane.
- Errors:
Err... | HTTP | Problem type slug |
|---|
unknown node (ErrNotFound, a port error) | 404 | not-found |
ErrLaneLoop | 422 | lane-loop |
ErrLaneTypePairNotAllowed | 422 | lane-type-pair-not-allowed |
ErrLaneEndpointNotActive | 409 | lane-endpoint-not-active |
ErrDuplicateLane | 409 | duplicate-lane |
- Events:
LaneOpened.
- Idempotency: by
Idempotency-Key; a retry with a new key finds the
lane already open and gets ErrDuplicateLane.
CloseLane
- Actor / trigger: network-ops planner.
- Inbound adapter: REST
POST /lanes/{laneId}/closures.
- Preconditions: the lane is
OPEN.
- Main flow:
- Load the
Lane.
- Move to
CLOSED, record closedAt.
- Save, write
LaneClosed to the outbox, commit.
- Answer
200 with the lane.
- Errors:
Err... | HTTP | Problem type slug |
|---|
ErrIllegalTransition (lane already CLOSED) | 409 | illegal-transition |
- Events:
LaneClosed. linehaul-transportation then refuses to
schedule on it (ErrLaneClosed, its invariant).
- Idempotency: by
Idempotency-Key.
AssignServiceArea
- Actor / trigger: network-ops planner; in bulk at network redesign.
- Inbound adapter: REST
PUT /service-areas/{postalPrefix}.
- Input:
deliveryStationNodeId, assignmentVersion.
- Preconditions: the station exists, is a
DELIVERY_STATION and is
ACTIVE with a defined region; the version is above the prefix's current
one.
- Main flow:
- Load the
ServiceArea for the prefix, or start a new one.
- Load the station
Node (read only) and check type and state.
- Refuse a version not above the current one.
- Take
regionId from the station and check it names a defined Region
(read only).
- Assign the station. The prefix is
ASSIGNED, whether new or reassigned
(ASSIGNED to ASSIGNED).
- Save, write
ServiceAreaAssigned, commit.
- Answer
200 with the service area.
- Errors:
Err... | HTTP | Problem type slug |
|---|
ErrUnknownRegion | 422 | unknown-region |
ErrNotADeliveryStation | 409 | not-a-delivery-station |
ErrStaleAssignmentVersion | 409 | stale-assignment-version |
- Events:
ServiceAreaAssigned.
- Idempotency:
PUT with a version is naturally idempotent with the
key; a replay of the same version with a new key gets
ErrStaleAssignmentVersion.
DefineRegion
- Actor / trigger: network-ops planner; rare.
- Inbound adapter: REST
POST /regions.
- Input:
code, name.
- Preconditions: no region with that code.
- Main flow:
- Check the code is free.
- Create the
Region (DEFINED) with a new regionId.
- Save (a unique index on
code guards a concurrent define), write
RegionDefined, commit.
- Answer
201 with the region.
- Errors:
Err... | HTTP | Problem type slug |
|---|
ErrRegionCodeTaken | 409 | region-code-taken |
- Events:
RegionDefined.
- Idempotency: by
Idempotency-Key; a retry with a new key gets
ErrRegionCodeTaken.