# azure-samples/azure-search-openai-javascript architecture

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

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

## Overview

The system architecture should be represented in multiple layers, focusing on these key components:

##### Frontend Layer
- React/Lit-based webapp package with its key components:
- Chat interface
- Q&A interface
- Settings management
- Supporting content display

##### Application Layer
- Static Web App hosting the frontend
- Two Container Apps hosting the backend services:
- Search Service (packages/search)
- Indexer Service (packages/indexer)

##### Core Services Layer
- Azure OpenAI Service:
- ChatGPT model (gpt-35-turbo)
- Embedding model for vector search
- Azure AI Search:
- Search indexes
- Vector search capabilities
- Azure Blob Storage for document storage

##### Monitoring & Security Layer
- Application Insights for telemetry
- Azure Monitor for logging
- Azure Active Directory (optional) for authentication

##### Component Representation
- Use rectangles for services and applications
- Use hexagons for Azure PaaS services
- Use clouds for external services/APIs

##### Connection Flows
- Blue: User requests
- Green: Document processing
- Orange: Search operations
- Purple: AI operations

##### Key Processes to Highlight

a. Document Processing Flow:
**Documents → Indexer Service → Azure AI Search**
- ↓
- Azure OpenAI (embeddings)

b. Chat/Query Flow:
**User → Frontend → Search Service → Azure AI Search**
- ↓
- Azure OpenAI (ChatGPT)
- ↓
- Response

##### Additional Elements

- Version/environment information
- Security boundaries and authentication flows
- Scaling capabilities of container apps

##### Architectural Patterns to Emphasize

- Retrieval Augmented Generation (RAG) pattern
- Microservices architecture
- Event-driven processing
- Stateless design

Important Implementation Details to Note:

##### Container Apps
- Autoscaling configuration (1-10 replicas)
- Resource allocation (1 vCPU, 2GB RAM)

##### Search Service
- Semantic search capabilities
- Vector search integration

##### Security
- CORS boundaries
- Authentication flows (if enabled)
- Network security measures

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]
        WebApp["Web Application"]:::frontend
        Chat["Chat Interface"]:::frontend
        QA["Q&A Interface"]:::frontend
        Settings["Settings"]:::frontend
        Support["Supporting Content"]:::frontend
    end

    subgraph "Application Layer"
        StaticWebApp["Static Web App"]:::hosting
        SearchService["Search Service"]:::service
        IndexerService["Indexer Service"]:::service
    end

    subgraph "Core Services"
        OpenAI["Azure OpenAI Service"]:::azure
        AISearch["Azure AI Search"]:::azure
        BlobStorage["Azure Blob Storage"]:::storage
    end

    subgraph "Monitoring & Security"
        AppInsights["Application Insights"]:::monitoring
        AzureMonitor["Azure Monitor"]:::monitoring
        AAD["Azure AD"]:::security
    end

    %% Client Layer Connections
    Browser --> WebApp
    WebApp --> Chat
    WebApp --> QA
    WebApp --> Settings
    WebApp --> Support

    %% Application Layer Connections
    WebApp --> StaticWebApp
    StaticWebApp --> SearchService
    StaticWebApp --> IndexerService

    %% Core Services Connections
    SearchService --> OpenAI
    SearchService --> AISearch
    IndexerService --> OpenAI
    IndexerService --> AISearch
    IndexerService --> BlobStorage

    %% Monitoring Connections
    SearchService -.-> AppInsights
    IndexerService -.-> AppInsights
    StaticWebApp -.-> AppInsights
    AppInsights --> AzureMonitor

    %% Security Connections
    Browser -.-> AAD
    SearchService -.-> AAD
    IndexerService -.-> AAD

    %% Click Events
    click WebApp "https://github.com/azure-samples/azure-search-openai-javascript/tree/main/packages/webapp"
    click Chat "https://github.com/azure-samples/azure-search-openai-javascript/tree/main/packages/chat-component"
    click Settings "https://github.com/azure-samples/azure-search-openai-javascript/tree/main/packages/webapp/src/components/SettingsButton"
    click Support "https://github.com/azure-samples/azure-search-openai-javascript/tree/main/packages/webapp/src/components/SupportingContent"
    click SearchService "https://github.com/azure-samples/azure-search-openai-javascript/tree/main/packages/search"
    click IndexerService "https://github.com/azure-samples/azure-search-openai-javascript/tree/main/packages/indexer"
    click OpenAI "https://github.com/azure-samples/azure-search-openai-javascript/blob/main/packages/search/src/plugins/openai.ts"
    click AISearch "https://github.com/azure-samples/azure-search-openai-javascript/blob/main/infra/core/search/search-services.bicep"
    click AppInsights "https://github.com/azure-samples/azure-search-openai-javascript/tree/main/infra/core/monitor"
    click AAD "https://github.com/azure-samples/azure-search-openai-javascript/tree/main/infra/core/security"
    click StaticWebApp "https://github.com/azure-samples/azure-search-openai-javascript/blob/main/infra/core/host/staticwebapp.bicep"
    click BlobStorage "https://github.com/azure-samples/azure-search-openai-javascript/blob/main/infra/core/storage/storage-account.bicep"

    %% Styling
    classDef frontend fill:#42b883,color:white
    classDef hosting fill:#2496ed,color:white
    classDef service fill:#1e88e5,color:white
    classDef azure fill:#0078d4,color:white
    classDef storage fill:#ffd700,color:black
    classDef monitoring fill:#ff7043,color:white
    classDef security fill:#7b1fa2,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        HostingService["Hosting Service"]:::hosting
        AppService["Application Service"]:::service
        AzureService["Azure Service"]:::azure
        StorageService["Storage Service"]:::storage
        MonitoringService["Monitoring Service"]:::monitoring
        SecurityService["Security Service"]:::security
    end
```
