# ranads/rrjl architecture

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

- Interactive diagram: https://gitdiagram.com/ranads/rrjl
- Repository: https://github.com/ranads/rrjl

## Overview

##### Primary Components
- Frontend/UI: Although there isn’t a dedicated "frontend" directory, the README specifies Streamlit is used for the graphical user interface. Represent this as a separate component.
- Backend/API: The presence of backend.py suggests that FastAPI handles incoming HTTP requests and business logic.
- Chatbot Logic: The chatbot.py file implies the inclusion of core chatbot functionalities, such as interfacing with language models or handling the RAG process.
- PDF Upload & Document Processing: As PDF file uploads are now supported, include a component that handles file ingestion and processing.
- Vector Store: A Chroma vector store is used to perform retrieval from the uploaded PDFs. This should be explicitly labeled.
- Database: The README mentions PostgreSQL for data storage (e.g., chat history). Add a separate component representing the database.
- Configuration & Deployment: Represent supporting components like GitHub workflows (.github/workflows/stage6deploy.yml) and shell scripts (setup.sh, update_app.sh) to demonstrate deployment and environment setup.

##### Interactions
- The user interacts with the system via the Streamlit frontend.
- The frontend communicates with the FastAPI backend (backend.py), likely sending chat messages and file uploads.
- The backend (FastAPI) routes requests to the appropriate modules:
- Chatbot logic in chatbot.py handles natural language processing and chat interactions.
- Uploaded PDFs are processed and passed to the vector store (Chroma) for context extraction.
- The API also interacts with PostgreSQL—for storing chat histories, and possibly metadata related to PDF documents.
- Data flows from the browser (user) through the frontend to the backend, and then across to both the vector store and the database.
- Deployment and continuous integration are supported by GitHub workflows and setup scripts to streamline project stability and updates.

##### Architectural Patterns & Design Principles
- Separation of Concerns: The clear division between the UI (Streamlit), API (FastAPI), chatbot core (chatbot.py), and external services (vector store and PostgreSQL) suggests adherence to modular, loosely coupled design principles.
- Extensibility: The structure easily allows for future expansion (e.g., new file types or enhanced chatbot features).

##### Relevant Technologies
- Frontend: Streamlit
- Backend: FastAPI (backend.py)
- Chatbot Processing: Chatbot.py likely involves LLM-related calls and RAG logic.
- PDF Processing: A module that converts PDFs to context for the vector store (not explicitly named but part of the new functionality).
- Vector Store: Chroma is used for retrieval purposes.
- Database: PostgreSQL for persistent storage.
- CI/CD: GitHub Actions (workflows in .github/workflows) for deployment automation.
- Shell Scripts: setup.sh and update_app.sh for environment configuration and deployment steps.

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User"]:::user

    subgraph "Presentation Layer"
        UI["Streamlit UI"]:::frontend
    end

    subgraph "Business Logic Layer"
        API["FastAPI Backend"]:::backend
        Chatbot["Chatbot Module (RAG Engine)"]:::module
        PDFProc["PDF Upload/Processing"]:::module
    end

    subgraph "Data & Services Layer"
        Vector["Chroma Vector Store"]:::store
        DB["PostgreSQL Database"]:::database
    end

    subgraph "Infrastructure"
        CICD["CI/CD Pipeline"]:::infra
        Setup["Deployment Script: setup.sh"]:::infra
        Update["Deployment Script: update_app.sh"]:::infra
    end

    User -->|"uses"| UI
    UI -->|"requests"| API
    API -->|"processes"| Chatbot
    API -->|"handles"| PDFProc
    Chatbot -->|"retrieves"| Vector
    PDFProc -->|"processes"| Vector
    API -->|"saves"| DB

    CICD -->|"automates"| Setup
    CICD -->|"automates"| Update
    Setup -.->|"deploys"| API
    Setup -.->|"deploys"| UI
    Update -.->|"deploys"| API
    Update -.->|"deploys"| UI

    click UI "https://github.com/ranads/rrjl/blob/main/README.md"
    click API "https://github.com/ranads/rrjl/blob/main/backend.py"
    click Chatbot "https://github.com/ranads/rrjl/blob/main/chatbot.py"
    click CICD "https://github.com/ranads/rrjl/blob/main/.github/workflows/stage6deploy.yml"
    click Setup "https://github.com/ranads/rrjl/blob/main/setup.sh"
    click Update "https://github.com/ranads/rrjl/blob/main/update_app.sh"

    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef backend fill:#FFCC99,stroke:#333,stroke-width:2px;
    classDef module fill:#D5F5E3,stroke:#333,stroke-width:2px;
    classDef store fill:#F9E79F,stroke:#333,stroke-width:2px;
    classDef database fill:#F5B7B1,stroke:#333,stroke-width:2px;
    classDef infra fill:#D6EAF8,stroke:#333,stroke-width:2px;
    classDef user fill:#E8DAEF,stroke:#333,stroke-width:2px;
```
