# azure-samples/openai architecture

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

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

## Overview

##### Project type and purpose
- This is a multi-module sample repository for Azure OpenAI Service, providing:
- Basic code snippets (Python, .NET, REST) demonstrating prompts, completions, embeddings, chat, DALL-E, Whisper, etc.
- End-to-end solutions (eCommerce demo, virtual assistant, call-center intelligence) combining UI, backend services, data stores, search, and AI models.
- Solution accelerators (Advanced RAG, Retail) showing full microservice architectures on Azure (AKS, App Service, Key Vault, Cosmos DB, AI Search).
- It’s not a single application but a collection of varied reference architectures.

##### High-level architecture patterns
- Each “solution” follows a full-stack, microservices-style pattern:
- Frontend: static SPA (React/Vite or ASP.NET Razor pages)
- Backend APIs: Python Flask/FastAPI or .NET Web API services for chat, ingestion, orchestrator, session manager
- Data layer: Azure Cosmos DB, Azure SQL, Azure Storage, vector stores (Qdrant, Milvus, Azure AI Search)
- AI layer: calls to Azure OpenAI Service (chat completions, embeddings, DALL-E, Whisper) and Azure Cognitive Services
- Infrastructure as code: Bicep ARM templates, Dockerfiles, Kubernetes manifests
- Common cross-cutting services: Key Vault (secrets), App Insights (logging), Managed Identity/Role-based security.

- User/client (web browser or notebook)
- Frontend UI (SPA or Razor web app)
- API Gateway / App Service front door (optional)
- Backend microservices grouped by function:
- Ingestion Service (data ingestion, document prep)
- Search Service (vector search, Azure AI Search)
- Orchestrator Service (prompt composition, multi-step workflows)
- Session Manager (chat session persistence, adaptive cards)
- Data stores:
- Cosmos DB or SQL DB for metadata, session logs
- Blob Storage for documents, embeddings files
- AI endpoints:
- Azure OpenAI Service (model endpoint)
- Azure Cognitive Services (speech-to-text, vision, filters)
- DevOps / Infra: Bicep modules for compute (AKS/App Service), database, search, key vault

##### Architectural patterns & principles
- Microservices—each domain (ingestion, search, orchestrator, session) is isolated
- Event-driven or request-response via REST APIs
- IaC—define infra components with Bicep and Kubernetes manifests
- Secure by design—Key Vault for secrets, managed identities, role assignments
- Scalability—AKS or App Service Plan for auto-scale

