# vidyasagar55001-dot/chatbot architecture

> Architecture diagram of the GitHub repository vidyasagar55001-dot/chatbot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vidyasagar55001-dot/chatbot
- Repository: https://github.com/vidyasagar55001-dot/chatbot

## Overview

AGY is a web-research application: a user submits a query and style, Agent 1 gathers web results and produces a draft, Agent 2 filters and formats it, and the browser displays the result. The server owns orchestration and offers both SSE streaming and a REST endpoint; the UI also exposes health status, source links, and an agent inspector with audit metrics. The README documents these capabilities, while sampled source confirms the core calls and event flow; unsampled UI details are not expanded beyond those documented capabilities.

Main entry points: [`server.js`](https://github.com/vidyasagar55001-dot/chatbot/blob/main/server.js) (Express API), [`public/app.js`](https://github.com/vidyasagar55001-dot/chatbot/blob/main/public/app.js) (SSE Client), [`agents/agent1Search.js`](https://github.com/vidyasagar55001-dot/chatbot/blob/main/agents/agent1Search.js) (Web Research Agent), [`agents/agent2Filter.js`](https://github.com/vidyasagar55001-dot/chatbot/blob/main/agents/agent2Filter.js) (Critic & Formatter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["User Interface"]
  node_web_ui["Web Interface<br/>[index.html]"]
  node_query_controls["Query &amp; Styles<br/>[app.js]"]
  node_sse_client["SSE Client<br/>[app.js]"]
  node_result_view["Results &amp; Sources<br/>[app.js]"]
  node_pipeline_inspector["Pipeline Inspector<br/>[app.js]"]
end

subgraph group_api["API Orchestration"]
  node_server["Express API<br/>[server.js]"]
  node_health_check["Health Check<br/>[server.js]"]
end

subgraph group_research["Research Pipeline"]
  node_agent1["Web Research Agent<br/>[agent1Search.js]"]
  node_web_search["Web Search"]
  node_draft_synthesis["Draft Synthesis<br/>[agent1Search.js]"]
  node_agent2["Critic &amp; Formatter<br/>[agent2Filter.js]"]
  node_audit_metrics["Filter Audit<br/>[agent2Filter.js]"]
end

subgraph group_integrations["External Services"]
  node_agy_bridge["AGY CLI Bridge<br/>[agyBridge.js]"]
end

node_user(("User"))
node_search_provider["DuckDuckGo"]
node_agy_cli["AGY CLI"]

node_user -->|"uses"| node_web_ui
node_web_ui -->|"hosts"| node_query_controls
node_query_controls -->|"submits query"| node_sse_client
node_sse_client -->|"requests stream"| node_server
node_server -->|"routes health"| node_health_check
node_server -->|"runs search"| node_agent1
node_server -->|"runs filter"| node_agent2
node_agent1 -->|"retrieves results"| node_web_search
node_web_search -->|"queries"| node_search_provider
node_agent1 -->|"builds draft"| node_draft_synthesis
node_agent1 -->|"requests synthesis"| node_agy_bridge
node_agent2 -->|"requests filtering"| node_agy_bridge
node_agy_bridge -->|"runs prompt"| node_agy_cli
node_agent2 -->|"calculates metrics"| node_audit_metrics
node_server -->|"streams events"| node_sse_client
node_sse_client -->|"renders output"| node_result_view
node_sse_client -->|"provides draft &amp; audit"| node_pipeline_inspector
node_result_view -->|"delivers results"| node_user
node_pipeline_inspector -->|"shows comparison"| node_user
node_server -->|"runs REST query"| node_agent1

click node_web_ui "https://github.com/vidyasagar55001-dot/chatbot/blob/main/public/index.html"
click node_query_controls "https://github.com/vidyasagar55001-dot/chatbot/blob/main/public/app.js"
click node_sse_client "https://github.com/vidyasagar55001-dot/chatbot/blob/main/public/app.js"
click node_result_view "https://github.com/vidyasagar55001-dot/chatbot/blob/main/public/app.js"
click node_pipeline_inspector "https://github.com/vidyasagar55001-dot/chatbot/blob/main/public/app.js"
click node_server "https://github.com/vidyasagar55001-dot/chatbot/blob/main/server.js"
click node_health_check "https://github.com/vidyasagar55001-dot/chatbot/blob/main/server.js"
click node_agent1 "https://github.com/vidyasagar55001-dot/chatbot/blob/main/agents/agent1Search.js"
click node_web_search "https://github.com/vidyasagar55001-dot/chatbot/blob/main/services/webSearchFallback.js"
click node_draft_synthesis "https://github.com/vidyasagar55001-dot/chatbot/blob/main/agents/agent1Search.js"
click node_agent2 "https://github.com/vidyasagar55001-dot/chatbot/blob/main/agents/agent2Filter.js"
click node_audit_metrics "https://github.com/vidyasagar55001-dot/chatbot/blob/main/agents/agent2Filter.js"
click node_agy_bridge "https://github.com/vidyasagar55001-dot/chatbot/blob/main/services/agyBridge.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web_ui,node_query_controls,node_sse_client,node_result_view,node_pipeline_inspector,node_user toneBlue
class node_server,node_health_check toneAmber
class node_agent1,node_web_search,node_draft_synthesis,node_agent2,node_audit_metrics toneMint
class node_agy_bridge toneRose
class node_search_provider,node_agy_cli toneIndigo
```

## Components

### User Interface

- [Web Interface](https://github.com/vidyasagar55001-dot/chatbot/blob/main/public/index.html): `public/index.html`
- [Query & Styles](https://github.com/vidyasagar55001-dot/chatbot/blob/main/public/app.js): `public/app.js`
- [SSE Client](https://github.com/vidyasagar55001-dot/chatbot/blob/main/public/app.js): `public/app.js`
- [Results & Sources](https://github.com/vidyasagar55001-dot/chatbot/blob/main/public/app.js): `public/app.js`
- [Pipeline Inspector](https://github.com/vidyasagar55001-dot/chatbot/blob/main/public/app.js): `public/app.js`

### API Orchestration

- [Express API](https://github.com/vidyasagar55001-dot/chatbot/blob/main/server.js): `server.js`
- [Health Check](https://github.com/vidyasagar55001-dot/chatbot/blob/main/server.js): `server.js`

### Research Pipeline

- [Web Research Agent](https://github.com/vidyasagar55001-dot/chatbot/blob/main/agents/agent1Search.js): `agents/agent1Search.js`
- [Web Search](https://github.com/vidyasagar55001-dot/chatbot/blob/main/services/webSearchFallback.js): `services/webSearchFallback.js`
- [Draft Synthesis](https://github.com/vidyasagar55001-dot/chatbot/blob/main/agents/agent1Search.js): `agents/agent1Search.js`
- [Critic & Formatter](https://github.com/vidyasagar55001-dot/chatbot/blob/main/agents/agent2Filter.js): `agents/agent2Filter.js`
- [Filter Audit](https://github.com/vidyasagar55001-dot/chatbot/blob/main/agents/agent2Filter.js): `agents/agent2Filter.js`

### External Services

- [AGY CLI Bridge](https://github.com/vidyasagar55001-dot/chatbot/blob/main/services/agyBridge.js): `services/agyBridge.js`

### Other components

- **User**
- **DuckDuckGo**
- **AGY CLI**

## Connections

- User → Web Interface: uses (evidence: `README.md`)
- Web Interface → Query & Styles: hosts (evidence: `public/app.js`)
- Query & Styles → SSE Client: submits query (evidence: `public/app.js`)
- SSE Client → Express API: requests stream (evidence: `public/app.js`)
- Express API → Health Check: routes health (evidence: `server.js`)
- Express API → Web Research Agent: runs search (evidence: `server.js`)
- Express API → Critic & Formatter: runs filter (evidence: `server.js`)
- Web Research Agent → Web Search: retrieves results (evidence: `agents/agent1Search.js`)
- Web Search → DuckDuckGo: queries (evidence: `services/webSearchFallback.js`)
- Web Research Agent → Draft Synthesis: builds draft (evidence: `agents/agent1Search.js`)
- Web Research Agent → AGY CLI Bridge: requests synthesis (evidence: `agents/agent1Search.js`)
- Critic & Formatter → AGY CLI Bridge: requests filtering (evidence: `agents/agent2Filter.js`)
- AGY CLI Bridge → AGY CLI: runs prompt (evidence: `services/agyBridge.js`)
- Critic & Formatter → Filter Audit: calculates metrics (evidence: `agents/agent2Filter.js`)
- Express API → SSE Client: streams events (evidence: `server.js`)
- SSE Client → Results & Sources: renders output (evidence: `public/app.js`)
- SSE Client → Pipeline Inspector: provides draft & audit (evidence: `public/app.js`)
- Results & Sources → User: delivers results (evidence: `README.md`)
- Pipeline Inspector → User: shows comparison (evidence: `README.md`)
- Express API → Web Research Agent: runs REST query (evidence: `server.js`)
