# donismaelito/quill architecture

> Architecture diagram of the GitHub repository donismaelito/quill, 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/donismaelito/quill
- Repository: https://github.com/donismaelito/quill

## Overview

##### Main Components
- Frontend:
- Use the “src/frontend/quill” directory as the Next.js (React) web UI.
- API endpoints under “src/frontend/quill/src/app/api/…” and clearly show components like chat interfaces, document upload & preview, and layout elements.
- Backend Services:
- Python-based backend: the “src” folder holds multiple modules such as “appeals,” “assessment,” “document_creation,” “document_templating,” and different RAG versions (“rag”, “rag_v2”, “rag_v3”, “rag_v4”).
- The “src/main.py” acts as an entry point to run the backend.
- Integration scripts like “llama3_2_finetune.ipynb” and the experimental “openai_assistant” folder.
- Document Processing & OCR:
- “src/document_creation” and “src/document_templating” contain scripts like “write_pdf.py”, “mistral_ocr.py”, and are responsible for form processing and document creation.
- Integration with OCR tools like Tesseract and poppler, as detailed in the README.
- Retrieval Augmented Generation (RAG) Engine:
- Multiple RAG modules (rag, rag_v2, rag_v3, rag_v4) indicate an evolving system for combining local LLM responses with a vector database.
- Sub-components for vector database storage (e.g., “chroma.sqlite3” in vector_db folders) and JSON-based user information.
- External API & Experimentation Modules:
- “openai_assistant” shows integration with the OpenAI Assistant API.
- Other experiments, such as “llama3.2-vision” and “janus_finetune”, should be represented as optional or experimental services.
- Configuration & Data:
- The “config” directory holds configuration data (config.yaml).
- The “data” and “uploads” directories store test files, user inputs, and form samples.
- Dependency and package management files include “requirements.txt”, “package.json”, “package-lock.json”, and Python packaging files in “src/deepseek”.

##### Relationships and Interactions
- Backend process modules (e.g., document creation, RAG, and OCR processing) as separate blocks that interact with the vector database and external services.
- Data flows such as:
- User uploads a document via the UI.
- The backend (within “document_creation” or one of the RAG components) processes the document with OCR and LLM calls.
- Data is stored or fetched from a vector database (shown in rag_v2, rag_v3 components).
- Final outputs (e.g., filled PDFs) are sent back to the UI.
- Feedback loops for update modes and persistent storage, as seen in the updated RAG system.

##### Architectural Patterns & Design Principles
- Modular design: Each “src” subfolder is a distinct module with dedicated responsibilities (e.g., appeals, assessment, templating).
- Separation of concerns:
- The Next.js frontend is entirely separated from the Python backend.
- Document processing, data extraction, and form filling are distinct processes.
- Extensibility: The experimental modules (OpenAI assistant API, Janus, and multiple rag versions) can be depicted as plug-in components that can be enabled or extended.

##### Relevant Technologies & Frameworks
- Python for backend script execution and document processing.
- Node.js/Next.js for the web UI.
- Deep learning models (R1, LLaVA, GPT-4o, etc.) indicated in the README for LLM tasks.
- Tesseract and poppler for OCR.
- Vector databases (using chroma.sqlite3 files) for the RAG system.
- API integrations (OpenAI Assistant API) as experimental services.

##### Specific Elements
- Clear Labels: Each component (Frontend, Backend, Document Processing, RAG Engine, External Services, Data/Config) should be labeled.
– Backend logic and processing modules another.
– External services and databases a third distinct style.
- Annotated Dependencies: Optionally include key technologies (e.g., “Next.js”, “Python”, “Tesseract”, “Vector DB”) next to respective blocks.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        A["Next.js Web UI"]:::frontend
        B["API Endpoints"]:::frontend
        C["UI Components"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        D["Backend Main (Python)"]:::backend
        
        %% Document Processing Cluster
        subgraph "Document Processing"
            E["Document Creation"]:::processing
            F["Document Templating"]:::processing
        end
        
        %% RAG Engine Cluster
        subgraph "RAG Engine"
            G["RAG v1"]:::rag
            H["RAG v2"]:::rag
            I["RAG v3"]:::rag
            J["RAG v4"]:::rag
        end
        
        %% Model Integration Cluster
        subgraph "Model Integration"
            K["OpenAI Assistant API"]:::integration
            L["Llama3.2 Vision"]:::integration
            M["Janus Finetuning"]:::integration
        end
    end

    %% Configuration & Dependency Layer
    subgraph "Configuration & Data"
        N["Configuration"]:::config
        O["Data Samples"]:::config
        P["Uploads"]:::config
        Q["Dependencies"]:::dependencies
        R["Deepseek Packaging"]:::dependencies
    end

    %% Data Flow Connections
    A --> B
    B -->|"API call"| D
    D --> E
    D --> F
    D --> G
    D --> H
    D --> I
    D --> J
    D --> K
    D --> L
    D --> M
    E -->|"Stores output"| P
    F -->|"Stores template"| P
    D -->|"Uses"| N
    D -->|"Reads"| O
    D -->|"Depends"| Q
    D -->|"Integrates"| R
    D -->|"Response"| C

    %% Class Definitions
    classDef frontend fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef backend fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef processing fill:#ffa500,stroke:#333,stroke-width:2px;
    classDef rag fill:#ffdead,stroke:#333,stroke-width:2px;
    classDef integration fill:#ffffe0,stroke:#333,stroke-width:2px;
    classDef config fill:#dda0dd,stroke:#333,stroke-width:2px;
    classDef dependencies fill:#d3d3d3,stroke:#333,stroke-width:2px;

    %% Click Events
    click A "https://github.com/donismaelito/quill/tree/main/src/frontend/quill"
    click B "https://github.com/donismaelito/quill/tree/main/src/frontend/quill/src/app/api"
    click C "https://github.com/donismaelito/quill/tree/main/src/frontend/quill/src/components"
    click D "https://github.com/donismaelito/quill/blob/main/src/main.py"
    click E "https://github.com/donismaelito/quill/tree/main/src/document_creation"
    click F "https://github.com/donismaelito/quill/tree/main/src/document_templating"
    click G "https://github.com/donismaelito/quill/tree/main/src/rag"
    click H "https://github.com/donismaelito/quill/tree/main/src/rag_v2"
    click I "https://github.com/donismaelito/quill/tree/main/src/rag_v3"
    click J "https://github.com/donismaelito/quill/tree/main/src/rag_v4"
    click K "https://github.com/donismaelito/quill/tree/main/openai_assistant"
    click L "https://github.com/donismaelito/quill/blob/main/src/llama3.2-vision"
    click M "https://github.com/donismaelito/quill/tree/main/src/janus_finetune/quill"
    click N "https://github.com/donismaelito/quill/tree/main/config"
    click O "https://github.com/donismaelito/quill/tree/main/data"
    click P "https://github.com/donismaelito/quill/tree/main/src/uploads"
    click Q "https://github.com/donismaelito/quill/blob/main/requirements.txt"
    click R "https://github.com/donismaelito/quill/tree/main/src/deepseek"
```
