# sharma39vishal/talk-to-pdf-ai architecture

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

- Interactive diagram: https://gitdiagram.com/sharma39vishal/talk-to-pdf-ai
- Repository: https://github.com/sharma39vishal/talk-to-pdf-ai

## Overview

##### Project Type and Purpose
- This is a full-stack web application (“Talk To PDF”) that allows users to upload PDF documents, ask questions about their contents, and receive LLM-generated answers.
- Key indicators: Flask backend (app.py), static frontend assets in build/index.html, PDF processing and vector search logic in Python modules.

##### File Structure Analysis
- Top-level files:
- app.py – Flask server application entry point
- searching_logic.py – PDF ingestion, text splitting, FAISS vector store, QA pipeline
- requirements.txt – Python dependencies (Flask, LangChain, PyPDF2, FAISS, OpenAI)
- build/index.html – Compiled frontend UI (HTML/CSS/JS) served by Flask or static middleware
- No separate “frontend” folder suggests a single‐page app delivered from build/

##### README Insights
- Technologies: Flask backend, HTML/CSS/JS frontend, PyPDF2 for PDF handling, LangChain for text splitting and QA, FAISS for vector storage, OpenAI GPT for LLM
- Workflow described: upload PDF → split text → build vector index → query index → call LLM → respond

##### Main Components
a. Frontend (User Interface)
- Browser running build/index.html + JS logic
- Responsible for file upload form and question input
b. Backend (Flask API)
- app.py exposes endpoints:
– POST /upload (receive PDF)
– POST /ask (receive question, trigger searching_logic)
c. PDF Processing & Vector Store
- searching_logic.py modules:
– PDF ingestion via PyPDF2
– CharacterTextSplitter (LangChain)
– FAISS in-memory vector database
d. LLM Service (External)
- OpenAI GPT-3 (or compatible) called via API key
e. Data Flow & Storage
- Temporary storage of uploaded PDFs (filesystem or memory)
- In-memory or persisted FAISS index
f. User (Actor)
- Initiates upload and queries; receives answers

##### Relationships & Data Flows
- User → Browser UI: selects PDF, inputs question
- Browser UI → Flask API:
- Upload request triggers PDF ingestion
- Ask request triggers similarity search + LLM call
- Flask API → PDF Processing: extract text and split into chunks
- Flask API → FAISS Vector Store: store and query vectors
- Flask API → OpenAI API: send context + question, receive answer
- Flask API → Browser UI: return answer for display

##### Architectural Patterns & Principles
- Separation of concerns:
- UI layer (static assets)
- API layer (Flask controllers)
- Business logic layer (searching_logic.py)
- Data layer (FAISS index)
- External service integration (OpenAI)
- Stateless HTTP endpoints with in-memory or transient storage
- Modularity via Python modules for PDF and vector logic

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Layer
    User(["User"]):::actor
    User -->|"interacts with"| BrowserUI

    %% Frontend Layer
    subgraph "Frontend"
        BrowserUI["Browser UI\n(build/index.html)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend"
        API["Flask API\n(app.py)"]:::backend
        API -->|"HTTP POST /upload"| BL
        API -->|"HTTP POST /ask"| BL
    end

    %% Business Logic Layer
    subgraph "Business Logic"
        BL["searching_logic.py\n(PDF Processing & Vector Store)"]:::backend
        BL --> PDF["PDF Ingestion\n(PyPDF2)"]:::backend
        PDF --> Split["Text Splitter\n(LangChain)"]:::backend
        Split --> Store["FAISS Vector Store"]:::datastore
        Store -->|"similarity search"| BL
    end

    %% External Services
    subgraph "External Services"
        OpenAI["OpenAI GPT\n(API)"]:::external
    end

    %% Data Flows
    API -->|"calls OpenAI API\n(JSON context+question)"| OpenAI
    OpenAI -->|"JSON answer"| API
    API -->|"JSON answer"| BrowserUI
    BrowserUI -->|"displays answer"| User

    %% Project Docs & Dependencies
    subgraph "Project Files"
        Req["requirements.txt"]:::docs
        Readme["README.md"]:::docs
    end

    %% Click Events
    click BrowserUI "https://github.com/sharma39vishal/talk-to-pdf-ai/blob/master/build/index.html"
    click API "https://github.com/sharma39vishal/talk-to-pdf-ai/blob/master/app.py"
    click BL "https://github.com/sharma39vishal/talk-to-pdf-ai/blob/master/searching_logic.py"
    click Req "https://github.com/sharma39vishal/talk-to-pdf-ai/blob/master/requirements.txt"
    click Readme "https://github.com/sharma39vishal/talk-to-pdf-ai/blob/master/README.md"

    %% Styles
    classDef frontend fill:#cfe2ff,stroke:#0366d6,color:#0366d6,stroke-width:1px
    classDef backend fill:#d1e7dd,stroke:#0f5132,color:#0f5132,stroke-width:1px
    classDef datastore fill:#ffe5b4,stroke:#d39e00,color:#d39e00,stroke-width:1px
    classDef external fill:#e3d5ff,stroke:#5e2a7e,color:#5e2a7e,stroke-width:1px
    classDef docs fill:#f0f0f0,stroke:#333,stroke-width:1px
    classDef actor fill:#ffffff,stroke:#000000,stroke-width:1px,stroke-dasharray: 5 5
```
