# fahadahmedk/ragdocmanager2 architecture

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

- Interactive diagram: https://gitdiagram.com/fahadahmedk/ragdocmanager2
- Repository: https://github.com/fahadahmedk/ragdocmanager2

## Overview

##### Main Components
- API Layer: Represented by the “api” directory, this layer exposes REST endpoints. The subdirectories indicate routes for “documents”, “registration”, and “search”.
- Document Processing Module: Under “document_processor” you have submodules for chunkers, document loaders, and embedders, plus processing utilities. This module is responsible for transforming raw documents into indexed content.
- Document Management Module: In “document_manager”, which contains logic for document management including Azure-specific implementations.
- Indexing and Search Subsystems:
- “index” and “index_manager” hold indexing logic, including adapters for Azure AI indexing.
- “search” contains search logic with an adapter for Azure AI query.
- Customer Management Module: The “customer_manager” handles customer-specific data and configurations.
- Storage Services: The “storage” directory is divided into:
- Database manager (with a CosmosDB manager)
- History storage
- Object storage (azure_blob_storage)
- Secrets storage, including Azure Key Vault integrations
- Utils: The “utils” module provides helper functions such as for I/O operations.
- Main Entry Point: “main.py” acts as the application’s entry point to wire all these components.

##### Relationships and Interactions
- API routes receive incoming requests (such as document uploads, registration, and search queries) and then forward them to the appropriate service components.
- Document Management and Processing modules interact; documents might first be loaded and chunked, then embedded, and subsequently sent to the indexing module.
- The indexing module (comprising “index” and “index_manager”) builds indexes used by the search module to efficiently retrieve documents.
- Customer management ensures that customer-specific configurations or policies are applied across the document and indexing workflows.
- The storage layer interacts with several modules for data persistence, including saving raw documents, the indexing data, and maintaining history, as well as managing authentication and secrets via the secrets module.

