{
  "schema_version": 2,
  "diagram_type": "workflow",
  "meta": {
    "title": "Một sự kiện, hai kênh nhận — thiết kế đề xuất",
    "locale": "vi",
    "quality_profile": "showcase",
    "output": "docs/ssa-miniapp/archify/notification-delivery.html"
  },
  "lanes": [
    {
      "id": "app",
      "label": "Backend → inbox Mini App"
    },
    {
      "id": "zalo",
      "label": "ZBS qua Zalo/OA"
    },
    {
      "id": "exception",
      "label": "Kiểm soát và ngoại lệ",
      "variant": "exception"
    }
  ],
  "mainPath": [
    "commit",
    "dispatch",
    "inbox",
    "read",
    "authorize",
    "detail"
  ],
  "nodes": [
    {
      "id": "commit",
      "lane": "app",
      "col": 0,
      "type": "database",
      "label": "Commit nghiệp vụ",
      "sublabel": "Đơn / tiền + outbox"
    },
    {
      "id": "dispatch",
      "lane": "app",
      "col": 1,
      "type": "messagebus",
      "label": "Phân phối event",
      "sublabel": "Dedupe theo người/kênh"
    },
    {
      "id": "inbox",
      "lane": "app",
      "col": 2,
      "type": "database",
      "label": "Inbox người nhận",
      "sublabel": "Unread / read riêng"
    },
    {
      "id": "read",
      "lane": "app",
      "col": 3,
      "type": "frontend",
      "label": "Mở trong app",
      "sublabel": "Đánh dấu đã đọc"
    },
    {
      "id": "authorize",
      "lane": "app",
      "col": 4,
      "type": "security",
      "label": "Kiểm quyền hiện tại",
      "sublabel": "Đúng đơn / trẻ / resource"
    },
    {
      "id": "detail",
      "lane": "app",
      "col": 5,
      "type": "frontend",
      "label": "Xem nội dung",
      "sublabel": "Hoặc từ chối truy cập"
    },
    {
      "id": "gate",
      "lane": "zalo",
      "col": 1,
      "type": "security",
      "label": "Đủ điều kiện gửi?",
      "sublabel": "Quyền / template / audience"
    },
    {
      "id": "send",
      "lane": "zalo",
      "col": 2,
      "type": "external",
      "label": "Gửi ZBS",
      "sublabel": "Template + delivery key"
    },
    {
      "id": "delivery",
      "lane": "zalo",
      "col": 3,
      "type": "database",
      "label": "Lưu delivery",
      "sublabel": "Accepted ≠ delivered"
    },
    {
      "id": "deeplink",
      "lane": "zalo",
      "col": 4,
      "type": "frontend",
      "label": "Bấm deep link",
      "sublabel": "Đăng nhập nếu cần"
    },
    {
      "id": "blocked",
      "lane": "exception",
      "col": 1,
      "type": "security",
      "label": "Dừng kênh ZBS",
      "sublabel": "Quyền / mẫu không hợp lệ"
    },
    {
      "id": "retry",
      "lane": "exception",
      "col": 2,
      "type": "messagebus",
      "label": "Retry có kiểm soát",
      "sublabel": "Backoff / key / DLQ"
    },
    {
      "id": "unknown",
      "lane": "exception",
      "col": 3,
      "type": "backend",
      "label": "Tra kết quả gửi",
      "sublabel": "Mơ hồ → owner xử lý"
    }
  ],
  "edges": [
    {
      "id": "commit_dispatch",
      "from": "commit",
      "to": "dispatch",
      "variant": "emphasis"
    },
    {
      "id": "dispatch_inbox",
      "from": "dispatch",
      "to": "inbox",
      "variant": "emphasis"
    },
    {
      "id": "inbox_read",
      "from": "inbox",
      "to": "read",
      "variant": "emphasis"
    },
    {
      "id": "read_auth",
      "from": "read",
      "to": "authorize",
      "variant": "emphasis"
    },
    {
      "id": "auth_content",
      "from": "authorize",
      "to": "detail",
      "variant": "security",
      "label": "Quyết định"
    },
    {
      "id": "dispatch_gate",
      "from": "dispatch",
      "to": "gate",
      "variant": "dashed",
      "role": "async"
    },
    {
      "id": "gate_send",
      "from": "gate",
      "to": "send",
      "variant": "security",
      "label": "Hợp lệ"
    },
    {
      "id": "gate_stop",
      "from": "gate",
      "to": "blocked",
      "variant": "security",
      "label": "Không hợp lệ",
      "role": "error"
    },
    {
      "id": "send_delivery",
      "from": "send",
      "to": "delivery",
      "variant": "emphasis",
      "label": "Kết quả"
    },
    {
      "id": "delivery_deeplink",
      "from": "delivery",
      "to": "deeplink",
      "variant": "emphasis",
      "label": "Người nhận mở"
    },
    {
      "id": "deeplink_auth",
      "from": "deeplink",
      "to": "authorize",
      "variant": "security"
    },
    {
      "id": "send_retry",
      "from": "send",
      "to": "retry",
      "variant": "dashed",
      "label": "Lỗi tạm",
      "role": "error"
    },
    {
      "id": "retry_send",
      "from": "retry",
      "to": "send",
      "variant": "dashed",
      "label": "Kiểm lại quyền",
      "role": "return"
    },
    {
      "id": "send_unknown",
      "from": "send",
      "to": "unknown",
      "variant": "security",
      "label": "Timeout",
      "role": "branch"
    }
  ],
  "cards": [
    {
      "dot": "cyan",
      "title": "Inbox khác tin Zalo",
      "items": [
        "Đã giao ZBS không tự đánh dấu đã đọc inbox. Read lưu riêng theo guardian/recipient, không dùng trạng thái của cha cho mẹ.",
        "ZNS trong yêu cầu dùng tên hiện hành ZBS Template Message. Đây không phải quyền push tự do vào Mini App."
      ]
    },
    {
      "dot": "amber",
      "title": "Không mất hoặc lặp nghiệp vụ",
      "items": [
        "Event/recipient/channel chống xử lý trùng; retry không tạo lại đơn, thu tiền hoặc hoàn tiền. Kết quả mơ hồ phải tra provider hoặc giao owner, không gửi lại mù.",
        "Deep link là entry, không phải quyền truy cập. Khi revoked hoặc sai owner, backend từ chối dù tin đã gửi."
      ]
    },
    {
      "dot": "slate",
      "title": "Phạm vi thiết kế",
      "items": [
        "Nguồn: FEATURES.md §7.2–7.5 và T17; bản thiết kế làm việc 12/11/2026. Chưa có backend, quyền OA/template hay delivery thật được xác nhận."
      ]
    }
  ]
}
