Skip to content

Architecture

Media Studio API Architecture

Overview

Media Studio is a FastAPI-based unified API gateway that standardizes access to multiple third-party AI providers for image, video, audio, and text capabilities.

High-Level Architecture

flowchart LR
    classDef client fill:#FDE68A,stroke:#B45309,color:#78350F;
    classDef gateway fill:#DBEAFE,stroke:#2563EB,color:#1E3A8A;
    classDef domain fill:#E0E7FF,stroke:#4F46E5,color:#312E81;
    classDef provider fill:#DCFCE7,stroke:#16A34A,color:#14532D;
    classDef infra fill:#F3E8FF,stroke:#7C3AED,color:#4C1D95;

    client["Client Apps"]:::client --> gw["Media Studio API<br/>FastAPI Gateway"]:::gateway

    gw --> img["Image<br/>BRIA · Firefly · OpenAI · Imagen · Gemini"]:::domain
    gw --> vid["Video<br/>VEO · Runway · Firefly · HeyGen"]:::domain
    gw --> aud["Audio<br/>ElevenLabs · Lyria · Whisper · Azure AI"]:::domain
    gw --> txt["Text<br/>Captioning · Prompt Enhancement"]:::domain

    img --> p1["BRIA AI"]:::provider
    img --> p2["Adobe Firefly"]:::provider
    img --> p3["OpenAI"]:::provider
    img --> p4["Google Vertex AI"]:::provider
    vid --> p4
    vid --> p5["Runway"]:::provider
    vid --> p2
    vid --> p6["HeyGen"]:::provider
    aud --> p7["ElevenLabs"]:::provider
    aud --> p4
    aud --> p3
    aud --> p8["Azure AI Speech"]:::provider
    txt --> p3
    txt --> p4

    gw --> infra["Azure Infra<br/>Blob Storage · Key Vault · App Insights"]:::infra

Request Flow

sequenceDiagram
    participant Client
    participant API Gateway
    participant Router
    participant Service
    participant Provider
    participant Storage

    Client->>API Gateway: HTTP Request
    API Gateway->>API Gateway: Authenticate (X-API-Key)
    API Gateway->>API Gateway: RequestIDMiddleware
    API Gateway->>API Gateway: ModelExtractionMiddleware
    API Gateway->>Router: Route Request
    Router->>Service: Process Request
    Service->>Storage: Upload Input Media
    Service->>Provider: Call External API

    alt Async Processing
        Provider-->>Service: Job ID
        Service-->>Client: Return Job ID + Status URL
        Client->>API Gateway: Poll Status
        API Gateway->>Service: Get Result
        Service->>Provider: Check Status
        Provider-->>Service: Result
        Service->>Storage: Store Result
        Service-->>Client: Return Result URLs
    else Sync Processing
        Provider-->>Service: Result
        Service->>Storage: Store Result
        Service-->>Client: Return Result URLs
    end

Component Architecture

graph LR
    subgraph "API Layer"
        FastAPI[FastAPI App<br/>main.py]
        Middleware[Middleware<br/>RequestID, ModelExtraction]
        Routers[Route Handlers<br/>routers/]
        Deps[Dependency Injection<br/>dependencies.py]
    end

    subgraph "Service Layer"
        Providers[Provider Clients<br/>providers/]
        Models[Pydantic Models<br/>models/]
        Processing[Image Processing<br/>processing/]
    end

    subgraph "Infrastructure Layer"
        Settings[Settings<br/>Pydantic from env vars]
        Storage[Azure Blob Storage<br/>utils/azure_blob.py]
        GCS[GCS Uploader<br/>utils/gcs_upload.py]
        Monitoring[OpenTelemetry +<br/>App Insights]
    end

    FastAPI --> Middleware
    Middleware --> Routers
    Routers --> Deps
    Routers --> Providers
    Providers --> Models
    Providers --> Processing
    Providers --> Storage
    Providers --> GCS
    FastAPI --> Monitoring
    Settings --> Providers

Provider Capabilities

graph TD
    subgraph "BRIA"
        B1[Image Generation]
        B2[Background Removal]
        B3[Product Photography]
        B4[Image Editing]
        B5[Vector Generation]
        B6[Video Processing]
        B7[LoRA Custom Models]
    end

    subgraph "Google Vertex AI"
        G1[Imagen Generation]
        G2[VEO Video Generation]
        G3[Gemini Image Gen/Edit]
        G4[Image Editing & Expand]
        G5[Lyria Music Generation]
    end

    subgraph "OpenAI"
        O1[GPT Image Generation]
        O2[Image Editing]
        O3[Captioning]
        O4[Prompt Enhancement]
        O5[Whisper Transcription]
    end

    subgraph "Adobe Firefly"
        A1[Image Generation]
        A2[Video Generation]
        A3[Image Expand & Fill]
        A4[Object Composite]
    end

    subgraph "Runway"
        R1[Image Generation]
        R2[Text/Image to Video]
        R3[Video to Video]
        R4[Video Upscaling]
        R5[Motion / Act-Two]
    end

    subgraph "ElevenLabs"
        E1[Text-to-Speech]
        E2[Sound Effects]
        E3[Voice Design]
        E4[WebSocket Streaming]
    end

    subgraph "HeyGen"
        H1[Video Translation]
    end

    subgraph "Azure AI"
        AZ1[Speech Transcription]
    end

Deployment Architecture

graph TB
    subgraph "Azure Infrastructure"
        subgraph "Compute"
            ASP[App Service Plan<br/>Linux]
            WA[Web App<br/>Docker Container]
            SLOTS[Deployment Slots<br/>dev / test / stage]
        end

        subgraph "Storage"
            ACR[Container Registry]
            BLOB[Blob Storage<br/>Media Files]
        end

        subgraph "Security"
            KV[Key Vault<br/>API Keys & Secrets]
            MI[Managed Identity]
        end

        subgraph "Monitoring"
            AI[Application Insights]
            OTEL[OpenTelemetry<br/>Tracing & Metrics]
            LA[Log Analytics]
        end
    end

    subgraph "CI/CD"
        GH[GitHub Actions]
    end

    GH --> ACR
    ACR --> WA
    ASP --> WA
    WA --> SLOTS

    WA --> BLOB
    WA --> KV
    WA --> AI

    MI --> KV
    MI --> BLOB
    MI --> ACR

    AI --> LA
    OTEL --> AI