# enesmanan/paper-bold architecture

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

- Interactive diagram: https://gitdiagram.com/enesmanan/paper-bold
- Repository: https://github.com/enesmanan/paper-bold

## Overview

##### Main Components
- Web Server (Flask Application): Represented by app.py, this component is the entry point for handling HTTP requests, routing, and integration of core processing logic.
- Frontend: Consisting of static assets (CSS, images) and HTML templates (index.html and viewer.html) that form the user interface.
- PDF Processing Module: The module responsible for content extraction using PyPDF2. This should be annotated as “Content Extraction” where PDFs are converted to text.
- Intelligent Chunking Module: Once text is extracted, it is segmented based on document size and structure (this is noted in the README).
- Embedding Engine: Converts text chunks into semantic vectors using Google’s embedding model. This is a crucial processing step.
- Vector Database (Chroma): The Chroma database component where the vectorized representations are stored for fast retrieval.
- Query Processing & Retrieval Chain: Implements a ConversationalRetrievalChain that handles contextual matching based on user query input.
- Response Generation Module: Uses Gemini-powered synthesis for generating user answers and insights.

##### Relationships and Flow
- An HTTP request is sent to the Flask server.
- The server invokes the PDF Processing Module (via PyPDF2) to extract text.
- The extracted text is fed into the Intelligent Chunking Module.
- Each text chunk is passed to the Embedding Engine, which generates semantic vectors.
- The vectors are stored in the Chroma database (vector storage).
- When the user asks a question, this query is processed and linked via a ConversationalRetrievalChain that queries the Chroma database.
- The retrieved context is then passed to the Response Generation Module (powered by Gemini) that synthesizes and produces the answer.
- Finally, the answer is sent back to the frontend for display.

##### Architectural Patterns and Design Principles
- Modular Pipeline: Clearly separated stages (extraction, chunking, embedding, storage, retrieval, and generation) which make the system more maintainable.
- Separation of Concerns: UI, business logic, and data processing are divided into distinct layers (frontend vs. backend vs. processing modules).
- Stateless Web Server: Each request (upload or query) is handled independently, invoking processing pipelines as needed.
- Extensibility: The design is set to easily incorporate additional language processing, different embedding models, or alternative vector storage solutions.

##### Relevant Technologies and Frameworks
- Backend: Python and Flask to handle HTTP requests and coordinate the processing pipeline.
- Frontend: HTML, CSS, and JavaScript, with assets located in the “static” and “templates” directories.
- AI and NLP: PyPDF2 for PDF parsing, Google Embedding for semantic vectorization, LangChain for chain models, and Gemini for response generation.
- Data Storage: Chroma database to house the generated vectors.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        FP1["Index Page (index.html)"]:::frontend
        FP2["Viewer Page (viewer.html)"]:::frontend
        FP3["Static Assets"]:::frontend
    end

    subgraph "Backend Processing"
        BP1["Flask Web Server (app.py)"]:::backend
        BP2["Content Extraction"]:::backend
        BP3["Intelligent Chunking"]:::backend
        BP4["Embedding Engine"]:::backend
        BP5[("Vector Storage (Chroma DB)")]:::database
        BP6["Conversational Retrieval Chain"]:::backend
        BP7["Response Generation"]:::backend
    end

    U["User"]:::external

    U -->|"uploadPDF"| FP1
    FP1 -->|"sendRequest"| BP1
    BP1 -->|"extractPDF"| BP2
    BP2 -->|"chunkText"| BP3
    BP3 -->|"embedText"| BP4
    BP4 -->|"storeVector"| BP5
    BP5 -->|"queryVector"| BP6
    BP6 -->|"generateResponse"| BP7
    BP7 -->|"returnAnswer"| FP2

    %% Click Events
    click FP1 "https://github.com/enesmanan/paper-bold/blob/main/templates/index.html"
    click FP2 "https://github.com/enesmanan/paper-bold/blob/main/templates/viewer.html"
    click FP3 "https://github.com/enesmanan/paper-bold/tree/main/static"
    click BP1 "https://github.com/enesmanan/paper-bold/blob/main/app.py"
    click BP2 "https://github.com/enesmanan/paper-bold/blob/main/app.py"
    click BP3 "https://github.com/enesmanan/paper-bold/blob/main/app.py"
    click BP4 "https://github.com/enesmanan/paper-bold/blob/main/app.py"
    click BP6 "https://github.com/enesmanan/paper-bold/blob/main/app.py"
    click BP7 "https://github.com/enesmanan/paper-bold/blob/main/app.py"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef database fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
