# fahadahmedk/ragdocmanager architecture

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

## Overview

##### Main Components
- API Layer – Under the “src/rag_doc_manager/api” directory, you have routes defined for documents, registration, and search. This layer will expose the HTTP endpoints and act as the interactive entry point for users.
- Document Manager – Located in “src/rag_doc_manager/document_manager,” this should be highlighted as the central component. It includes integration with Azure services (as indicated by “azure_document_manager.py”), various data models, and contractual interfaces.
- Document Processor – This module (“src/rag_doc_manager/document_processor”) is responsible for handling tasks such as chunking, loading, and embedding of documents. It also includes factories that support multiple strategies.
- Index and Index Manager – Found in “src/rag_doc_manager/index” and “src/rag_doc_manager/index_manager,” these components handle the creation, management, and querying of document indexes.
- Search – Under “src/rag_doc_manager/search,” this component includes adaptors (like “azure_ai_query_engine.py”) that connect search queries to the underlying indexed data.
- Storage – Various storage facets are split into managing databases (e.g., Cosmos DB), blob storage (Azure Blob Storage), secrets (with Azure Key Vault), and history management. These are found in “src/rag_doc_manager/storage” and related subdirectories.
- Customer Manager – This component (“src/rag_doc_manager/customer_manager”) manages customer-related data and schema management, ensuring that document operations are performed in a multitenant or customer-specific context.
- Utility Functions – Found in “src/rag_doc_manager/utils” to support common IO operations and data manipulation.

##### Relationships and Interactions
- Within the system, illustrate the internal flow:
- Document Manager connects with Document Processor to handle document transformations (chunking, loading, embedding).
- Processed documents then get handed off to the Index or Index Manager components to create an index.
- The Search module queries the index when needed.
- In parallel, the Storage module supports the entire system by managing persistent data (documents, indexes, audit history, and configuration secrets).
- The Customer Manager may interact with several components (API, Document Manager, and Storage) to enforce customer-specific rules.

##### Architectural Patterns and Design Principles
- That the system is modular and decoupled; components communicate via well-defined interfaces (evident from the “base”, “contracts”, and “factory” files defined in multiple modules).
- Separation of concerns – the API layer for communication, Document Manager for core business logic (document handling), Document Processor for data handling, and Storage/Search for persistence and retrieval.

##### Relevant Technologies and Frameworks
- The project uses Python (as seen in files like __init__.py, pyproject.toml, and a Dockerfile for containerization).
- Azure services are explicitly referenced in multiple modules.
- The usage of a structured folder design, including factories and adaptors, suggests extensibility for various document processing strategies.

- Restate the Document Manager as the central hub that interfaces with Document Processor, Index/Index Manager, and Storage layers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend
    U("User"):::userStyle

    %% API Layer
    API("API Gateway"):::apiStyle

    %% Core Backend Components
    DM("Document Manager"):::coreStyle
    DP("Document Processor"):::moduleStyle
    IDX("Index"):::moduleStyle
    IDXM("Index Manager"):::moduleStyle
    SRCH("Search Interface"):::moduleStyle
    SM("Storage & Secrets"):::storageStyle
    CM("Customer Manager"):::moduleStyle
    UT("Utility Functions"):::moduleStyle

    %% Relationships
    U -->|"sendsRequest"| API
    API -->|"documentOps"| DM
    API -->|"searchQueries"| SRCH
    API -->|"customerReq"| CM

    DM -->|"processDocuments"| DP
    DP -->|"generateIndex"| IDX
    DP -->|"manageIndex"| IDXM
    SRCH -->|"queryIndex"| IDX

    DM -->|"storeData"| SM
    DP -->|"storeData"| SM
    IDX -->|"storeIndex"| SM
    IDXM -->|"storeIndex"| SM
    CM -->|"storeCustomerData"| SM

    DM -->|"customerContext"| CM

    UT -->|"supportOps"| DM
    UT -->|"supportOps"| DP
    UT -->|"supportOps"| SM

    %% Click Events
    click API "https://github.com/fahadahmedk/ragdocmanager/tree/main/src/rag_doc_manager/api"
    click API "https://github.com/fahadahmedk/ragdocmanager/tree/main/src/rag_doc_manager/api/routes"
    click DM "https://github.com/fahadahmedk/ragdocmanager/tree/main/src/rag_doc_manager/document_manager"
    click DP "https://github.com/fahadahmedk/ragdocmanager/tree/main/src/rag_doc_manager/document_processor"
    click IDX "https://github.com/fahadahmedk/ragdocmanager/tree/main/src/rag_doc_manager/index"
    click IDXM "https://github.com/fahadahmedk/ragdocmanager/tree/main/src/rag_doc_manager/index_manager"
    click SRCH "https://github.com/fahadahmedk/ragdocmanager/tree/main/src/rag_doc_manager/search"
    click SM "https://github.com/fahadahmedk/ragdocmanager/tree/main/src/rag_doc_manager/storage"
    click CM "https://github.com/fahadahmedk/ragdocmanager/tree/main/src/rag_doc_manager/customer_manager"
    click UT "https://github.com/fahadahmedk/ragdocmanager/tree/main/src/rag_doc_manager/utils"

    %% Style Definitions
    classDef userStyle fill:#FFD700,stroke:#000,stroke-width:2px
    classDef apiStyle fill:#ADD8E6,stroke:#000,stroke-width:2px
    classDef coreStyle fill:#FFB6C1,stroke:#C71585,stroke-width:3px,font-weight:bold
    classDef moduleStyle fill:#E6E6FA,stroke:#4B0082,stroke-width:2px
    classDef storageStyle fill:#90EE90,stroke:#006400,stroke-width:2px
```
