# hayatahmad05/agentic-chatbot architecture

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

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

## Overview

##### Project Type and Purpose
- RAGChat is a backend-centric, retrieval-augmented chatbot service with an optional Gradio UI. It uses FastAPI to expose HTTP endpoints, orchestrates an “agent + tools” pattern to query documents and live web search, and powers responses via Google Gemini 2.0 Flash. Data persistence (memory + document store) is in MongoDB Atlas.

##### File Structure Analysis
- Top-level scripts
- main.py / run.bat – application entrypoint
- api.py – defines FastAPI routes (chat, upload, health check)
- Agent.py – orchestrates agent logic, dispatch to tools & LLM
- llm.py – wrapper around Google Gemini via LangChain & embeddings
- logging_config.py – Request-ID middleware and logging setup
- Tools folder
- BasicToolNode.py – generic LangGraph tool node base class
- RagTool.py – custom RAG search tool (vector + keyword retrieval)
- config files
- requirements.txt – dependency list
- .gitignore

##### README Insights
- Core components: FastAPI backend, Google Gemini LLM, MongoDB, LangGraph tools (rag_search + tavily_search), optional Gradio UI
- Architectural patterns: Agent‐oriented (agent + tools), hybrid RAG search (vector + keyword), middleware for logging/tracing

a. Main Components
1. Client Layer
– Gradio UI (optional) or any HTTP client
2. API Layer (FastAPI)
– Exposes /chat, /upload, /health endpoints
– Logging & Request ID middleware
3. Agent Core (Agent.py)
– Coordinates tool invocation and LLM calls
4. Tools Subsystem (Tools/)
– RAG Tool (RagTool.py) – builds queries using embeddings & MongoDB
– Tavily Search Tool – real-time internet lookup
5. LLM Layer (llm.py)
– Google Gemini via LangChain
– Embeddings generation (GoogleGenerativeAIEmbeddings)
6. Data Stores
– MongoDB Atlas
- Document collection (ingested docs + embeddings)
- Conversation history collection (memory recall)
7. External Services
– Tavily API for live search
b. Interactions & Data Flow
– Client → HTTP request → FastAPI
– FastAPI → (with Request ID) → Agent Core
– Agent Core → invokes Tools (RAGTool → MongoDB; Tavily → external API)
– Agent Core → llm.py → Google Gemini (context + tool results)
– llm response → Agent → FastAPI → Client
– Upload endpoint → splits & embeds docs → stores in MongoDB
c. Architectural Patterns
– Agent + Tools (pluggable tool nodes via LangGraph)
– Hybrid RAG (vector + keyword)
– Middleware for cross-cutting concerns (logging, tracing)
d. Key Technologies
– FastAPI (backend web framework)
– LangChain + LangGraph (LLM orchestration)
– GoogleGenerativeAIEmbeddings (vector store)
– MongoDB Atlas (NoSQL document store)
– Tavily (external search)
– Gradio (optional UI)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Entrypoint
    subgraph "Application Entrypoint"
        main_py["main.py"]:::config
        run_bat["run.bat"]:::config
    end

    %% Client Layer
    Client["Gradio UI / HTTP Client"]:::client

    %% API Layer
    subgraph "API Layer"
        API["FastAPI Service"]:::api
        api_py["api.py"]:::api
        log_py["logging_config.py"]:::api
    end

    %% Agent Core
    subgraph "Agent Core"
        Agent["Agent.py"]:::business
    end

    %% Tools Subsystem
    subgraph "Tools Subsystem"
        Basic["BasicToolNode.py"]:::business
        Rag["RagTool.py"]:::business
    end

    %% LLM Layer
    subgraph "LLM Layer"
        llm["llm.py"]:::business
        Gemini["Google Gemini"]:::external
    end

    %% Data Stores
    subgraph "Data Stores"
        Mongo["MongoDB Atlas"]:::datastore
    end

    %% External Services
    subgraph "External Services"
        Tavily["Tavily API"]:::external
    end

    %% Configuration & Documentation
    subgraph "Configuration & Docs"
        req["requirements.txt"]:::config
        gitignore[".gitignore"]:::config
        readme["README.md"]:::config
    end

    %% Connections
    main_py --> API
    run_bat --> API
    Client --> API
    API -->|"1. request"| Agent
    Agent -->|"2. invoke tools"| Basic
    Agent --> Basic
    Agent -->|"2. invoke tools"| Rag
    Rag --> Mongo
    Agent -->|"2. invoke tools"| Tavily
    Tavily --> Agent
    Agent -->|"3. call LLM"| llm
    llm --> Gemini
    llm --> Agent
    Agent -->|"4. response"| API
    API --> Client

    %% Click Events
    click main_py "https://github.com/hayatahmad05/agentic-chatbot/blob/main/main.py"
    click run_bat "https://github.com/hayatahmad05/agentic-chatbot/blob/main/run.bat"
    click api_py "https://github.com/hayatahmad05/agentic-chatbot/blob/main/api.py"
    click log_py "https://github.com/hayatahmad05/agentic-chatbot/blob/main/logging_config.py"
    click Agent "https://github.com/hayatahmad05/agentic-chatbot/blob/main/Agent.py"
    click Basic "https://github.com/hayatahmad05/agentic-chatbot/blob/main/Tools/BasicToolNode.py"
    click Rag "https://github.com/hayatahmad05/agentic-chatbot/blob/main/Tools/RagTool.py"
    click llm "https://github.com/hayatahmad05/agentic-chatbot/blob/main/llm.py"
    click req "https://github.com/hayatahmad05/agentic-chatbot/blob/main/requirements.txt"
    click gitignore "https://github.com/hayatahmad05/agentic-chatbot/blob/main/.gitignore"
    click readme "https://github.com/hayatahmad05/agentic-chatbot/blob/main/README.md"

    %% Styles
    classDef client fill:#f2f2f2,stroke:#333,stroke-width:1px;
    classDef api fill:#cce5ff,stroke:#333,stroke-width:1px;
    classDef business fill:#d4edda,stroke:#333,stroke-width:1px;
    classDef datastore fill:#e2d6f3,stroke:#333,stroke-width:1px;
    classDef external fill:#ffe5b4,stroke:#333,stroke-width:1px;
    classDef config fill:#f8f9fa,stroke:#333,stroke-width:1px;
```
