# azure-samples/azure-search-openai-demo-csharp architecture

> Architecture diagram of the GitHub repository azure-samples/azure-search-openai-demo-csharp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/azure-samples/azure-search-openai-demo-csharp
- Repository: https://github.com/azure-samples/azure-search-openai-demo-csharp

## Overview

##### Project type and purpose
- This is a full-stack .NET sample application demonstrating a Retrieval-Augmented Generation (RAG) pattern over enterprise data using Azure AI services.
- It includes a Blazor WebAssembly frontend, an ASP.NET Core Minimal API backend, Azure Functions for embedding, a .NET MAUI hybrid client, and Bicep-based IaC to deploy Azure resources (Container Apps, Cognitive Search, OpenAI, Blob Storage, Application Insights, etc.).

##### File structure
- Top-level subdivisions under `app/`:
- `frontend` – Blazor WebAssembly client (static SPA)
- `backend` – ASP.NET Core Minimal API orchestrator & static host
- `functions/EmbedFunctions` – Azure Function to produce vector embeddings
- `SharedWebComponents` – Razor component library shared between WebAssembly and MAUI
- `maui-blazor` – .NET MAUI hybrid app reusing Blazor components
- `prepdocs` – CLI tool to preprocess and chunk PDF documents before indexing
- `shared` – Shared DTOs and interfaces for search, embedding, vision, and OCR services
- `tests` – Unit and component tests for frontend parser logic and backend services
- Infrastructure folder `infra/` contains Bicep templates grouping core (storage, search, key vault), host (container apps, registry, functions), AI (cognitive services), monitoring and security.

##### README for architecture insights
- User clients (Web, MAUI) → Minimal API → Azure AI Search & OpenAI → returns responses
- Document ingestion pipeline: Blob Storage → Azure Functions (embedding) → Cognitive Search index
- Optional vision/OCR pipeline via Azure Computer Vision
- The flow orchestration is handled by ASP.NET Minimal API using Azure SDK and Semantic Kernel.

##### Essential elements to capture
- Clear component names (e.g., “Minimal API Container App”, “Embed Function App”)
- Data flow order (user query → retriever → generator → response)
- Ingestion pipeline (doc prep → embedding → index)
- External dependencies (Azure services)
- Infrastructure boundary and deployment artifacts (Bicep)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        FE["Blazor WebAssembly (SPA)"]:::frontend
        MAUI[".NET MAUI Hybrid Client"]:::mobile
    end

    %% Orchestration Layer
    subgraph "API Orchestration"
        direction TB
        API["ASP.NET Core Minimal API Container App"]:::api
        SWC["Shared Razor Components Library"]:::shared
        SHARED["Shared DTOs & Interfaces"]:::shared
    end

    %% Ingestion Layer
    subgraph "Ingestion & Embeddings"
        direction TB
        CLI["Document Prep CLI Tool"]:::api
        FUNC["Azure Function Embed Service"]:::func
    end

    %% Azure PaaS Resources
    subgraph "Azure Services"
        direction TB
        BLOB["Azure Blob Storage"]:::azure
        SEARCH["Azure Cognitive Search"]:::azure
        OPENAI["Azure OpenAI Service"]:::azure
        VISION["Azure Computer Vision"]:::azure
        KV["Azure Key Vault"]:::azure
        AI["Application Insights"]:::azure
    end

    %% Infrastructure as Code
    subgraph "Infrastructure as Code (Bicep)"
        direction TB
        INFRA["Bicep Templates"]:::infra
    end

    %% Connections
    FE -->|HTTP| API
    MAUI -->|HTTP| API
    API -->|"Azure SDK"| SEARCH
    API -->|"REST"| OPENAI
    API -->|"REST"| VISION
    API -->|"SDK"| KV
    API -->|"Telemetry"| AI

    CLI -->|Uploads PDFs| BLOB
    BLOB -->|Trigger| FUNC
    FUNC -->|"Index Embeddings"| SEARCH

    INFRA -->|Deploys| API
    INFRA -->|Deploys| FUNC
    INFRA -->|Provision| BLOB
    INFRA -->|Provision| SEARCH
    INFRA -->|Provision| OPENAI
    INFRA -->|Provision| VISION
    INFRA -->|Provision| KV
    INFRA -->|Provision| AI

    %% Click Events
    click FE "https://github.com/azure-samples/azure-search-openai-demo-csharp/tree/main/app/frontend"
    click MAUI "https://github.com/azure-samples/azure-search-openai-demo-csharp/tree/main/app/maui-blazor"
    click API "https://github.com/azure-samples/azure-search-openai-demo-csharp/tree/main/app/backend"
    click FUNC "https://github.com/azure-samples/azure-search-openai-demo-csharp/tree/main/app/functions/EmbedFunctions"
    click CLI "https://github.com/azure-samples/azure-search-openai-demo-csharp/tree/main/app/prepdocs/PrepareDocs"
    click SWC "https://github.com/azure-samples/azure-search-openai-demo-csharp/tree/main/app/SharedWebComponents"
    click SHARED "https://github.com/azure-samples/azure-search-openai-demo-csharp/tree/main/app/shared/Shared"
    click INFRA "https://github.com/azure-samples/azure-search-openai-demo-csharp/tree/main/infra/"

    %% Styles
    classDef frontend fill:#f4cccc,stroke:#c00,color:#000
    classDef mobile fill:#c9daf8,stroke:#06c,color:#000
    classDef api fill:#d9ead3,stroke:#090,color:#000
    classDef func fill:#ead1dc,stroke:#c00,color:#000
    classDef shared fill:#fff2cc,stroke:#c60,color:#000
    classDef azure fill:#d0e0e3,stroke:#076,color:#000
    classDef infra fill:#cccccc,stroke:#666,color:#000
```
