# suvkp/docuassist_ai architecture

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

- Interactive diagram: https://gitdiagram.com/suvkp/docuassist_ai
- Repository: https://github.com/suvkp/docuassist_ai

## Overview

##### Main Components
- Frontend (User Interface):
- Represented by the "ui" directory in the repository and the Streamlit framework (as mentioned in the README).
- This component handles user interactions such as document uploads, Q&A inputs, and displaying results.
- Backend (Core Processing Service):
- Captured within the "core" directory, which contains modules like doc_processor.py, index.py, and retriever.py.
- This layer is responsible for parsing documents, indexing content, retrieving relevant information, and interacting with AI models.
- External Services & APIs:
- OpenAI APIs: Both for the GPT-4o mini model (which drives the Q&A functionality) and the text embedding model for document parsing.
- LlamaParse and LlamaIndex: As integration points for parsing complex documents and managing document indexing.
- Data & Resources:
- The “resource” directory contains sample documents (PDFs, brochures) and the “document” directory holds various technical documentation files. Even if these are examples, they represent what users might upload as input to the system.
- Infrastructure / Deployment:
- The existence of .devcontainer and configuration files indicates containerized development or deployment environments which can be included subtly in your overall architecture (especially if hosting or container orchestration is planned).
- Main Entry Point:
- The file “main.py” signifies the application’s start point, orchestrating the overall flow from user input via the frontend layer to core processing and external API calls.

##### Relationships and Data Flow
- This to the backend process, showing how the user’s actions (document uploads and query inputs) trigger processing in the “core” modules.
- The Backend:
- Interaction among its subcomponents: document parsing (likely in doc_processor.py), text indexing (index.py, possibly coordinating with LlamaIndex), and information retrieval (retriever.py). These subcomponents collectively handle the request before calling external AI services.
- External API Integration:
- Data Repositories:
- How the document resources (uploaded user documents, technical docs, etc.) flow into the parser, and then how indexed outputs are stored/fetched during Q&A sessions.

##### Architectural Patterns and Design Principles
- A clear separation of concerns between the UI (Streamlit) and backend logic.
- Modular design: Notice how individual backend components (document processor, indexer, retriever) are decoupled, making it easier to maintain and scale each part.
- Microservices-like integration in that external services (LlamaParse/LlamaIndex, OpenAI APIs) are clearly defined as external dependencies—this abstraction should be visually captured.
- RAG (Retrieval Augmented Generation) design, where the system first retrieves the relevant chunk of document information before generating a concise response through the LLM.

##### Final Touches
- Maintain clarity by avoiding overcrowding; try to focus on the most important architectural elements and indicate major data flows.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    UI["Frontend (Streamlit UI)"]:::frontend

    %% Main Entry Point
    MAIN["Main Entry Point"]:::main

    %% Backend Processing Layer with submodules
    BE["Backend Processing"]:::backend
    subgraph "Backend Processing Modules"
        DP["Document Parsing Module"]:::backendModule
        IDX["Indexing Module"]:::backendModule
        RET["Retrieval Module"]:::backendModule
    end

    %% External AI Services
    EXT["External AI Services"]:::external
    OAI_GPT["OpenAI GPT-4o (Text Generation)"]:::externalAPI
    OAI_EMB["OpenAI Embedding (Context Extraction)"]:::externalAPI
    LLAMA["LlamaParse & LlamaIndex"]:::externalAPI

    %% Data & Resources
    DATA_DOC["Technical Documents"]:::data
    DATA_RES["Sample Resources"]:::data

    %% Infrastructure / Deployment
    CONTAINER["Containerized Environment"]:::container

    %% Connections
    UI -->|"triggers"| MAIN
    MAIN -->|"orchestrates"| BE

    BE -->|"invokes"| DP
    BE -->|"coordinates"| IDX
    BE -->|"handles queries"| RET

    DP -->|"extracts_text_for_embedding"| OAI_EMB
    DP -->|"parses_PDFs"| LLAMA
    IDX -->|"indexes_content"| RET
    RET -->|"generates_response"| OAI_GPT
    OAI_GPT -->|"returns_answer"| UI

    DATA_DOC -->|"provides_documents"| DP
    DATA_RES -->|"supplies_samples"| DP

    CONTAINER -->|"hosts"| UI
    CONTAINER -->|"hosts"| BE

    %% External services grouping (for visual clarity)
    EXT --- OAI_GPT
    EXT --- OAI_EMB
    EXT --- LLAMA

    %% Click Events
    click UI "https://github.com/suvkp/docuassist_ai/blob/main/ui/side_panel.py"
    click DP "https://github.com/suvkp/docuassist_ai/blob/main/core/doc_processor.py"
    click IDX "https://github.com/suvkp/docuassist_ai/blob/main/core/index.py"
    click RET "https://github.com/suvkp/docuassist_ai/blob/main/core/retriever.py"
    click MAIN "https://github.com/suvkp/docuassist_ai/blob/main/main.py"
    click DATA_DOC "https://github.com/suvkp/docuassist_ai/tree/main/document"
    click DATA_RES "https://github.com/suvkp/docuassist_ai/tree/main/resource"
    click CONTAINER "https://github.com/suvkp/docuassist_ai/blob/main/.devcontainer/devcontainer.json"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef main fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef backendModule fill:#98FB98,stroke:#000,stroke-width:1px;
    classDef external fill:#F0E68C,stroke:#000,stroke-width:2px;
    classDef externalAPI fill:#FFEFD5,stroke:#000,stroke-width:2px;
    classDef data fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef container fill:#FFA07A,stroke:#000,stroke-width:2px;
```
