# azure-samples/openai-chat-vision-quickstart architecture

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

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

## Overview

##### Project’s Core Components
- Frontend Component: This is built with basic HTML/JavaScript and resides in the templates and static files within the src/quartapp folder. It handles user interactions including chat inputs and image uploads as well as integrating speech input and output.
- Backend Application: The core logic is implemented in Python using the Quart framework (an asynchronous alternative to Flask). The main backend code is in src/quartapp (with chat handling files like chat.py) and is containerized (with Dockerfile and related configuration files like gunicorn.conf.py).
- Infrastructure as Code: The infra directory contains many Bicep files, clearly outlining the provisioning of Azure resources such as Azure OpenAI, Azure Container Apps, Azure Container Registry, Log Analytics (monitoring), and RBAC configurations. This is key to understanding the deployment and environment setup.
- Deployment & CI/CD Pipeline: GitHub workflows in the .github/workflows directory, the azd (Azure Developer CLI) configuration, Docker and Dev Containers (via .devcontainer) setup the automated and containerized deployment pipeline.
- Additional Resources: Notebooks (for demo and testing) and tests (unit tests and snapshot tests) provide additional context that the project is built with testing and experimentation in mind.

##### Mapping Out Component Relationships
- Browser/Client (Frontend): Represent the static web application that interacts with the user.
- Azure Services: Create a grouped component representing the cloud environment, which includes:
– Azure Container Apps: Where the containerized backend is deployed.
– Container Apps Environment: The isolated context running the containers and linked to a container registry.
– Azure Container Registry: Where the container images are stored and retrieved.
– Azure OpenAI Service: The cognitive service (configured with Managed Identity) used by the backend to generate responses.
– Additional services such as Azure Log Analytics (for monitoring) and RBAC/security components provisioned via Bicep.
- Continuous Integration/Deployment Pipeline: Illustrate GitHub Actions workflows and the azd CLI used for deploying resources and code to Azure.

- That user interactions (chat messages, image uploads) flow from the Browser/Client to the Application Backend.
- That the backend communicates with Azure OpenAI to obtain GPT-4-generated responses.

##### Architectural Patterns and Design Principles
- Separation of concerns between the frontend (UI) and backend (logic/processing) which is typical in full-stack applications.
- Infrastructure-as-code approach where every Azure element is provisioned using Bicep scripts.
- Use of containerization (via Docker) and automated deployment pipelines (via azd and GitHub Actions) for a continuous deployment cycle.
- The design also leverages managed identity to enhance security when the backend interacts with Azure OpenAI.

##### Relevant Technologies and Frameworks
- Python (with Quart framework)
- JavaScript (for the frontend functionalities like speech input/output)
- Docker (containerizing the backend and application)
- Bicep (for provisioning Azure resources)
- Azure Container Apps & Azure OpenAI
- GitHub Actions for CI/CD and Azure Developer CLI (azd) for deployment

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        F["Browser/Client (HTML/JS)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        B["Application Backend (Python/Quart)"]:::backend
    end

    %% Azure Services
    subgraph "Azure Services"
        A1["Azure OpenAI Service"]:::azure
        A2["Azure Container Apps"]:::azure
        A3["Container Apps Environment"]:::azure
        A4["Azure Container Registry"]:::azure
        A5["Azure Log Analytics & RBAC"]:::azure
    end

    %% Deployment Pipeline
    subgraph "Deployment Pipeline"
        D1["GitHub Actions Workflows"]:::pipeline
        D2["Dev Containers & azd Deployment"]:::pipeline
    end

    %% Infrastructure as Code
    subgraph "Infrastructure as Code"
        I1["Bicep Scripts (Azure Provisioning)"]:::infra
    end

    %% Additional Resources
    subgraph "Additional Resources"
        R1["Notebooks"]:::additional
        R2["Tests"]:::additional
    end

    %% Connections
    F -->|"sends_chat/image"| B
    B -->|"calls_AzureOpenAI"| A1
    B -->|"deployed_to"| A2
    A2 -->|"runs_on"| A3
    D1 -->|"builds_container"| D2
    D2 -->|"deploys_container"| A4
    A4 -->|"feeds_container"| A2
    D1 -->|"updates"| B
    D1 -->|"triggers_infra"| I1
    I1 -->|"provisions"| A1
    I1 -->|"provisions"| A2
    I1 -->|"provisions"| A3
    I1 -->|"provisions"| A4
    I1 -->|"provisions"| A5
    R1 ---|"supplements"| B
    R2 ---|"validates"| B

    %% Styles
    classDef frontend fill:#f9f,stroke:#333,stroke-width:2px;
    classDef backend fill:#bbf,stroke:#333,stroke-width:2px;
    classDef azure fill:#9f6,stroke:#333,stroke-width:2px;
    classDef pipeline fill:#fea,stroke:#333,stroke-width:2px;
    classDef infra fill:#cfc,stroke:#333,stroke-width:2px;
    classDef additional fill:#ffc,stroke:#333,stroke-width:2px;

    %% Click Events for Frontend Component
    click F "https://github.com/azure-samples/openai-chat-vision-quickstart/tree/main/src/quartapp/templates"
    click F "https://github.com/azure-samples/openai-chat-vision-quickstart/tree/main/src/quartapp/static"

    %% Click Events for Backend Application
    click B "https://github.com/azure-samples/openai-chat-vision-quickstart/tree/main/src/quartapp"
    click B "https://github.com/azure-samples/openai-chat-vision-quickstart/blob/main/src/quartapp/chat.py"
    click B "https://github.com/azure-samples/openai-chat-vision-quickstart/tree/main/src/Dockerfile"
    click B "https://github.com/azure-samples/openai-chat-vision-quickstart/blob/main/src/gunicorn.conf.py"

    %% Click Events for Infrastructure as Code
    click I1 "https://github.com/azure-samples/openai-chat-vision-quickstart/tree/main/infra"
    click I1 "https://github.com/azure-samples/openai-chat-vision-quickstart/tree/main/infra/core/ai"
    click I1 "https://github.com/azure-samples/openai-chat-vision-quickstart/tree/main/infra/core/host"
    click I1 "https://github.com/azure-samples/openai-chat-vision-quickstart/tree/main/infra/core/monitor"
    click I1 "https://github.com/azure-samples/openai-chat-vision-quickstart/tree/main/infra/core/security"

    %% Click Events for Deployment Pipeline
    click D1 "https://github.com/azure-samples/openai-chat-vision-quickstart/tree/main/.github/workflows"
    click D1 "https://github.com/azure-samples/openai-chat-vision-quickstart/blob/main/.devcontainer"

    %% Click Events for Additional Resources
    click R1 "https://github.com/azure-samples/openai-chat-vision-quickstart/tree/main/notebooks"
    click R2 "https://github.com/azure-samples/openai-chat-vision-quickstart/tree/main/tests"
```
