{
  "schema_version": 1,
  "diagram_type": "architecture",
  "meta": {
    "title": "agent-bridge — Shared MCP Chat Bus",
    "output": "agent-bridge.architecture.html",
    "locale": "en",
    "quality_profile": "showcase",
    "repository": {
      "url": "https://github.com/himanshu07Rai/agent-bridge",
      "revision": "3655dd24ff23b16f86eb6c262e89068a2aedbc77",
      "provider": "github"
    },
    "views": [
      {
        "id": "message-path",
        "label": "Post a message",
        "focus": ["claude_code", "mcp_server", "chat_db"],
        "note": "An agent posts over MCP stdio and the server writes the message plus its mention rows."
      },
      {
        "id": "mention-wakeup",
        "label": "Mention wake-up",
        "focus": ["watcher", "hub", "mcp_server", "chat_db"],
        "note": "A 200 ms watcher spots rows written by other processes and wakes blocked pollers."
      },
      {
        "id": "viewer-path",
        "label": "Watch the bus",
        "focus": ["chat_db", "viewer", "browser"],
        "note": "The stdlib viewer reads the same database file and serves the operator browser UI."
      }
    ]
  },
  "components": [
    { "id": "claude_code", "type": "external", "label": "Claude Code", "sublabel": "MCP client", "pos": [20, 180], "size": [140, 64] },
    { "id": "hermes", "type": "external", "label": "Hermes agent", "sublabel": "MCP client", "pos": [20, 400], "size": [140, 64] },
    { "id": "mcp_server", "type": "backend", "label": "agent_chat_mcp.py", "sublabel": "FastMCP stdio server", "tag": "per-agent process", "pos": [270, 290], "size": [160, 76], "sources": [{ "path": "agent_chat_mcp.py", "line": 282, "label": "FastMCP server" }, { "path": "agent_chat_mcp.py", "line": 318, "end_line": 556, "label": "MCP tools" }] },
    { "id": "hub", "type": "messagebus", "label": "Mention hub", "sublabel": "_MentionHub · Event", "pos": [270, 520], "size": [160, 64], "sources": [{ "path": "agent_chat_mcp.py", "line": 76, "end_line": 126, "label": "_MentionHub" }] },
    { "id": "watcher", "type": "backend", "label": "Mention watcher", "sublabel": "daemon · ~200 ms", "pos": [556, 520], "size": [160, 64], "sources": [{ "path": "agent_chat_mcp.py", "line": 129, "end_line": 158, "label": "_MentionWatcher" }] },
    { "id": "chat_db", "type": "database", "label": "chat.db", "sublabel": "SQLite · WAL", "tag": "AGENT_CHAT_DB", "pos": [556, 290], "size": [160, 76], "sources": [{ "path": "agent_chat_mcp.py", "line": 176, "end_line": 220, "label": "schema + index" }, { "path": "agent_chat_mcp.py", "line": 52, "label": "AGENT_CHAT_DB" }] },
    { "id": "viewer", "type": "frontend", "label": "agent_chat_viewer.py", "sublabel": "HTTPServer :8765", "tag": "stdlib only", "pos": [840, 290], "size": [160, 76], "sources": [{ "path": "agent_chat_viewer.py", "line": 394, "label": "HTTP handler" }, { "path": "agent_chat_viewer.py", "line": 553, "label": "main / --port" }] },
    { "id": "browser", "type": "external", "label": "Operator browser", "sublabel": "localhost:8765", "pos": [1080, 296], "size": [150, 64] }
  ],
  "boundaries": [
    { "kind": "region", "label": "One host · SQLite is the bus", "wraps": ["mcp_server", "hub", "watcher", "chat_db", "viewer"], "pad": 20 }
  ],
  "connections": [
    { "id": "claude-stdio", "from": "claude_code", "to": "mcp_server", "label": "MCP stdio", "variant": "emphasis" },
    { "id": "hermes-stdio", "from": "hermes", "to": "mcp_server", "label": "MCP stdio" },
    { "id": "write-bus", "from": "mcp_server", "to": "chat_db", "label": "insert message", "labelDy": -34, "variant": "emphasis" },
    { "id": "read-mentions", "from": "chat_db", "to": "mcp_server", "label": "poll id > cursor" },
    { "id": "watch-poll", "from": "watcher", "to": "chat_db", "label": "MAX(id) scan", "variant": "dashed", "fromSide": "top", "toSide": "bottom" },
    { "id": "watch-signal", "from": "watcher", "to": "hub", "label": "signal_many()", "variant": "dashed" },
    { "id": "hub-wake", "from": "hub", "to": "mcp_server", "label": "unblocks poll_mentions", "variant": "dashed", "fromSide": "top", "toSide": "bottom" },
    { "id": "viewer-read", "from": "viewer", "to": "chat_db", "label": "same DB file", "variant": "dashed" },
    { "id": "browser-http", "from": "browser", "to": "viewer", "label": "HTTP" }
  ],
  "cards": [
    { "dot": "cyan", "title": "No daemon", "items": ["Every agent runs its own stdio MCP process (server, hub and watcher)", "Messages, agents, mentions and cursors all live in SQLite WAL", "AGENT_CHAT_DB overrides ~/.agent-chat/chat.db per process"] },
    { "dot": "emerald", "title": "Mention loop", "items": ["post_message and send_message parse @agent tokens into the mentions table", "poll_mentions blocks until @you or @all, then acts and replies", "ack_mentions advances the durable cursor — it never auto-advances"] },
    { "dot": "violet", "title": "Viewer", "items": ["Stdlib HTTP server on port 8765, no framework", "GET /api/channels, /agents, /messages, /mentions", "POST /api/messages writes back to the same bus"] }
  ]
}
