# limeload/customer-support-agent architecture

> Architecture diagram of the GitHub repository limeload/customer-support-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/limeload/customer-support-agent
- Repository: https://github.com/limeload/customer-support-agent

## Overview

This is a multi-agent customer-support platform with chat and polled-email entry points. A request loads conversation context, runs through triage, a specialist, escalation review, and a final quality check, then saves the response and agent path. The README also documents ticket handling, knowledge-document management, feedback, analytics, and an admin Agent Trace. Relationships are grounded in the README and shown excerpts; unsampled capabilities are included where documented, but their internal wiring is not inferred.

Main entry points: [`lib/agents/graph.ts`](https://github.com/limeload/customer-support-agent/blob/main/lib/agents/graph.ts) (Support Graph), [`lib/db/client.ts`](https://github.com/limeload/customer-support-agent/blob/main/lib/db/client.ts) (Supabase), [`app/(admin)/dashboard/page.tsx`](https://github.com/limeload/customer-support-agent/blob/main/app/(admin)/dashboard/page.tsx) (Support Dashboard), [`app/api/chat/route.ts`](https://github.com/limeload/customer-support-agent/blob/main/app/api/chat/route.ts) (Chat API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_channels["Customer Channels"]
  node_chat_ui["Chat Widget<br/>[ChatWidget.tsx]"]
  node_chat_api["Chat API<br/>[route.ts]"]
  node_gmail_poll["Gmail Poller<br/>[route.ts]"]
  node_analytics_api["Analytics API<br/>[route.ts]"]
  node_documents_api["Documents API<br/>[route.ts]"]
  node_feedback_api["Feedback API<br/>[route.ts]"]
  node_ticket_api["Ticket API<br/>[route.ts]"]
  node_admin["Support Dashboard<br/>[page.tsx]"]
end

subgraph group_agents["Agent Workflow"]
  node_graph["Support Graph<br/>[graph.ts]"]
  node_state["Shared Agent State<br/>[state.ts]"]
  node_triage["Triage Agent<br/>[triage.ts]"]
  node_knowledge_agent["Knowledge Agent<br/>[knowledgeBase.ts]"]
  node_billing_agent["Order Billing Agent<br/>[orderBilling.ts]"]
  node_troubleshooting["Troubleshooting Agent<br/>[troubleshooting.ts]"]
  node_escalation["Escalation Agent<br/>[escalation.ts]"]
  node_quality["Quality Review<br/>[qualityReview.ts]"]
  node_guardrails["Guardrail Policies<br/>[policies.ts]"]
end

subgraph group_support["Support Capabilities"]
  node_knowledge["Knowledge Retrieval<br/>[retrieve.ts]"]
  node_document_ingest["Document Ingestion<br/>[ingest.ts]"]
  node_tickets["Ticket Operations<br/>[tickets.ts]"]
  node_slack["Slack Notifications<br/>[slack.ts]"]
  node_gmail_tools["Email Operations<br/>[gmail.ts]"]
  node_analytics["Analytics Agent<br/>[analytics.ts]"]
end

subgraph group_data["Data and Operations"]
  node_conversations["Conversation Store<br/>[conversations.ts]"]
  node_database[("Supabase<br/>[client.ts]")]
  node_logger["Agent Logging<br/>[logger.ts]"]
end

node_customer(("Customer"))
node_email_service["Gmail"]
node_llm["OpenAI Models"]

node_customer -->|"sends message"| node_chat_ui
node_chat_ui -.->|"submits request"| node_chat_api
node_chat_api -->|"loads and saves"| node_conversations
node_chat_api -->|"invokes"| node_graph
node_chat_api -->|"loads customer"| node_database
node_email_service -->|"provides messages"| node_gmail_poll
node_gmail_poll -->|"invokes"| node_graph
node_gmail_poll -->|"loads and saves"| node_conversations
node_gmail_poll -->|"reads and replies"| node_gmail_tools
node_graph -->|"dispatches first"| node_triage
node_graph -->|"routes by intent"| node_knowledge_agent
node_graph -->|"routes by intent"| node_billing_agent
node_graph -->|"routes by intent"| node_troubleshooting
node_graph -->|"routes and follows up"| node_escalation
node_graph -->|"dispatches final check"| node_quality
node_quality -->|"checks response"| node_guardrails
node_quality -->|"polishes or revises"| node_llm
node_knowledge_agent -->|"retrieves sources"| node_knowledge
node_escalation -->|"creates ticket"| node_tickets
node_escalation -->|"notifies"| node_slack
node_graph -->|"shares typed state"| node_state
node_documents_api -->|"ingests upload"| node_document_ingest
node_documents_api -->|"lists documents"| node_database
node_document_ingest -->|"stores chunks"| node_database
node_document_ingest -->|"embeds chunks"| node_llm
node_conversations -->|"reads and writes"| node_database
node_logger -->|"stores agent traces"| node_database
node_analytics_api -->|"runs analysis"| node_analytics
node_analytics -->|"reads ticket data"| node_database
node_feedback_api -->|"stores rating"| node_database
node_ticket_api -->|"manages tickets"| node_tickets
node_admin -.->|"requests analytics"| node_analytics_api
node_admin -.->|"manages documents"| node_documents_api
node_admin -.->|"reviews tickets"| node_ticket_api
node_admin -.->|"views agent trace"| node_logger

click node_chat_ui "https://github.com/limeload/customer-support-agent/blob/main/components/ChatWidget.tsx"
click node_chat_api "https://github.com/limeload/customer-support-agent/blob/main/app/api/chat/route.ts"
click node_gmail_poll "https://github.com/limeload/customer-support-agent/blob/main/app/api/cron/gmail-poll/route.ts"
click node_graph "https://github.com/limeload/customer-support-agent/blob/main/lib/agents/graph.ts"
click node_state "https://github.com/limeload/customer-support-agent/blob/main/lib/agents/state.ts"
click node_triage "https://github.com/limeload/customer-support-agent/blob/main/lib/agents/triage.ts"
click node_knowledge_agent "https://github.com/limeload/customer-support-agent/blob/main/lib/agents/knowledgeBase.ts"
click node_billing_agent "https://github.com/limeload/customer-support-agent/blob/main/lib/agents/orderBilling.ts"
click node_troubleshooting "https://github.com/limeload/customer-support-agent/blob/main/lib/agents/troubleshooting.ts"
click node_escalation "https://github.com/limeload/customer-support-agent/blob/main/lib/agents/escalation.ts"
click node_quality "https://github.com/limeload/customer-support-agent/blob/main/lib/agents/qualityReview.ts"
click node_guardrails "https://github.com/limeload/customer-support-agent/blob/main/lib/guardrails/policies.ts"
click node_knowledge "https://github.com/limeload/customer-support-agent/blob/main/lib/rag/retrieve.ts"
click node_document_ingest "https://github.com/limeload/customer-support-agent/blob/main/lib/rag/ingest.ts"
click node_tickets "https://github.com/limeload/customer-support-agent/blob/main/lib/tools/tickets.ts"
click node_slack "https://github.com/limeload/customer-support-agent/blob/main/lib/tools/slack.ts"
click node_gmail_tools "https://github.com/limeload/customer-support-agent/blob/main/lib/tools/gmail.ts"
click node_conversations "https://github.com/limeload/customer-support-agent/blob/main/lib/conversations.ts"
click node_database "https://github.com/limeload/customer-support-agent/blob/main/lib/db/client.ts"
click node_logger "https://github.com/limeload/customer-support-agent/blob/main/lib/logging/logger.ts"
click node_analytics "https://github.com/limeload/customer-support-agent/blob/main/lib/agents/analytics.ts"
click node_analytics_api "https://github.com/limeload/customer-support-agent/blob/main/app/api/analytics/route.ts"
click node_documents_api "https://github.com/limeload/customer-support-agent/blob/main/app/api/documents/route.ts"
click node_feedback_api "https://github.com/limeload/customer-support-agent/blob/main/app/api/feedback/route.ts"
click node_ticket_api "https://github.com/limeload/customer-support-agent/blob/main/app/api/tickets/route.ts"
click node_admin "https://github.com/limeload/customer-support-agent/blob/main/app/(admin)/dashboard/page.tsx"

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_chat_ui,node_chat_api,node_gmail_poll,node_analytics_api,node_documents_api,node_feedback_api,node_ticket_api,node_admin toneBlue
class node_graph,node_state,node_triage,node_knowledge_agent,node_billing_agent,node_troubleshooting,node_escalation,node_quality,node_guardrails toneAmber
class node_knowledge,node_document_ingest,node_tickets,node_slack,node_gmail_tools,node_analytics toneMint
class node_conversations,node_database,node_logger toneRose
class node_customer,node_email_service,node_llm toneIndigo
```

## Components

### Customer Channels

- [Chat Widget](https://github.com/limeload/customer-support-agent/blob/main/components/ChatWidget.tsx): `components/ChatWidget.tsx`
- [Chat API](https://github.com/limeload/customer-support-agent/blob/main/app/api/chat/route.ts): `app/api/chat/route.ts`
- [Gmail Poller](https://github.com/limeload/customer-support-agent/blob/main/app/api/cron/gmail-poll/route.ts): `app/api/cron/gmail-poll/route.ts`
- [Analytics API](https://github.com/limeload/customer-support-agent/blob/main/app/api/analytics/route.ts): `app/api/analytics/route.ts`
- [Documents API](https://github.com/limeload/customer-support-agent/blob/main/app/api/documents/route.ts): `app/api/documents/route.ts`
- [Feedback API](https://github.com/limeload/customer-support-agent/blob/main/app/api/feedback/route.ts): `app/api/feedback/route.ts`
- [Ticket API](https://github.com/limeload/customer-support-agent/blob/main/app/api/tickets/route.ts): `app/api/tickets/route.ts`
- [Support Dashboard](https://github.com/limeload/customer-support-agent/blob/main/app/(admin)/dashboard/page.tsx): `app/(admin)/dashboard/page.tsx`

### Agent Workflow

- [Support Graph](https://github.com/limeload/customer-support-agent/blob/main/lib/agents/graph.ts): `lib/agents/graph.ts`
- [Shared Agent State](https://github.com/limeload/customer-support-agent/blob/main/lib/agents/state.ts): `lib/agents/state.ts`
- [Triage Agent](https://github.com/limeload/customer-support-agent/blob/main/lib/agents/triage.ts): `lib/agents/triage.ts`
- [Knowledge Agent](https://github.com/limeload/customer-support-agent/blob/main/lib/agents/knowledgeBase.ts): `lib/agents/knowledgeBase.ts`
- [Order Billing Agent](https://github.com/limeload/customer-support-agent/blob/main/lib/agents/orderBilling.ts): `lib/agents/orderBilling.ts`
- [Troubleshooting Agent](https://github.com/limeload/customer-support-agent/blob/main/lib/agents/troubleshooting.ts): `lib/agents/troubleshooting.ts`
- [Escalation Agent](https://github.com/limeload/customer-support-agent/blob/main/lib/agents/escalation.ts): `lib/agents/escalation.ts`
- [Quality Review](https://github.com/limeload/customer-support-agent/blob/main/lib/agents/qualityReview.ts): `lib/agents/qualityReview.ts`
- [Guardrail Policies](https://github.com/limeload/customer-support-agent/blob/main/lib/guardrails/policies.ts): `lib/guardrails/policies.ts`

### Support Capabilities

- [Knowledge Retrieval](https://github.com/limeload/customer-support-agent/blob/main/lib/rag/retrieve.ts): `lib/rag/retrieve.ts`
- [Document Ingestion](https://github.com/limeload/customer-support-agent/blob/main/lib/rag/ingest.ts): `lib/rag/ingest.ts`
- [Ticket Operations](https://github.com/limeload/customer-support-agent/blob/main/lib/tools/tickets.ts): `lib/tools/tickets.ts`
- [Slack Notifications](https://github.com/limeload/customer-support-agent/blob/main/lib/tools/slack.ts): `lib/tools/slack.ts`
- [Email Operations](https://github.com/limeload/customer-support-agent/blob/main/lib/tools/gmail.ts): `lib/tools/gmail.ts`
- [Analytics Agent](https://github.com/limeload/customer-support-agent/blob/main/lib/agents/analytics.ts): `lib/agents/analytics.ts`

### Data and Operations

- [Conversation Store](https://github.com/limeload/customer-support-agent/blob/main/lib/conversations.ts): `lib/conversations.ts`
- [Supabase](https://github.com/limeload/customer-support-agent/blob/main/lib/db/client.ts): `lib/db/client.ts`
- [Agent Logging](https://github.com/limeload/customer-support-agent/blob/main/lib/logging/logger.ts): `lib/logging/logger.ts`

### Other components

- **Customer**
- **Gmail**
- **OpenAI Models**

## Connections

- Customer → Chat Widget: sends message (evidence: `README.md`)
- Chat Widget → Chat API: submits request
- Chat API → Conversation Store: loads and saves (evidence: `app/api/chat/route.ts`)
- Chat API → Support Graph: invokes (evidence: `app/api/chat/route.ts`)
- Chat API → Supabase: loads customer (evidence: `app/api/chat/route.ts`)
- Gmail → Gmail Poller: provides messages (evidence: `app/api/cron/gmail-poll/route.ts`)
- Gmail Poller → Support Graph: invokes (evidence: `app/api/cron/gmail-poll/route.ts`)
- Gmail Poller → Conversation Store: loads and saves (evidence: `app/api/cron/gmail-poll/route.ts`)
- Gmail Poller → Email Operations: reads and replies (evidence: `app/api/cron/gmail-poll/route.ts`)
- Support Graph → Triage Agent: dispatches first (evidence: `lib/agents/graph.ts`)
- Support Graph → Knowledge Agent: routes by intent (evidence: `lib/agents/graph.ts`)
- Support Graph → Order Billing Agent: routes by intent (evidence: `lib/agents/graph.ts`)
- Support Graph → Troubleshooting Agent: routes by intent (evidence: `lib/agents/graph.ts`)
- Support Graph → Escalation Agent: routes and follows up (evidence: `lib/agents/graph.ts`)
- Support Graph → Quality Review: dispatches final check (evidence: `lib/agents/graph.ts`)
- Quality Review → Guardrail Policies: checks response (evidence: `lib/agents/qualityReview.ts`)
- Quality Review → OpenAI Models: polishes or revises (evidence: `lib/agents/qualityReview.ts`)
- Knowledge Agent → Knowledge Retrieval: retrieves sources (evidence: `README.md`)
- Escalation Agent → Ticket Operations: creates ticket (evidence: `README.md`)
- Escalation Agent → Slack Notifications: notifies (evidence: `README.md`)
- Support Graph → Shared Agent State: shares typed state (evidence: `lib/agents/graph.ts`)
- Documents API → Document Ingestion: ingests upload (evidence: `app/api/documents/route.ts`)
- Documents API → Supabase: lists documents (evidence: `app/api/documents/route.ts`)
- Document Ingestion → Supabase: stores chunks (evidence: `lib/rag/ingest.ts`)
- Document Ingestion → OpenAI Models: embeds chunks (evidence: `lib/rag/ingest.ts`)
- Conversation Store → Supabase: reads and writes (evidence: `lib/conversations.ts`)
- Agent Logging → Supabase: stores agent traces (evidence: `lib/logging/logger.ts`)
- Analytics API → Analytics Agent: runs analysis (evidence: `app/api/analytics/route.ts`)
- Analytics Agent → Supabase: reads ticket data (evidence: `lib/agents/analytics.ts`)
- Feedback API → Supabase: stores rating (evidence: `app/api/feedback/route.ts`)
- Ticket API → Ticket Operations: manages tickets (evidence: `app/api/tickets/route.ts`)
- Support Dashboard → Analytics API: requests analytics (evidence: `README.md`)
- Support Dashboard → Documents API: manages documents (evidence: `README.md`)
- Support Dashboard → Ticket API: reviews tickets (evidence: `README.md`)
- Support Dashboard → Agent Logging: views agent trace (evidence: `README.md`)
