# aymenfurter/smartrag architecture

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

- Interactive diagram: https://gitdiagram.com/aymenfurter/smartrag
- Repository: https://github.com/aymenfurter/smartrag

## Overview

##### Main System Components

a) Frontend Layer:
- React-based web application
- Key components for different interaction modes (Chat, Voice, Research, Upload)
- Configuration management

b) Backend Services:
- Flask API server
- Multiple specialized modules (compare, ingestion, query, integration)
- Queue processors for indexing and uploads

c) Azure Cloud Services:
- Azure OpenAI Service
- Azure AI Search
- Document Intelligence
- Container Apps
- Blob Storage
- Cognitive Services

##### Architectural Patterns to Highlight

a) Multi-Agent System:
- Interaction between Researcher and Reviewer agents
- AutoGen framework integration
- Collaborative querying flow

b) Document Processing Pipeline:
- Document ingestion flow
- Indexing queue processing
- PDF processing and enhancement
- Table and image post-processing

c) Query Processing:
- GraphRAG implementation
- Voice processing pipeline
- Research workflow

**[User Interface Layer]**

**[API Gateway Layer]**

**[Service Layer]**
- Ingestion Services
- Query Services
- Comparison Services
- Integration Services

**[Agent Layer]**
- Researcher Agents
- Reviewer Agents

**[Azure Services Layer]**

##### Important Flows to Illustrate

- Document ingestion flow (Upload → Processing → Indexing)
- Query processing flow (User Input → Agent Processing → Response)
- Voice interaction flow (Speech → Text → Processing → Speech)
- Research workflow (Query → Multi-Agent Processing → Synthesis)

##### Technical Details

Technical elements:

- Container deployment boundaries
- Azure service connections
- Queue processing flows
- Storage interactions
- API endpoints

##### Component Relationships

Relationships:

- Frontend to API connections
- Service interdependencies
- Agent communication patterns
- Azure service integration points

