# khavanw/customer-support-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/khavanw/customer-support-chatbot
- Repository: https://github.com/khavanw/customer-support-chatbot

## Overview

##### Main Components
- Frontend: Represents the client-side application (React-based, as indicated by files like App.jsx, main.jsx, and components such as ChatBot).
- Backend: Contains the core server logic. Within this, further break down into major sub-components:
- API Layer: Under backend/src/api (mainly main.py) – handles incoming HTTP requests and routes them.
- Data Processing: In backend/src/data_processing (e.g., node_handler.py, transformation.py) – responsible for processing various input data formats (PDF, Word, Excel) and converting them to a processable JSON format.
- Hybrid Search: Located in backend/src/search with modules like hybrid_search.py and reranking.py – manages both semantic and keyword searches, including invoking the reranking model.
- Language Models Integration: Under backend/src/language_models (with module files such as gemini_llm.py, prompt_template.py) – integrates the Gemini LLM with custom prompt templates.
- Indexing: Potentially handling interactions with the vector database (see backend/src/indexing/qdrant_indexer.py).
- Infrastructure & Deployment:
- Docker and Docker Compose (files like docker-compose.yml, Dockerfiles in both backend & frontend), which encapsulate the service containers and the deployment strategy.
- Healthcheck and environment files support operational readiness.

##### Relationships and Data Flow
- Within the backend, illustrate the flow starting from the API layer which directs requests to the appropriate modules:
a. Data inputs are processed by the Data Processing module.
b. Processed data is sent to the Hybrid Search module where both semantic and sparse searches take place.
c. The Language Model module (Gemini LLM integration) is then used to generate a conversational response; it may also use results from the search and reranking processes.
- Docker-related components as “Containers,” showing that both frontend and backend are deployed via Docker Compose.

##### Architectural Patterns and Design Principles
- Use a layered architecture style:
- UI Layer: Frontend React application.
- Service Layer: Backend API (FastAPI) that bridges frontend calls to the underlying business logic.
- Data & Processing Layer: Components handling document processing, search indexing, and language model inference.
- RESTful API interactions and note that containerization (using Docker) encapsulates the individual services.
- Demonstrate how external models (Gemini LLM and embedding models) interact with the backend processing pipeline.

##### Relevant Technologies and Deployment Aspects
- Frontend Technologies: React, Vite, Tailwind CSS.
- Backend Technologies: Python, FastAPI, Docker, along with the specific AI models (Gemini LLM, LlamaIndex) and embedding libraries.
- Deployment: Docker Compose orchestrates both frontend and backend containers.
- External Tools: Qdrant for vector database functions, and additional dependencies like Sentence-Transformers and transformers packages for NLP.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        FE("Frontend - React Application"):::frontend
    end

    %% Service Layer (Backend)
    subgraph "Service Layer (Backend - FastAPI Service)"
        API("API Layer"):::backend
        DP("Data Processing Module"):::backend
        HS("Hybrid Search Module"):::backend
        LM("Language Models Integration"):::backend
        IDX("Indexing Component"):::backend
    end

    %% Infrastructure & Deployment
    subgraph "Infrastructure & Deployment"
        DOCKER("Docker Compose Deployment"):::docker
        QDRANT("Qdrant Vector Database"):::database
    end

    %% Data Flow Connections
    FE -->|"HTTP_request"| API
    API -->|"process_data"| DP
    DP -->|"send_to_search"| HS
    HS -->|"search_result"| LM
    LM -->|"invoke_indexer"| IDX
    IDX -->|"embed_storage"| QDRANT

    %% Docker container relationships
    DOCKER -->|"containerizes"| FE
    DOCKER -->|"containerizes"| API

    %% Click Events for Component Mapping
    click FE "https://github.com/khavanw/customer-support-chatbot/tree/master/frontend/"
    click API "https://github.com/khavanw/customer-support-chatbot/blob/master/backend/src/api/main.py"
    click DP "https://github.com/khavanw/customer-support-chatbot/blob/master/backend/src/data_processing/node_handler.py"
    click DP "https://github.com/khavanw/customer-support-chatbot/blob/master/backend/src/data_processing/transformation.py"
    click HS "https://github.com/khavanw/customer-support-chatbot/blob/master/backend/src/search/hybrid_search.py"
    click HS "https://github.com/khavanw/customer-support-chatbot/blob/master/backend/src/search/reranking.py"
    click LM "https://github.com/khavanw/customer-support-chatbot/blob/master/backend/src/language_models/gemini_llm.py"
    click LM "https://github.com/khavanw/customer-support-chatbot/blob/master/backend/src/language_models/prompt_template.py"
    click IDX "https://github.com/khavanw/customer-support-chatbot/blob/master/backend/src/indexing/qdrant_indexer.py"
    click DOCKER "https://github.com/khavanw/customer-support-chatbot/blob/master/docker-compose.yml"
    click DOCKER "https://github.com/khavanw/customer-support-chatbot/tree/master/backend/dockerfile"
    click DOCKER "https://github.com/khavanw/customer-support-chatbot/tree/master/frontend/Dockerfile"

    %% Styles
    classDef frontend fill:#f9d,stroke:#333,stroke-width:2px;
    classDef backend fill:#cfc,stroke:#333,stroke-width:2px;
    classDef docker fill:#ff9,stroke:#333,stroke-width:2px;
    classDef database fill:#9ff,stroke:#333,stroke-width:2px;
```
