# naveenmldeveloper/supermarket-chatbot-ai-powered-customer-support-application-using-rag-system- architecture

> Architecture diagram of the GitHub repository naveenmldeveloper/supermarket-chatbot-ai-powered-customer-support-application-using-rag-system-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/naveenmldeveloper/supermarket-chatbot-ai-powered-customer-support-application-using-rag-system-
- Repository: https://github.com/naveenmldeveloper/supermarket-chatbot-ai-powered-customer-support-application-using-rag-system-

## Overview

##### Project Type and Purpose
- This is a full-stack, web-based RAG (Retrieval-Augmented Generation) application: the “Supermarket Chatbot.”
- Purpose: serve customer queries on product availability, pricing, stock, categories, etc., by combining semantic search over a FAISS index built from a MySQL product database and an LLM (DeepSeek V3 via OpenRouter) for response generation.

##### File Structure
- Top-level:
- data/ (faiss_index/, mappings/) – serialized FAISS index and ID-to-vector mappings
- scripts/database.sql – schema & seed data for MySQL
- src/ – core Python modules
- templates/chatbot.html – frontend UI
- src/ breakdown:
- app.py – Flask server, HTTP routes, UI rendering
- db_connect.py – MySQL connection wrapper
- build_index.py – ingests DB rows, generates embeddings (SentenceTransformers), builds/persists FAISS index
- rag_pipeline.py – retrieval + prompt construction + LLM API call
- utils.py – helpers (logging, fuzzy matching)
- Config & dependencies: .env, requirements.txt

##### README Insights
- Architecture described as:
User ↔ Flask UI → RAG pipeline → [FAISS semantic search + fuzzy matching over product data] → constructs prompt → calls LLM API → returns answer
- Tech stack: Flask, MySQL, FAISS, Sentence Transformers, OpenRouter LLM, FuzzyWuzzy

##### Main Components
a. Frontend Layer:
- Static HTML/JS (templates/chatbot.html)
- User input (chat bubbles), AJAX or form POST to Flask
b. Backend Layer (Flask):
- app.py routes request to rag_pipeline
- db_connect service for raw product data
- utils for string cleaning/fuzzy matching
c. Indexing Subsystem (offline or pre-processing):
- build_index.py reads DB → embeddings via Sentence Transformers → builds FAISS index → stores in data/faiss_index/
d. Retrieval & Generation:
- RAG Pipeline:
1. Query → fuzzy match + normalized text
2. Semantic search: FAISS index lookup → top k product vectors
3. Prompt assembly (product metadata from DB)
4. LLM call via OpenRouter (DeepSeek V3)
e. Data Stores:
- MySQL (Product_details table)
- FAISS index files + mapping pickle
f. External Services:
- OpenRouter / DeepSeek V3 LLM API

##### Architectural Patterns & Design Principles
- Separation of concerns:
- Pre-processing/indexing (build_index.py) vs. runtime (app.py + rag_pipeline)
- Data layer (db_connect.py) abstracted from business logic
- Modular pipeline for retrieval (FAISS) + generation (LLM)
- Use of caching/persistence: FAISS index reused between requests

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layers
    subgraph "Presentation Layer"
        direction TB
        UI["Chat UI"]:::frontend
    end

    subgraph "Application Layer"
        direction TB
        App["Flask Backend (app.py)"]:::backend
        DBConn["DB Connection (db_connect.py)"]:::backend
        Utils["Utilities (utils.py)"]:::backend
        RAG["RAG Pipeline (rag_pipeline.py)"]:::backend
        Builder["Index Builder (build_index.py)"]:::offline
    end

    subgraph "Data Layer"
        direction TB
        MySQL["MySQL Database"]:::datastore
        FAISS["FAISS Index"]:::datastore
        Map["ID-to-Vector Mappings"]:::datastore
    end

    subgraph "External Services"
        direction TB
        LLM["OpenRouter LLM (DeepSeek V3)"]:::external
    end

    %% Runtime Flow
    UI -->|HTTP POST request| App
    App -->|uses| DBConn
    App -->|calls| Utils
    App -->|forwards query| RAG

    RAG -->|SQL SELECT| DBConn
    RAG -->|FAISS search| FAISS
    RAG -->|load mapping| Map
    RAG -->|constructs prompt| App
    RAG -->|LLM API call| LLM
    LLM -->|response| RAG
    RAG -->|returns answer| App
    App -->|HTTP response| UI

    %% Build-time Flow
    Builder -->|reads| MySQL
    Builder -->|embeddings + build| FAISS
    Builder -->|writes| Map

    %% Click Events
    click UI "https://github.com/naveenmldeveloper/supermarket-chatbot-ai-powered-customer-support-application-using-rag-system-/blob/main/templates/chatbot.html"
    click App "https://github.com/naveenmldeveloper/supermarket-chatbot-ai-powered-customer-support-application-using-rag-system-/blob/main/src/app.py"
    click DBConn "https://github.com/naveenmldeveloper/supermarket-chatbot-ai-powered-customer-support-application-using-rag-system-/blob/main/src/db_connect.py"
    click Utils "https://github.com/naveenmldeveloper/supermarket-chatbot-ai-powered-customer-support-application-using-rag-system-/blob/main/src/utils.py"
    click RAG "https://github.com/naveenmldeveloper/supermarket-chatbot-ai-powered-customer-support-application-using-rag-system-/blob/main/src/rag_pipeline.py"
    click Builder "https://github.com/naveenmldeveloper/supermarket-chatbot-ai-powered-customer-support-application-using-rag-system-/blob/main/src/build_index.py"
    click MySQL "https://github.com/naveenmldeveloper/supermarket-chatbot-ai-powered-customer-support-application-using-rag-system-/blob/main/scripts/database.sql"
    click FAISS "https://github.com/naveenmldeveloper/supermarket-chatbot-ai-powered-customer-support-application-using-rag-system-/blob/main/data/faiss_index/product_index.faiss"
    click Map "https://github.com/naveenmldeveloper/supermarket-chatbot-ai-powered-customer-support-application-using-rag-system-/blob/main/data/mappings/product_mapping.pkl"
    click README "https://github.com/naveenmldeveloper/supermarket-chatbot-ai-powered-customer-support-application-using-rag-system-/blob/main/README.md"
    click requirements "https://github.com/naveenmldeveloper/supermarket-chatbot-ai-powered-customer-support-application-using-rag-system-/blob/main/requirements.txt"

    %% Styles
    classDef frontend fill:#D5E8D4,stroke:#82B366,stroke-width:2px;
    classDef backend fill:#FFE6CC,stroke:#D79B00,stroke-width:2px;
    classDef datastore fill:#FFF2CC,stroke:#D6B656,stroke-width:2px;
    classDef external fill:#E1D5E7,stroke:#9673A6,stroke-width:2px;
    classDef offline fill:#F8CECC,stroke:#B85450,stroke-width:2px;
```
