{
  "schema_version": 1,
  "diagram_type": "sequence",
  "meta": {
    "title": "iSpeed.my — Margin Facility & Settlement Flow",
    "subtitle": "Margin application, LOO acceptance, and facility revision",
    "output": "ispeed-margin-settlement.html",
    "viewBox": [1080, 620],
    "column_fit": "spread",
    "animation": "trace",
    "quality_profile": "showcase",
    "views": [
      { "id": "application", "label": "Application", "focus": ["user", "web", "web-api", "vbroker-k2"], "note": "Application info, digital certificate, LOO" },
      { "id": "facility", "label": "Facility", "focus": ["web", "web-api", "vbroker"], "note": "Facility revision and status" },
      { "id": "full-flow", "label": "Full Flow", "focus": ["user", "web", "web-api", "vbroker-k2", "vbroker"], "note": "Complete margin lifecycle" }
    ]
  },
  "participants": [
    { "id": "user", "type": "external", "label": "Customer", "sublabel": "Web" },
    { "id": "web", "type": "frontend", "label": "Web App", "sublabel": "margin pages" },
    { "id": "web-api", "type": "backend", "label": "Web API", "sublabel": "rt-mx-web-api" },
    { "id": "vbroker-k2", "type": "external", "label": "VBroker-K2", "sublabel": "margin service" },
    { "id": "vbroker", "type": "backend", "label": "VBroker API", "sublabel": "/account/margin" }
  ],
  "segments": [
    { "from": 150, "to": 265, "label": "Application" },
    { "from": 275, "to": 565, "label": "Facility & Settlement" }
  ],
  "messages": [
    { "id": "m1", "from": "user", "to": "web", "y": 160, "label": "Open margin application", "variant": "default" },
    { "id": "m2", "from": "web", "to": "web-api", "y": 190, "label": "MarginApplicationInformation", "variant": "emphasis" },
    { "id": "m3", "from": "web-api", "to": "vbroker-k2", "y": 220, "label": "/margin/appinfo", "variant": "default" },
    { "id": "m4", "from": "vbroker-k2", "to": "web-api", "y": 250, "label": "application info", "variant": "return" },
    { "id": "m5", "from": "web", "to": "web-api", "y": 280, "label": "DigitalCertificate", "variant": "default" },
    { "id": "m6", "from": "web-api", "to": "vbroker-k2", "y": 310, "label": "/margin/digicert/create", "variant": "default" },
    { "id": "m7", "from": "web", "to": "web-api", "y": 340, "label": "AcceptLoo (digital pin)", "variant": "emphasis" },
    { "id": "m8", "from": "web-api", "to": "vbroker-k2", "y": 370, "label": "/margin/loo/accept", "variant": "default" },
    { "id": "m9", "from": "web", "to": "web-api", "y": 400, "label": "MarginReviseFacility", "variant": "emphasis" },
    { "id": "m10", "from": "web-api", "to": "vbroker", "y": 430, "label": "/account/margin/revise/facility", "variant": "default" },
    { "id": "m11", "from": "vbroker", "to": "web-api", "y": 460, "label": "facility accepted", "variant": "return" },
    { "id": "m12", "from": "web-api", "to": "web", "y": 490, "label": "margin status", "variant": "return" },
    { "id": "m13", "from": "web", "to": "user", "y": 520, "label": "Show status", "variant": "return" }
  ],
  "activations": [
    { "participant": "web", "from": 155, "to": 530, "type": "frontend" },
    { "participant": "web-api", "from": 185, "to": 505, "type": "backend" },
    { "participant": "vbroker-k2", "from": 215, "to": 375, "type": "external" },
    { "participant": "vbroker", "from": 425, "to": 470, "type": "backend" }
  ],
  "cards": [
    {
      "dot": "emerald",
      "title": "Two Backends",
      "items": [
        "Application group routes to /vbroker-k2 (external)",
        "Facility group routes to /vbroker",
        "vbroker-k2 is not in this repo"
      ]
    },
    {
      "dot": "violet",
      "title": "Facility Data",
      "items": [
        "vb_margin_revise_fac + pledge + doc tables",
        "Settlement in vb_margin_sett_rqs",
        "Stamping fee as negative vb_cash_tran"
      ]
    },
    {
      "dot": "cyan",
      "title": "Mobile",
      "items": [
        "12360 margin summary, 12361 outstanding",
        "Margin ratio colour thresholds in 4 bands",
        "No margin application UI on mobile"
      ]
    }
  ]
}
