# su77ungr/casalioy architecture

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

- Interactive diagram: https://gitdiagram.com/su77ungr/casalioy
- Repository: https://github.com/su77ungr/casalioy

## Overview

##### Main Components
- Ingestion Module:
- Represented by the “ingest.py” script (within the casalioy folder).
- Responsible for consuming documents from the “source_documents” directory (various formats: CSV, PDF, DOCX, etc.), parsing and chunking them, and creating embeddings.
- Uses LangChain tools and llama-cpp-based embeddings (e.g., LlamaCppEmbeddings).
- Vector Database Component:
- A local vector store implemented using Qdrant – stored in the “db” folder.
- Acts as the repository for the generated document embeddings.
- Query / LLM Processing Module:
- The “startLLM.py” script initiates the process of handling user queries.
- Performs a similarity search on the vector database to retrieve relevant document segments.
- Forwards those segments as context into the chosen LLM (which may be GPT4All-J or a similar model compatible with LlamaCpp).
- GUI Interface:
- The “gui.py” (in the casalioy folder) provides a Streamlit-based web interface.
- Allows users to chat interactively with the local LLM, abstracting the CLI details.
- Utility and Environment Setup:
- “load_env.py” manages environment variables loaded from the .env file, ensuring configuration (like MODEL_PATH, chunk size, etc.) is centralized.
- Other utility scripts such as “CustomChains.py”, “ask_libgen.py”, and modules under “misc” provide additional functionality (e.g., conversion utilities, debugging, and even model conversion from GGML to GGUF).

##### Data Flow and Interactions
- Document Ingestion Flow:
- Documents in “source_documents” are processed by ingest.py.
- The ingestion process outputs embeddings which are then saved into the Qdrant vector store (local “db” folder).
- Query Processing Flow:
- When a user submits a query (via CLI “startLLM.py” or the Streamlit GUI):
→ The query is used to perform a similarity search on the local vector store.
→ The most relevant document segments are retrieved.
→ The selected context is forwarded along with the query to the LLM for answer generation.
- LLM and External Dependencies:
- The system relies on external libraries such as LangChain and llama-cpp for core functionalities.
- Dockerfiles and GitHub workflows encapsulate the environment for deployment or GPU support.

##### Architectural Patterns and Design Principles
- Modular and Layered Architecture:
- The project separates concerns into ingestion, storage, processing, and interaction layers.
- Configurability:
- With environment files (.env) and configuration scripts (load_env.py), the toolkit supports customization and extensibility.
- Containerization:
- Dockerfiles and CI/CD GitHub workflows ensure that the application can be deployed in a consistent environment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Ingestion Layer
    subgraph "Data Ingestion Layer"
        SourceDocs["Source Documents Repository"]:::ingestion
        Ingestion["ingest.py (Document Ingestion Module)"]:::ingestion
    end

    %% Storage Layer
    subgraph "Storage Layer"
        VectorDB["Vector Database (Qdrant)"]:::db
    end

    %% Query Processing Layer
    subgraph "Query Processing Layer"
        CLIEngine["startLLM.py (LLM Query Engine - CLI)"]:::query
        LLM["Local LLM (GPT4All-J)"]:::query
    end

    %% User Interface Layer
    subgraph "User Interface Layer"
        GUI["gui.py (Streamlit GUI)"]:::interface
    end

    %% Configuration & Utilities
    subgraph "Configuration & Utilities"
        loadEnv["load_env.py"]:::utility
        customChains["CustomChains.py"]:::utility
        askLibgen["ask_libgen.py"]:::utility
        misc["Misc Utilities (misc)"]:::utility
    end

    %% External Dependencies
    subgraph "External Dependencies"
        LangChain["LangChain"]:::external
        LlamaCpp["llama-cpp"]:::external
    end

    %% Deployment & Containerization
    subgraph "Deployment & Containerization"
        Deployment["Deployment & Containerization\n(Dockerfile, Dockerfile-GPU, GitHub workflows)"]:::deployment
    end

    %% Data Flow Connections
    SourceDocs -->|"ingests_docs"| Ingestion
    Ingestion -->|"creates_embeddings"| VectorDB

    CLIEngine -->|"similarity_lookup"| VectorDB
    CLIEngine -->|"forwards_context"| LLM
    GUI -->|"initiates_query"| CLIEngine

    %% External Dependencies Relations
    Ingestion -->|"uses"| LangChain
    Ingestion -->|"uses"| LlamaCpp
    CLIEngine -->|"depends_on"| LangChain
    CLIEngine -->|"depends_on"| LlamaCpp

    %% Utilities influencing Ingestion
    loadEnv --- Ingestion
    loadEnv --- CLIEngine
    customChains --- Ingestion
    askLibgen --- Ingestion
    misc --- Ingestion

    %% Deployment influencing all components
    Deployment --- Ingestion
    Deployment --- VectorDB
    Deployment --- CLIEngine
    Deployment --- GUI
    Deployment --- loadEnv
    Deployment --- customChains
    Deployment --- askLibgen
    Deployment --- misc

    %% Click Events
    click Ingestion "https://github.com/su77ungr/casalioy/blob/main/casalioy/ingest.py"
    click CLIEngine "https://github.com/su77ungr/casalioy/blob/main/casalioy/startLLM.py"
    click GUI "https://github.com/su77ungr/casalioy/blob/main/casalioy/gui.py"
    click loadEnv "https://github.com/su77ungr/casalioy/blob/main/casalioy/load_env.py"
    click customChains "https://github.com/su77ungr/casalioy/blob/main/casalioy/CustomChains.py"
    click askLibgen "https://github.com/su77ungr/casalioy/blob/main/casalioy/ask_libgen.py"
    click misc "https://github.com/su77ungr/casalioy/tree/main/casalioy/misc"
    click SourceDocs "https://github.com/su77ungr/casalioy/tree/main/source_documents"
    click Deployment "https://github.com/su77ungr/casalioy/tree/main/Dockerfile"
    click Deployment "https://github.com/su77ungr/casalioy/tree/main/Dockerfile-GPU"
    click Deployment "https://github.com/su77ungr/casalioy/tree/main/.github/workflows"

    %% Styles
    classDef ingestion fill:#a3d5ff,stroke:#1f78b4,stroke-width:2px;
    classDef query fill:#ffcc80,stroke:#f57c00,stroke-width:2px;
    classDef interface fill:#c8e6c9,stroke:#388e3c,stroke-width:2px;
    classDef db fill:#ffab91,stroke:#d84315,stroke-width:2px;
    classDef utility fill:#e1bee7,stroke:#8e24aa,stroke-width:2px;
    classDef external fill:#ffe082,stroke:#f9a825,stroke-width:2px;
    classDef deployment fill:#dcedc8,stroke:#7cb342,stroke-width:2px;
```