This system design should reflect SmartRAG's nature as a demonstration tool while showing its sophisticated implementation of RAG concepts, multi-agent systems, and cloud service integration.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface"]
        App["Main App"]:::frontend
        Chat["Chat Interface"]:::frontend
        Voice["Voice Interface"]:::frontend
        Research["Research Interface"]:::frontend
        Upload["Upload Interface"]:::frontend
    end

    subgraph API["API Gateway"]
        Routes["API Routes"]:::backend
        Server["Main Server"]:::backend
    end

    subgraph Services["Service Layer"]
        subgraph Doc["Document Processing"]
            PDF["PDF Processing"]:::service
            DocInt["Document Intelligence"]:::service
            TablePost["Table Post-processing"]:::service
            IndexQ["Indexing Queue"]:::queue
            UploadQ["Upload Queue"]:::queue
        end

        subgraph Query["Query Processing"]
            GraphRAG["GraphRAG Implementation"]:::service
            ChatSvc["Chat Service"]:::service
            VoiceSvc["Voice Chat Service"]:::service
            ResearchSvc["Research Service"]:::service
        end

        subgraph Compare["Comparison System"]
            CompSvc["Comparison Service"]:::service
            CompExec["Comparison Executor"]:::service
            RespProc["Response Processor"]:::service
        end

        subgraph Integration["Azure Integration"]
            Search["AI Search Integration"]:::integration
            OpenAI["OpenAI Integration"]:::integration
            Blob["Blob Storage"]:::integration
            IndexMgr["Index Management"]:::integration
        end
    end

    subgraph Processors["Queue Processors"]
        UploadProc["Upload Processor"]:::queue
        IndexProc["Index Processor"]:::queue
    end

    subgraph Azure["Azure Services"]
        CogSvc["Cognitive Services"]:::azure
        SearchSvc["Search Services"]:::azure
        Storage["Storage Account"]:::azure
        Container["Container Apps"]:::azure
    end

    %% Connections
    App --> Routes
    Chat --> Routes
    Voice --> Routes
    Research --> Routes
    Upload --> Routes

    Routes --> Server
    Server --> Doc
    Server --> Query
    Server --> Compare

    Doc --> Integration
    Query --> Integration
    Compare --> Integration

    Integration --> Azure
    Processors --> Azure

    %% Click Events
    click App "https://github.com/aymenfurter/smartrag/blob/main/frontend/src/App.js"
    click Chat "https://github.com/aymenfurter/smartrag/blob/main/frontend/src/components/ChatSection.js"
    click Voice "https://github.com/aymenfurter/smartrag/blob/main/frontend/src/components/VoiceSection.js"
    click Research "https://github.com/aymenfurter/smartrag/blob/main/frontend/src/components/ResearchSection.js"
    click Upload "https://github.com/aymenfurter/smartrag/blob/main/frontend/src/components/UploadSection.js"
    click Routes "https://github.com/aymenfurter/smartrag/blob/main/app/api/routes.py"
    click Server "https://github.com/aymenfurter/smartrag/blob/main/main.py"
    click PDF "https://github.com/aymenfurter/smartrag/blob/main/app/ingestion/pdf_processing.py"
    click DocInt "https://github.com/aymenfurter/smartrag/blob/main/app/ingestion/doc_intelligence.py"
    click TablePost "https://github.com/aymenfurter/smartrag/blob/main/app/ingestion/table_postprocessor.py"
    click IndexQ "https://github.com/aymenfurter/smartrag/blob/main/app/ingestion/indexing_queue.py"
    click UploadQ "https://github.com/aymenfurter/smartrag/blob/main/app/ingestion/upload_queue.py"
    click GraphRAG "https://github.com/aymenfurter/smartrag/blob/main/app/query/graphrag_query.py"
    click ChatSvc "https://github.com/aymenfurter/smartrag/blob/main/app/query/chat_service.py"
    click VoiceSvc "https://github.com/aymenfurter/smartrag/blob/main/app/query/voice_chat_service.py"
    click ResearchSvc "https://github.com/aymenfurter/smartrag/blob/main/app/query/research.py"
    click Search "https://github.com/aymenfurter/smartrag/blob/main/app/integration/azure_aisearch.py"
    click OpenAI "https://github.com/aymenfurter/smartrag/blob/main/app/integration/azure_openai.py"
    click Blob "https://github.com/aymenfurter/smartrag/blob/main/app/integration/blob_service.py"
    click IndexMgr "https://github.com/aymenfurter/smartrag/blob/main/app/integration/index_manager.py"
    click CompSvc "https://github.com/aymenfurter/smartrag/blob/main/app/compare/comparison_service.py"
    click CompExec "https://github.com/aymenfurter/smartrag/blob/main/app/compare/comparison_executor.py"
    click RespProc "https://github.com/aymenfurter/smartrag/blob/main/app/compare/response_processor.py"
    click CogSvc "https://github.com/aymenfurter/smartrag/blob/main/infra/core/ai/cognitiveservices.bicep"
    click SearchSvc "https://github.com/aymenfurter/smartrag/blob/main/infra/core/search/search-services.bicep"
    click Storage "https://github.com/aymenfurter/smartrag/blob/main/infra/core/storage/storage-account.bicep"
    click Container "https://github.com/aymenfurter/smartrag/blob/main/infra/core/host/container-apps.bicep"
    click UploadProc "https://github.com/aymenfurter/smartrag/blob/main/upload_queue_processor.py"
    click IndexProc "https://github.com/aymenfurter/smartrag/blob/main/indexing_queue_processor.py"

    %% Styles
    classDef frontend fill:#90EE90
    classDef backend fill:#ADD8E6
    classDef service fill:#98FB98
    classDef queue fill:#DDA0DD
    classDef integration fill:#F0E68C
    classDef azure fill:#87CEEB

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Component"]:::backend
        Service["Service Component"]:::service
        Queue["Queue Component"]:::queue
        Int["Integration Component"]:::integration
        AzureService["Azure Service"]:::azure
    end
```
