# cosmicishan/ai-lawyer-chatbot architecture

> Architecture diagram of the GitHub repository cosmicishan/ai-lawyer-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/cosmicishan/ai-lawyer-chatbot
- Repository: https://github.com/cosmicishan/ai-lawyer-chatbot

## Overview

##### Project type and purpose
- This is a full-stack AI-powered Q&A system (legal document chatbot).
- Users upload PDF legal texts, retrieve relevant content via a vector database, and generate answers with an LLM.

##### File structure
- Top-level scripts:
- frontend.py – Streamlit UI (web interface)
- vector_database.py – FAISS + LangChain wrapper for embedding storage & retrieval
- rag_pipeline.py – Retrieval-Augmented Generation pipeline using DeepSeek R1 + Groq
- PDFs/ – directory where uploaded documents are stored
- requirements.txt / README.md – configuration & documentation

##### README for additional insights
- Tech stack: Streamlit (UI), FAISS (vector DB), Ollama embeddings, DeepSeek R1 LLM
- Workflow summary: upload → vectorize & store → query → retrieve → answer

a. Main components
1. User Interface (Streamlit Frontend)
2. PDF Storage
3. Embedding Service (Ollama)
4. Vector Database (FAISS via LangChain)
5. RAG Pipeline (rag_pipeline.py with DeepSeek R1 + Groq)
6. External Services (if any, e.g., Ollama API or GPU inference endpoint)
b. Relationships & data flow
- User interacts with Streamlit UI → uploads PDF or submits a question
- On PDF upload:
- Streamlit calls vector_database.py
- vector_database.py invokes Ollama Embeddings to generate embeddings
- Embeddings are indexed and stored in FAISS
- On question submission:
- Streamlit triggers rag_pipeline.py
- Pipeline uses LangChain to query FAISS for similar chunks
- Retrieved chunks + user query feed into DeepSeek R1 model (via Groq accelerator)
- Model returns an answer → Streamlit displays it
c. Architectural patterns / design principles
- Separation of concerns: UI logic (frontend.py) vs. data/storage (vector_database.py) vs. AI logic (rag_pipeline.py)
- RAG pattern: decoupling retrieval (FAISS) from generation (LLM)
- Modular design: each script encapsulates a single responsibility
d. Key technologies & libraries
- Streamlit for front-end UX
- FAISS + LangChain for vector search
- Ollama Embeddings for text-to-vector
- DeepSeek R1 LLM + Groq for inference

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client/UI Layer
    subgraph "Client/UI Layer"
        UI[/Streamlit UI/]:::ui
    end

    %% Backend Services
    subgraph "Backend Services"
        VBDSvc["Vector DB Service"]:::service
        RAG["RAG Pipeline"]:::service
    end

    %% Storage/Database
    subgraph "Storage/Database"
        PDFStore[(PDF Storage)]:::db
        FAISS[(FAISS Vector Store)]:::db
    end

    %% External Components
    subgraph "External & AI Components"
        Ollama["Ollama Embeddings API"]:::ext
        DeepSeek["DeepSeek R1 + Groq"]:::ext
    end

    %% Documentation & Configuration
    subgraph "Documentation & Config"
        README["README.md"]:::doc
        REQ["requirements.txt"]:::doc
    end

    %% Data Flows
    UI -->|"Upload PDF"| VBDSvc
    VBDSvc -->|"Generate Embeddings"| Ollama
    Ollama -->|"Embeddings"| FAISS
    VBDSvc -->|"Indexing"| FAISS

    UI -->|"Submit Query"| RAG
    RAG -->|"Query Embeddings"| FAISS
    FAISS -->|"Retrieved Chunks"| RAG
    RAG -->|"Generate Answer"| DeepSeek
    DeepSeek -->|"Answer"| UI

    %% Click Events
    click UI "https://github.com/cosmicishan/ai-lawyer-chatbot/blob/main/frontend.py"
    click VBDSvc "https://github.com/cosmicishan/ai-lawyer-chatbot/blob/main/vector_database.py"
    click RAG "https://github.com/cosmicishan/ai-lawyer-chatbot/blob/main/rag_pipeline.py"
    click README "https://github.com/cosmicishan/ai-lawyer-chatbot/blob/main/README.md"
    click REQ "https://github.com/cosmicishan/ai-lawyer-chatbot/blob/main/requirements.txt"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef db fill:#98FB98,stroke:#333,stroke-width:1px;
    classDef service fill:#FFD580,stroke:#333,stroke-width:1px;
    classDef ext fill:#D3D3D3,stroke:#333,stroke-width:1px;
    classDef doc fill:#E6E6FA,stroke:#333,stroke-width:1px;
```