##### Architectural Patterns and Key Technologies
- Modular Design: The project is clearly partitioned into specialized modules (API, document processing, indexing, search, storage) that interact with one another.
- Adapter/Factory Patterns: Many modules (document_processor’s chunkers, document_loaders, embedders; search and index adaptors) use factory and adapter patterns to allow integration with different external providers (e.g., Azure AI services).
- Integration with External Services: The project leverages Azure’s services for document management (azure_document_manager), indexing (azure_ai_indexing_engine), query (azure_ai_query_engine), storage (azure_blob_storage), databases (cosmosdb_manager), and secrets (azure_key_vault).

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Layer
    Client["Client"]:::external

    %% API Layer
    subgraph "API Layer"
        API["API Endpoints"]:::api
        R1["Documents Route"]:::api
        R2["Registration Route"]:::api
        R3["Search Route"]:::api
    end

    Client -->|"calls"| API
    API --> R1
    API --> R2
    API --> R3

    %% Business Logic Layer
    subgraph "Business Logic"
        %% Document Processing Submodule
        subgraph "Document Processing"
            DP["Document Processor"]:::logic
            CH["Chunkers"]:::logic
            DL["Document Loaders"]:::logic
            EM["Embedders"]:::logic
            PU["Processing Utils"]:::logic
            PROC["Processor"]:::logic
        end

        DM["Document Manager"]:::logic

        %% Indexing and Search Subsystem
        subgraph "Indexing & Search"
            IX["Indexing"]:::logic
            IM["Index Manager"]:::logic
            SR["Search"]:::logic
        end

        CM["Customer Manager"]:::logic
        MAIN["Main Entry Point"]:::logic
    end

    %% API to Business Logic interactions
    R1 -->|"ingests"| DP
    R1 -->|"updates"| DM
    R3 -->|"queries"| SR
    DP -->|"processed docs"| IX
    IX -->|"manages index"| IM
    IM -->|"supports query"| SR
    MAIN --> DP
    MAIN --> DM
    MAIN --> IX
    MAIN --> SR
    MAIN --> CM
    CM --- DP
    CM --- DM
    CM --- IX
    CM --- SR

    %% Storage and External Services Layer
    subgraph "Storage & External Services"
        ST["Storage Services"]:::storage
        COS["Cosmos DB Manager"]:::storage
        AB["Azure Blob Storage"]:::storage
        AKV["Azure Key Vault"]:::storage
        SH["Secrets Handler"]:::storage
    end

    %% Business Logic to Storage interactions
    DM -->|"persists docs"| ST
    DP -->|"stores processed data"| ST
    IX -->|"saves index"| ST
    SR -->|"retrieves data"| ST
    CM -->|"customer data"| ST

    ST --> COS
    ST --> AB
    ST --> AKV
    ST --> SH

    %% Utilities
    subgraph "Utilities"
        UT["Utils"]:::logic
    end
    MAIN --> UT

    %% Click Events
    click API "https://github.com/fahadahmedk/ragdocmanager2/tree/main/src/rag_doc_manager/api"
    click R1 "https://github.com/fahadahmedk/ragdocmanager2/blob/main/src/rag_doc_manager/api/routes/documents.py"
    click R2 "https://github.com/fahadahmedk/ragdocmanager2/blob/main/src/rag_doc_manager/api/routes/registration.py"
    click R3 "https://github.com/fahadahmedk/ragdocmanager2/blob/main/src/rag_doc_manager/api/routes/search.py"
    click DP "https://github.com/fahadahmedk/ragdocmanager2/tree/main/src/rag_doc_manager/document_processor"
    click CH "https://github.com/fahadahmedk/ragdocmanager2/tree/main/src/rag_doc_manager/document_processor/chunkers"
    click DL "https://github.com/fahadahmedk/ragdocmanager2/tree/main/src/rag_doc_manager/document_processor/document_loaders"
    click EM "https://github.com/fahadahmedk/ragdocmanager2/tree/main/src/rag_doc_manager/document_processor/embedders"
    click PU "https://github.com/fahadahmedk/ragdocmanager2/tree/main/src/rag_doc_manager/document_processor/processing_utils"
    click PROC "https://github.com/fahadahmedk/ragdocmanager2/blob/main/src/rag_doc_manager/document_processor/processor.py"
    click DM "https://github.com/fahadahmedk/ragdocmanager2/tree/main/src/rag_doc_manager/document_manager"
    click IX "https://github.com/fahadahmedk/ragdocmanager2/tree/main/src/rag_doc_manager/index"
    click IM "https://github.com/fahadahmedk/ragdocmanager2/tree/main/src/rag_doc_manager/index_manager"
    click SR "https://github.com/fahadahmedk/ragdocmanager2/tree/main/src/rag_doc_manager/search"
    click CM "https://github.com/fahadahmedk/ragdocmanager2/tree/main/src/rag_doc_manager/customer_manager"
    click ST "https://github.com/fahadahmedk/ragdocmanager2/tree/main/src/rag_doc_manager/storage"
    click COS "https://github.com/fahadahmedk/ragdocmanager2/blob/main/src/rag_doc_manager/storage/database_manager/cosmosdb_manager.py"
    click AB "https://github.com/fahadahmedk/ragdocmanager2/blob/main/src/rag_doc_manager/storage/object_storage/azure_blob_storage.py"
    click AKV "https://github.com/fahadahmedk/ragdocmanager2/blob/main/src/rag_doc_manager/storage/secrets/azure_key_vault.py"
    click SH "https://github.com/fahadahmedk/ragdocmanager2/blob/main/src/rag_doc_manager/storage/secrets/credentials_handler.py"
    click UT "https://github.com/fahadahmedk/ragdocmanager2/blob/main/src/rag_doc_manager/utils/io.py"
    click MAIN "https://github.com/fahadahmedk/ragdocmanager2/blob/main/src/rag_doc_manager/main.py"

    %% Styles
    classDef external fill:#f9d6d5,stroke:#f08080,stroke-width:2px;
    classDef api fill:#cce5ff,stroke:#66b3ff,stroke-width:2px;
    classDef logic fill:#e6ffe6,stroke:#66cc66,stroke-width:2px;
    classDef storage fill:#fff0cc,stroke:#ffd700,stroke-width:2px;
```
