# samnageub/genai architecture

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

- Interactive diagram: https://gitdiagram.com/samnageub/genai
- Repository: https://github.com/samnageub/genai

## Overview

##### Main Components
- User Interface (UI): The Streamlit front end is defined by the files app.py and rag_deep.py. The UI receives user input (queries) and displays model responses.
- Document Store: The “document_store” directory (with PDFs inside) acts as the repository of documents that the system uses for question answering.
- Model Integration: The local installation of Ollama (running deepseek-r1 with a chosen model size, such as 1.5b) interfaces with the application to perform the core deep learning tasks.
- PDF Parsing & Preprocessing: Libraries like pdfplumber are used to extract text data from PDFs. This is part of the backend processing.
- LangChain Components: The inclusion of libraries such as langchain_core, langchain_community, and langchain_ollama suggests that the project uses LangChain to manage workflows, query chaining, and integration with the language model.
- RAG Flow (for rag_deep.py): An additional flow that uses Retrieval Augmented Generation to incorporate document retrieval with language model outputs, enhancing the Q&A functionality.

##### Relationships and Interactions
- The UI (Streamlit app) serves as the entry point. Users submit queries via the browser.
- The UI triggers back-end processes that may include:
– Parsing documents from the document store (using pdfplumber).
– Passing queries and possibly document excerpts to the local language model via Ollama.
– Running LangChain pipelines to facilitate the RAG process (if using rag_deep.py).
- Data flows from the document store and through the preprocessing layer (PDF parsing) to build a context, which is then provided as input to the language model.
- The language model’s response is sent back through the LangChain flow to the UI for display.

##### Architectural Patterns or Design Principles
- Separation of Concerns: Clearly divide the UI (app.py and rag_deep.py) from the backend processing (PDF parsing, document storage, and language model communication).
- Modular Architecture: Each major task (e.g., document preprocessing, language model interfacing, and presentation layer) is handled by distinct modules or libraries.
- Pipeline/Chaining Pattern: The integration with LangChain indicates that there’s a staged processing flow — starting with input, then document retrieval/processing, and finally generating the response.

##### Relevant Technologies, Frameworks, and Libraries
- Streamlit for the web interface.
- pdfplumber for PDF text extraction.
- LangChain libraries (core, community, and ollama) for workflow management.
- Ollama for running the deep learning model locally.
- Python as the programming language (evidenced by the .py files).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend"
        UI1["Streamlit UI (app.py)"]
        UI2["Streamlit UI with RAG (rag_deep.py)"]
    end

    subgraph "Backend Processing"
        subgraph "Document Processing Pipeline"
            DS["Document Store (PDFs)"]
            PP["PDF Parser (pdfplumber)"]
            DS -->|"retrieves"| PP
        end
        LC["LangChain Workflow Manager"]
        PP -->|"builds_context"| LC
        subgraph "Local Model"
            LM["Local Ollama Model (deepseek-r1:1.5b)"]
        end
        LC -->|"model_inference"| LM
        LM -->|"model_response"| LC
    end

    UI1 -->|"sends_query"| LC
    UI2 -->|"sends_query"| LC
    LC -->|"displays_answer"| UI1
    LC -->|"displays_answer"| UI2

    click UI1 "https://github.com/samnageub/genai/blob/main/app.py"
    click UI2 "https://github.com/samnageub/genai/blob/main/rag_deep.py"
    click DS "https://github.com/samnageub/genai/tree/main/document_store/pdfs"

    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef storage fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef model fill:#FFB6C1,stroke:#333,stroke-width:2px;

    class UI1,UI2 frontend;
    class DS storage;
    class PP,LC backend;
    class LM model;
```
