# ouerghi01/ragentx architecture

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

- Interactive diagram: https://gitdiagram.com/ouerghi01/ragentx
- Repository: https://github.com/ouerghi01/ragentx

## Overview

##### Project Overview
- Agent Bot is an AI-powered assistant that leverages Retrieval-Augmented Generation (RAG), a scalable Cassandra DataStax backend, and FastAPI as the core web API server.
- The project also includes advanced features like an auto-complete engine implemented in C (via a Trie data structure), integrated into the Python service layer, and a dynamic frontend enhanced with HTMX.

##### Key Components
a. API / Web Server (FastAPI):
– Represent the FastAPI app (main.py) as the central hub.
– Note that API endpoints include “/” for the main page and “/send_message” to fetch AI-generated responses.
b. Service Layer:
- Crawler, TEXT2CQL_PROMPT, agent_service, auth_service, cassandra_service, cql_agent, load_data, notes, pdf_service, q_learning_llm, semantic_cache, and trie_service.
– Clearly indicate that these modules handle business logic, data processing, and integrations.
c. Auto-complete Engine:
d. Database:
– Include a “Cassandra (DataStax)” component representing the scalable NoSQL database.
e. External Integrations:
– Optionally, include external services for RAG such as LangChain (for prompt engineering and retrieval features).
f. Frontend Components:
– Represent the dynamic UI aspects:
- Static assets (CSS and JavaScript from APP/static)
- HTML templates (from APP/templates) rendered by FastAPI.
– Emphasize that the frontend is enhanced via HTMX for dynamic HTML updates.
g. Containerization / Deployment:
– Show a container boundary indicating Docker container(s) backed by the APP/dockerfile and the orchestration provided by docker-compose.yml.
– Optionally, indicate that build-related actions (via Makefile in APP) are part of the deployment pipeline.

##### Relationships and Interactions
- How front-end clients (browsers) interact via HTTP with the FastAPI layer.
- FastAPI dispatches requests to the appropriate service modules.
- Services, such as cassette_service, communicate with the Cassandra database.
- The auto-complete requests are handled by the Trie service that interfaces with the compiled C code.
- External API calls from the service layer toward LLM providers and LangChain.
– Mark data flow, for example, inbound request processing, retrieval augmented generation steps, and response dispatch.

##### Architectural Patterns & Key Principles
– Emphasize separation of concerns by grouping components in layers: Presentation (UI templates and static files), Application/API logic (FastAPI and endpoints), and Service integrations (business logic modules).
– Indicate the RAG pattern by showing both retrieval (data extraction from Cassandra and caches) and generation (using LLMs).
– The auto-completion module using a C-implemented Trie should be highlighted as a performance optimization layer.
– Containerization best practices are used for deployment; show Docker containers linked to the individual components if applicable.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FT["Frontend Templates"]:::frontend
        FS["Frontend Static Assets"]:::frontend
    end

    %% User Layer
    UB["User Browser"]:::client

    %% API Layer
    subgraph "API Layer"
        FA["FastAPI Web Server"]:::api
    end

    %% Services Layer
    subgraph "Services Layer"
        S["Services"]:::services
        TA["Trie Autocomplete Engine (C)"]:::services
        CS["Cassandra Service"]:::services
        AS["Agent Service"]:::services
        QL["Q-Learning LLM Service"]:::services
    end

    %% External Integrations
    subgraph "External Integrations"
        ELLM["External LLM Services (Gemini/Ollama)"]:::external
        LC["LangChain"]:::external
    end

    %% Database Layer
    subgraph "Database"
        DB["Cassandra DB (DataStax)"]:::database
    end

    %% Deployment / Containerization
    subgraph "Deployment"
        DF["Dockerfile"]:::container
        DC["docker-compose.yml"]:::container
        MK["Makefile"]:::container
    end

    %% Connections between layers
    UB -->|"HTTP"| FA
    FA -->|"dispatches to"| S
    FA -->|"renders"| FT
    FA -->|"serves"| FS

    S -->|"calls autocomplete"| TA
    S -->|"handles data operations"| CS
    S -->|"invokes LLM"| AS
    S -->|"triggers generation"| QL

    CS -->|"queries"| DB

    AS -->|"calls"| ELLM
    QL -->|"calls"| ELLM
    AS -->|"uses retrieval via"| LC

    %% Styling for clarity and color codes
    classDef api fill:#f9d5bb,stroke:#333,stroke-width:2px;
    classDef services fill:#d5e8d4,stroke:#333,stroke-width:2px;
    classDef external fill:#dae8fc,stroke:#333,stroke-width:2px;
    classDef frontend fill:#ffe6cc,stroke:#333,stroke-width:2px;
    classDef container fill:#e1d5e7,stroke:#333,stroke-width:2px;
    classDef database fill:#fff2cc,stroke:#333,stroke-width:2px;
    classDef client fill:#fce5cd,stroke:#333,stroke-width:2px;

    %% Click Events
    click FA "https://github.com/ouerghi01/ragentx/blob/main/APP/main.py"
    click S "https://github.com/ouerghi01/ragentx/tree/main/APP/services"
    click TA "https://github.com/ouerghi01/ragentx/blob/main/APP/c_src/trie.c"
    click TA "https://github.com/ouerghi01/ragentx/blob/main/APP/c_src/trie.h"
    click CS "https://github.com/ouerghi01/ragentx/blob/main/APP/services/cassandra_service.py"
    click AS "https://github.com/ouerghi01/ragentx/blob/main/APP/services/agent_service.py"
    click QL "https://github.com/ouerghi01/ragentx/blob/main/APP/services/q_learning_llm.py"
    click FT "https://github.com/ouerghi01/ragentx/tree/main/APP/templates"
    click FS "https://github.com/ouerghi01/ragentx/tree/main/APP/static"
    click DF "https://github.com/ouerghi01/ragentx/tree/main/APP/dockerfile"
    click DC "https://github.com/ouerghi01/ragentx/blob/main/docker-compose.yml"
    click MK "https://github.com/ouerghi01/ragentx/tree/main/APP/Makefile"
```
