# shourya845/chatbot architecture

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

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

## Overview

a31-assistance is a Python backend and terminal chatbot for answering A3i questions, routing pricing and demo requests, and storing confirmed leads. Visitors submit chat through the separate frontend or use the CLI. The backend manages sessions, resolves follow-ups and intents, then the agent retrieves official evidence, optionally adds approved company-background snapshots, and synthesizes a checked answer; direct demo submissions follow a separate lead-storage path. The graph reflects documented workflows and indexed references; unsampled implementation details are omitted where their links cannot be established.

Main entry points: [`agent.py`](https://github.com/shourya845/chatbot/blob/main/agent.py) (Answer agent), [`main.py`](https://github.com/shourya845/chatbot/blob/main/main.py) (FastAPI endpoints), [`tools.py`](https://github.com/shourya845/chatbot/blob/main/tools.py) (Search and excerpts), [`chat_cli.py`](https://github.com/shourya845/chatbot/blob/main/chat_cli.py) (Terminal chatbot)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User entry"]
  node_frontend["Next.js frontend"]
  node_api["FastAPI endpoints<br/>[main.py]"]
  node_cli["Terminal chatbot<br/>[chat_cli.py]"]
end

subgraph group_chat["Chat orchestration"]
  node_router["Intent routing<br/>[router.py]"]
  node_followup["Follow-up resolution<br/>[conversation.py]"]
  node_agent["Answer agent<br/>[agent.py]"]
  node_memory["Session memory<br/>[memory.py]"]
  node_guidance["Demo guidance<br/>[router.py]"]
end

subgraph group_evidence["Evidence retrieval"]
  node_search["Search and excerpts<br/>[tools.py]"]
  node_catalog["Official source catalog"]
  node_website["Official page reader<br/>[website.py]"]
  node_review["External snapshot review"]
  node_snapshotdb[("Snapshot database")]
end

subgraph group_leads["Demo requests"]
  node_leadapi["Lead endpoint<br/>[main.py]"]
  node_leads["Lead validation and storage<br/>[leads.py]"]
  node_leaddb[("Lead database")]
end

subgraph group_providers["External providers"]
  node_official["A3i website"]
  node_tavily["Tavily search"]
  node_groq["Groq model"]
  node_ollama["Ollama model"]
end

node_visitor(("Website visitor"))

node_visitor -->|"submits chat"| node_frontend
node_frontend -->|"proxies requests"| node_api
node_visitor -->|"enters messages"| node_cli
node_cli -->|"streams answers"| node_agent
node_cli -->|"loads and saves"| node_memory
node_api -->|"classifies intent"| node_router
node_router -->|"resolves context"| node_followup
node_api -->|"requests answers"| node_agent
node_api -->|"loads and saves"| node_memory
node_agent -->|"invokes search"| node_search
node_search -->|"retrieves pages"| node_website
node_website -->|"selects sources"| node_catalog
node_website -->|"fetches fragments"| node_official
node_search -->|"searches fallback"| node_tavily
node_search -->|"loads approved evidence"| node_review
node_review -->|"reads and reviews"| node_snapshotdb
node_agent -->|"generates answers"| node_groq
node_agent -->|"falls back"| node_ollama
node_agent -->|"streams response"| node_frontend
node_router -->|"handles demo intent"| node_guidance
node_visitor -->|"confirms demo form"| node_frontend
node_frontend -->|"posts lead"| node_leadapi
node_leadapi -->|"validates and saves"| node_leads
node_leads -->|"writes confirmed lead"| node_leaddb

click node_api "https://github.com/shourya845/chatbot/blob/main/main.py"
click node_cli "https://github.com/shourya845/chatbot/blob/main/chat_cli.py"
click node_router "https://github.com/shourya845/chatbot/blob/main/router.py"
click node_followup "https://github.com/shourya845/chatbot/blob/main/conversation.py"
click node_agent "https://github.com/shourya845/chatbot/blob/main/agent.py"
click node_memory "https://github.com/shourya845/chatbot/blob/main/memory.py"
click node_search "https://github.com/shourya845/chatbot/blob/main/tools.py"
click node_catalog "https://github.com/shourya845/chatbot/blob/main/website_sources.json"
click node_website "https://github.com/shourya845/chatbot/blob/main/website.py"
click node_review "https://github.com/shourya845/chatbot/blob/main/external_sources.py"
click node_guidance "https://github.com/shourya845/chatbot/blob/main/router.py"
click node_leadapi "https://github.com/shourya845/chatbot/blob/main/main.py"
click node_leads "https://github.com/shourya845/chatbot/blob/main/leads.py"

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_frontend,node_api,node_cli toneBlue
class node_router,node_followup,node_agent,node_memory,node_guidance toneAmber
class node_search,node_catalog,node_website,node_review,node_snapshotdb toneMint
class node_leadapi,node_leads,node_leaddb toneRose
class node_official,node_tavily,node_groq,node_ollama,node_visitor toneIndigo
```

## Components

### User entry

- **Next.js frontend**
- [FastAPI endpoints](https://github.com/shourya845/chatbot/blob/main/main.py): `main.py`
- [Terminal chatbot](https://github.com/shourya845/chatbot/blob/main/chat_cli.py): `chat_cli.py`

### Chat orchestration

- [Intent routing](https://github.com/shourya845/chatbot/blob/main/router.py): `router.py`
- [Follow-up resolution](https://github.com/shourya845/chatbot/blob/main/conversation.py): `conversation.py`
- [Answer agent](https://github.com/shourya845/chatbot/blob/main/agent.py): `agent.py`
- [Session memory](https://github.com/shourya845/chatbot/blob/main/memory.py): `memory.py`
- [Demo guidance](https://github.com/shourya845/chatbot/blob/main/router.py): `router.py`

### Evidence retrieval

- [Search and excerpts](https://github.com/shourya845/chatbot/blob/main/tools.py): `tools.py`
- [Official source catalog](https://github.com/shourya845/chatbot/blob/main/website_sources.json): `website_sources.json`
- [Official page reader](https://github.com/shourya845/chatbot/blob/main/website.py): `website.py`
- [External snapshot review](https://github.com/shourya845/chatbot/blob/main/external_sources.py): `external_sources.py`
- **Snapshot database**

### Demo requests

- [Lead endpoint](https://github.com/shourya845/chatbot/blob/main/main.py): `main.py`
- [Lead validation and storage](https://github.com/shourya845/chatbot/blob/main/leads.py): `leads.py`
- **Lead database**

### External providers

- **A3i website**
- **Tavily search**
- **Groq model**
- **Ollama model**

### Other components

- **Website visitor**

## Connections

- Website visitor → Next.js frontend: submits chat (evidence: `README.md`)
- Next.js frontend → FastAPI endpoints: proxies requests (evidence: `README.md`)
- Website visitor → Terminal chatbot: enters messages (evidence: `README.md`)
- Terminal chatbot → Answer agent: streams answers (evidence: `chat_cli.py`)
- Terminal chatbot → Session memory: loads and saves (evidence: `chat_cli.py`)
- FastAPI endpoints → Intent routing: classifies intent (evidence: `main.py`)
- Intent routing → Follow-up resolution: resolves context (evidence: `router.py`)
- FastAPI endpoints → Answer agent: requests answers (evidence: `main.py`)
- FastAPI endpoints → Session memory: loads and saves (evidence: `main.py`)
- Answer agent → Search and excerpts: invokes search (evidence: `agent.py`)
- Search and excerpts → Official page reader: retrieves pages (evidence: `tools.py`)
- Official page reader → Official source catalog: selects sources (evidence: `website.py`)
- Official page reader → A3i website: fetches fragments (evidence: `README.md`)
- Search and excerpts → Tavily search: searches fallback (evidence: `README.md`)
- Search and excerpts → External snapshot review: loads approved evidence (evidence: `tools.py`)
- External snapshot review → Snapshot database: reads and reviews (evidence: `external_sources.py`)
- Answer agent → Groq model: generates answers (evidence: `README.md`)
- Answer agent → Ollama model: falls back (evidence: `README.md`)
- Answer agent → Next.js frontend: streams response (evidence: `README.md`)
- Intent routing → Demo guidance: handles demo intent (evidence: `README.md`)
- Website visitor → Next.js frontend: confirms demo form (evidence: `README.md`)
- Next.js frontend → Lead endpoint: posts lead (evidence: `README.md`)
- Lead endpoint → Lead validation and storage: validates and saves (evidence: `main.py`)
- Lead validation and storage → Lead database: writes confirmed lead (evidence: `leads.py`)