##### Final touches
- Security boundaries (public internet vs. private VNet)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Swimlanes
    subgraph "User"
        User["User/Client<br/>(Browser/Notebook)"]:::external
    end

    subgraph "Azure Subscription"
        Frontend["Frontend UI<br/>(React/Vite SPA)"]:::frontend
        API["API Gateway / App Service"]:::compute
        BackendAPI["Backend APIs<br/>(FastAPI)"]:::compute

        subgraph "Microservices"
            Ingest["Ingestion Service"]:::compute
            SearchSrv["Search Service"]:::compute
            Orchestrator["Orchestrator Service"]:::compute
            SessionMgr["Session Manager"]:::compute
        end

        subgraph "Data Stores"
            CosmosDB["Cosmos DB"]:::database
            BlobStorage["Blob Storage"]:::database
        end

        subgraph "AI Services"
            OpenAI["Azure OpenAI Service"]:::azure
            CogSvc["Azure Cognitive Services"]:::azure
        end

        subgraph "Infrastructure as Code"
            BicepInfra["Bicep IaC (Bicep templates)"]:::infra
            AppInsights["App Insights"]:::infra
            KeyVault["Key Vault"]:::infra
            AppServiceHost["App Service Host Config"]:::infra
            K8s["Kubernetes Deployment Manifest"]:::infra
        end
    end

    %% Relationships
    User -->|"HTTPS"| Frontend
    Frontend -->|"HTTPS"| API
    API -->|"REST"| BackendAPI

    BackendAPI -->|"Ingest"| Ingest
    BackendAPI -->|"Search"| SearchSrv
    BackendAPI -->|"Orchestrate"| Orchestrator
    BackendAPI -->|"Session"| SessionMgr

    Ingest -->|"Store Docs"| BlobStorage
    Ingest -->|"Metadata"| CosmosDB

    SearchSrv -->|"Query"| CosmosDB
    SearchSrv -->|"Retrieve"| BlobStorage

    Orchestrator -->|"Chat History"| CosmosDB
    Orchestrator -->|"Vector Search"| SearchSrv
    Orchestrator -->|"Model Call"| OpenAI
    Orchestrator -->|"Cognitive Call"| CogSvc

    SessionMgr -->|"Persist Sessions"| CosmosDB

    %% Monitoring & Logging
    BackendAPI -->|"Logs"| AppInsights
    Ingest -->|"Logs"| AppInsights
    SearchSrv -->|"Logs"| AppInsights
    Orchestrator -->|"Logs"| AppInsights
    SessionMgr -->|"Logs"| AppInsights

    %% Infra dependencies
    BicepInfra -.-> AppServiceHost
    BicepInfra -.-> KeyVault
    BicepInfra -.-> AppInsights
    BicepInfra -.-> CosmosDB
    BicepInfra -.-> BlobStorage
    BicepInfra -.-> API
    BicepInfra -.-> K8s

    %% Click Events
    click Frontend "https://github.com/azure-samples/openai/tree/main/End_to_end_Solutions/AOAISearchDemo/app/frontend"
    click BackendAPI "https://github.com/azure-samples/openai/blob/main/End_to_end_Solutions/AOAISearchDemo/app/backend/app.py"
    click Orchestrator "https://github.com/azure-samples/openai/blob/main/End_to_end_Solutions/AOAISearchDemo/app/backend/approaches/approach.py"
    click OpenAI "https://github.com/azure-samples/openai/blob/main/End_to_end_Solutions/AOAISearchDemo/app/backend/cognition/openai_client.py"
    click SearchSrv "https://github.com/azure-samples/openai/blob/main/End_to_end_Solutions/AOAISearchDemo/app/backend/data_client/data_client.py"
    click SessionMgr "https://github.com/azure-samples/openai/blob/main/End_to_end_Solutions/AOAISearchDemo/app/data/managers/chat_sessions/api/manager.py"
    click CosmosDB "https://github.com/azure-samples/openai/blob/main/End_to_end_Solutions/AOAISearchDemo/app/data/cosmosdb/container.py"
    click Ingest "https://github.com/azure-samples/openai/blob/main/End_to_end_Solutions/AOAISearchDemo/scripts/indexing/prepdocs.py"
    click BicepInfra "https://github.com/azure-samples/openai/blob/main/End_to_end_Solutions/AOAISearchDemo/infra/main.bicep"
    click AppInsights "https://github.com/azure-samples/openai/blob/main/End_to_end_Solutions/AOAISearchDemo/infra/core/logging/appinsights.bicep"
    click KeyVault "https://github.com/azure-samples/openai/blob/main/End_to_end_Solutions/AOAISearchDemo/infra/core/keyvault/keyvault.bicep"
    click AppServiceHost "https://github.com/azure-samples/openai/blob/main/End_to_end_Solutions/AOAISearchDemo/infra/core/host/appservice.bicep"
    click K8s "https://github.com/azure-samples/openai/blob/main/End_to_end_Solutions/AOAISearchDemo/app/backend/deployment.yaml"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef compute fill:#d4edda,stroke:#333,stroke-width:1px
    classDef database fill:#fff3cd,stroke:#333,stroke-width:1px
    classDef azure fill:#e2e3ff,stroke:#333,stroke-width:1px
    classDef infra fill:#f8d7da,stroke:#333,stroke-width:1px
    classDef external fill:#ffffff,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
```
