{
  "docVersion": 1,
  "id": "template-chat-messaging-app",
  "name": "Chat — reliable delivery",
  "purpose": "Messages persist before ack, route via a connection registry to the recipient's gateway at-least-once, dedupe client-side, and fall back to push when offline.",
  "nodes": {
    "sender": {
      "type": "mobile",
      "label": "Alice",
      "x": 20,
      "y": 240,
      "runtime": "sends: client msg-id 8812"
    },
    "wsA": {
      "type": "websocket",
      "label": "Gateway A",
      "x": 280,
      "y": 240,
      "runtime": "1M held sockets",
      "patterns": [
        "autoscale"
      ]
    },
    "presence": {
      "type": "server",
      "label": "Presence",
      "x": 800,
      "y": 20,
      "runtime": "online · typing · last-seen"
    },
    "chatsvc": {
      "type": "k8s",
      "label": "Chat Service",
      "x": 540,
      "y": 240,
      "runtime": "persist FIRST, then ack",
      "color": "blue",
      "notes": "The ordering rule that makes chat trustworthy: write to the store, THEN ack the sender, THEN fan out delivery."
    },
    "store": {
      "type": "nosql",
      "label": "Message Store",
      "x": 540,
      "y": 480,
      "runtime": "conversation-sharded",
      "patterns": [
        "sharded",
        "replicated",
        "backup"
      ]
    },
    "q": {
      "type": "queue",
      "label": "Delivery Queue",
      "x": 800,
      "y": 240,
      "runtime": "per-recipient · at-least-once"
    },
    "registry": {
      "type": "keyvalue",
      "label": "Connection Registry",
      "x": 1060,
      "y": 20,
      "runtime": "bob → gateway B",
      "notes": "The routing table for live sockets. TTL'd entries — a crashed gateway's users simply resolve to 'offline'."
    },
    "deliver": {
      "type": "worker",
      "label": "Delivery Workers",
      "x": 1060,
      "y": 240,
      "runtime": "competing consumers",
      "color": "green"
    },
    "wsB": {
      "type": "websocket",
      "label": "Gateway B",
      "x": 1320,
      "y": 240,
      "runtime": "holds Bob's socket"
    },
    "recipient": {
      "type": "mobile",
      "label": "Bob",
      "x": 1580,
      "y": 240,
      "runtime": "dedupes by msg-id"
    },
    "push": {
      "type": "push",
      "label": "APNs / FCM",
      "x": 1320,
      "y": 480,
      "runtime": "offline fallback",
      "color": "amber"
    }
  },
  "edges": {
    "e1": {
      "from": "sender",
      "to": "wsA",
      "fromSide": "right",
      "toSide": "left",
      "label": "msg · client-id 8812",
      "animated": true
    },
    "e2": {
      "from": "wsA",
      "to": "chatsvc",
      "fromSide": "right",
      "toSide": "left",
      "animated": true,
      "patterns": [
        "timeout"
      ]
    },
    "e3": {
      "from": "chatsvc",
      "to": "store",
      "fromSide": "bottom",
      "toSide": "top",
      "label": "persist BEFORE ack",
      "animated": true
    },
    "e4": {
      "from": "chatsvc",
      "to": "q",
      "fromSide": "right",
      "toSide": "left",
      "label": "enqueue delivery",
      "style": "dashed",
      "patterns": [
        "ordered"
      ]
    },
    "e5": {
      "from": "q",
      "to": "deliver",
      "fromSide": "right",
      "toSide": "left",
      "style": "dashed",
      "patterns": [
        "dedup"
      ]
    },
    "e6": {
      "from": "deliver",
      "to": "registry",
      "fromSide": "top",
      "toSide": "bottom",
      "label": "where is Bob?"
    },
    "e7": {
      "from": "deliver",
      "to": "wsB",
      "fromSide": "right",
      "toSide": "left",
      "label": "push over socket",
      "animated": true
    },
    "e8": {
      "from": "wsB",
      "to": "recipient",
      "fromSide": "right",
      "toSide": "left",
      "patterns": [
        "idempotent"
      ]
    },
    "e9": {
      "from": "wsA",
      "to": "presence",
      "fromSide": "top",
      "toSide": "left",
      "label": "heartbeats",
      "style": "dashed"
    },
    "e10": {
      "from": "deliver",
      "to": "push",
      "fromSide": "bottom",
      "toSide": "top",
      "label": "no socket → notify",
      "style": "dashed",
      "patterns": [
        "fallback"
      ]
    }
  },
  "boxes": {
    "b1": {
      "x": 760,
      "y": 150,
      "w": 660,
      "h": 280,
      "label": "at-least-once inside — exactly-once is the CLIENT'S dedup",
      "color": "blue",
      "opacity": 0.04
    }
  },
  "texts": {
    "t1": {
      "x": 20,
      "y": 460,
      "text": "the reliability chain:\n1. persisted before Alice sees ✓\n2. redelivery allowed end-to-end\n3. Bob renders msg-id 8812 once,\n   however many times it arrives",
      "color": "green",
      "size": 12
    }
  },
  "meta": {
    "createdAt": "2026-07-13T09:00:00.000Z",
    "modifiedAt": "2026-07-13T09:00:00.000Z"
  }
}