{
  "schemaVersion": "0.1",
  "diagramFamily": "sequence",
  "scene": {
    "id": "request-flow-from-handler",
    "title": "Checkout request flow",
    "units": "px",
    "canvas": { "width": 1900, "height": 1150 }
  },
  "elements": [
    { "id": "client", "kind": "node", "nodeType": "sequence.actor", "shape": "rect", "label": "Client" },
    { "id": "checkout", "kind": "node", "nodeType": "sequence.lifeline", "shape": "rect", "label": "Checkout Service" },
    { "id": "auth", "kind": "node", "nodeType": "sequence.lifeline", "shape": "rect", "label": "Auth Service" },
    { "id": "cache", "kind": "node", "nodeType": "sequence.lifeline", "shape": "rect", "label": "Redis Cache" },
    { "id": "inventory", "kind": "node", "nodeType": "sequence.lifeline", "shape": "rect", "label": "Inventory Service" },
    { "id": "payment", "kind": "node", "nodeType": "sequence.lifeline", "shape": "rect", "label": "Payment Provider\n(Stripe)" },
    { "id": "notify", "kind": "node", "nodeType": "sequence.lifeline", "shape": "rect", "label": "Notification Queue" },

    { "id": "m_post", "kind": "edge", "edgeType": "sequence.message", "from": { "elementId": "client" }, "to": { "elementId": "checkout" }, "label": "POST /checkout" },
    { "id": "m_verify", "kind": "edge", "edgeType": "sequence.message", "from": { "elementId": "checkout" }, "to": { "elementId": "auth" }, "label": "verifyToken(jwt)" },
    { "id": "m_verify_ok", "kind": "edge", "edgeType": "sequence.reply", "from": { "elementId": "auth" }, "to": { "elementId": "checkout" }, "label": "user_id" },
    { "id": "m_cache_get", "kind": "edge", "edgeType": "sequence.message", "from": { "elementId": "checkout" }, "to": { "elementId": "cache" }, "label": "GET cart:{user_id}" },
    { "id": "m_cache_hit", "kind": "edge", "edgeType": "sequence.reply", "from": { "elementId": "cache" }, "to": { "elementId": "checkout" }, "label": "cart (hit)" },
    { "id": "m_reserve", "kind": "edge", "edgeType": "sequence.message", "from": { "elementId": "checkout" }, "to": { "elementId": "inventory" }, "label": "reserve(items)" },
    { "id": "m_reserved", "kind": "edge", "edgeType": "sequence.reply", "from": { "elementId": "inventory" }, "to": { "elementId": "checkout" }, "label": "reservation_id" },

    { "id": "note_payment", "kind": "node", "nodeType": "sequence.note", "shape": "rect", "label": "Stripe charge with\nidempotency key", "extensions": { "anchor": "payment" } },

    { "id": "frag_charge", "kind": "frame", "containerType": "fragment", "title": "[charge succeeded]", "children": ["m_charge", "m_charge_ok", "m_charge_retry", "m_charge_retry_ok"], "layout": { "mode": "absolute", "x": 270, "y": 545, "width": 1410, "height": 190 }, "extensions": { "operator": "alt", "operands": [{ "y": 635, "guard": "retry on 5xx (exp backoff: 1s, 2s, 4s)" }] } },

    { "id": "m_charge", "kind": "edge", "edgeType": "sequence.message", "from": { "elementId": "checkout" }, "to": { "elementId": "payment" }, "label": "charge($total, idempotency_key)" },
    { "id": "m_charge_ok", "kind": "edge", "edgeType": "sequence.reply", "from": { "elementId": "payment" }, "to": { "elementId": "checkout" }, "label": "charge_id" },
    { "id": "m_charge_retry", "kind": "edge", "edgeType": "sequence.message", "from": { "elementId": "checkout" }, "to": { "elementId": "payment" }, "label": "charge (retry)" },
    { "id": "m_charge_retry_ok", "kind": "edge", "edgeType": "sequence.reply", "from": { "elementId": "payment" }, "to": { "elementId": "checkout" }, "label": "charge_id (after retry)" },

    { "id": "m_commit", "kind": "edge", "edgeType": "sequence.message", "from": { "elementId": "checkout" }, "to": { "elementId": "inventory" }, "label": "commit(reservation_id)" },
    { "id": "m_notify", "kind": "edge", "edgeType": "sequence.async", "from": { "elementId": "checkout" }, "to": { "elementId": "notify" }, "label": "publish(order_placed)" },
    { "id": "m_self_validate", "kind": "edge", "edgeType": "sequence.message", "from": { "elementId": "checkout" }, "to": { "elementId": "checkout" }, "label": "build response" },
    { "id": "m_response", "kind": "edge", "edgeType": "sequence.reply", "from": { "elementId": "checkout" }, "to": { "elementId": "client" }, "label": "200 OK + receipt" }
  ]
}
