# bmoussaud/azure-rambi architecture

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

- Interactive diagram: https://gitdiagram.com/bmoussaud/azure-rambi
- Repository: https://github.com/bmoussaud/azure-rambi

## Overview

##### Project Type & Purpose
- Azure Rambi is a cloud-native, microservices-based full-stack application for generating, storing, and browsing AI-generated movie data (titles, plots, posters, galleries).
- It leverages Azure Container Apps for service hosting, Azure API Management (APIM) as the gateway, multiple Azure PaaS services (OpenAI, DALL-E, Redis, Cosmos DB, Event Hubs, Blob Storage, Key Vault, App Insights), Dapr for local dev, and Bicep for infra as code.

##### Main Components
a. Frontend (gui-svc)
- Python Flask app, served from Azure Container Apps.
- Static pages call backend over APIM.
b. API Gateway (APIM)
- Ingests all client calls, applies policies (TMDB, OpenAI), routes to container apps.
c. Microservices (Azure Container Apps)
- movie-generator-svc (FastAPI): calls Azure OpenAI to generate new movie ideas, uses Redis for caching/state.
- movie-poster-svc: calls DALL-E/OpenAI for poster images, stores metadata in Blob Storage or Cosmos DB.
- movie-gallery-svc: retrieves stored movies/posters, exposes browsing API, persists data to Cosmos DB.
d. Azure PaaS Services
- OpenAI (GPT-4, O1-mini) & DALL-E for language/image generation.
- Redis Cache for session/state management.
- Cosmos DB for persisting movie metadata.
- Blob Storage for poster image storage.
- Event Hubs / Dapr pub-sub for event-driven updates (e.g., gallery updates).
- Key Vault for secrets.
- App Insights for monitoring/tracing.
e. Supporting Infrastructure
- Azure Container Registry (ACR) for Docker images.
- Bicep modules under infra/ to provision all Azure resources.
- GitHub Actions pipeline to build, push images, deploy infra and services.

##### Relationships & Data Flows
- User → GUI (HTTPS) → APIM
- APIM → Microservices (via HTTPS, with Dapr sidecar locally)
- movie-generator-svc → OpenAI → returns JSON movie data → may publish events to Event Hubs / Dapr pub-sub → movie-gallery-svc subscribes
- movie-poster-svc → DALL-E → stores image in Blob Storage → updates Cosmos DB
- movie-gallery-svc → Cosmos DB / Blob Storage (reads metadata & image URLs)
- Services → Redis for caching / state (via Dapr state store in dev)
- All services → App Insights for telemetry
- GitHub Actions → ACR (push) & Azure infra (Bicep deploy) & Container Apps (deploy)

##### Architectural Patterns & Principles
- Microservices: independently deployable services per business capability
- Containerization: Docker + Azure Container Apps
- API Gateway pattern: APIM fronting all services
- Event-driven: pub/sub via Dapr or Event Hubs for decoupling generator and gallery
- Infrastructure as Code: Bicep modules for repeatable provisioning
- Sidecar / Dapr: local development parity for state, pub/sub
- Separation of concerns: distinct UI, compute, storage, and AI layers

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation (Frontend)" 
        direction TB
        GUI["gui-svc (Flask)"]:::frontend
    end

    %% API Gateway Layer
    subgraph "API Gateway"
        direction TB
        APIM["APIM (Azure API Management)"]:::gateway
    end

    %% Compute / Microservices
    subgraph "Container Apps (Microservices)"
        direction TB
        MG["movie-generator-svc (FastAPI)"]:::service
        MP["movie-poster-svc"]:::service
        MGAL["movie-gallery-svc"]:::service
    end

    %% Data / AI Services
    subgraph "Azure PaaS Services"
        direction TB
        OA["OpenAI / DALL·E"]:::ai
        REDIS["Redis Cache"]:::data
        COS["Cosmos DB"]:::data
        BLOB["Blob Storage"]:::data
        EH["Event Hubs"]:::data
        KV["Key Vault"]:::data
        AI["App Insights"]:::infra
    end

    %% DevOps / Infra
    subgraph "DevOps & Infra"
        direction TB
        ACR["Azure Container Registry"]:::infra
        BICEP["Bicep IaC"]:::infra
        GHA["GitHub Actions"]:::infra
    end

    %% Local Development
    subgraph "Local Dev (Dapr)"
        direction TB
        DAPR["Dapr Sidecars"]:::dev
        DCOMP["Dapr Components"]:::dev
    end

    %% Connections
    GUI -->|HTTPS| APIM
    APIM -->|HTTPS| MG
    APIM -->|HTTPS| MP
    APIM -->|HTTPS| MGAL

    MG -->|Generate| OA
    MG -->|Redis State| REDIS
    MG -->|Pub/Sub| EH
    MG -->|Telemetry| AI

    MP -->|Generate Image| OA
    MP -->|Store Image| BLOB
    MP -->|Update Metadata| COS
    MP -->|Telemetry| AI

    MGAL -->|Read Metadata| COS
    MGAL -->|Read Images| BLOB
    MGAL -->|Subscribe| EH
    MGAL -->|Telemetry| AI

    MGAL -->|Cache| REDIS

    MG ---|Local Dev| DAPR
    MP ---|Local Dev| DAPR
    MGAL ---|Local Dev| DAPR
    MGAL ---|Local Dev| DCOMP
    MP ---|Local Dev| DCOMP
    MG ---|Local Dev| DCOMP

    GHA -->|Push Images| ACR
    GHA -->|Deploy| BICEP
    BICEP -->|Provision| ACR
    BICEP -->|Provision| APIM
    BICEP -->|Provision| MG
    BICEP -->|Provision| MP
    BICEP -->|Provision| MGAL
    BICEP -->|Provision| REDIS
    BICEP -->|Provision| EH
    BICEP -->|Provision| COS
    BICEP -->|Provision| BLOB
    BICEP -->|Provision| KV
    BICEP -->|Provision| AI

    %% Click Events
    click GUI "https://github.com/bmoussaud/azure-rambi/tree/main/src/gui_svc/"
    click APIM "https://github.com/bmoussaud/azure-rambi/tree/main/src/apim/"
    click MG "https://github.com/bmoussaud/azure-rambi/tree/main/src/movie_generator_svc/"
    click MP "https://github.com/bmoussaud/azure-rambi/tree/main/src/movie_poster_svc/"
    click MGAL "https://github.com/bmoussaud/azure-rambi/tree/main/src/movie_gallery_svc/"
    click BICEP "https://github.com/bmoussaud/azure-rambi/tree/main/infra/"
    click GHA "https://github.com/bmoussaud/azure-rambi/tree/main/.github/workflows/"
    click DAPR "https://github.com/bmoussaud/azure-rambi/blob/main/dapr.yaml"
    click DCOMP "https://github.com/bmoussaud/azure-rambi/blob/main/dapr/local/components/movie-gallery-svc.yaml"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#024B8A,stroke-width:2px
    classDef gateway fill:#A9C4E5,stroke:#113F67,stroke-width:2px
    classDef service fill:#C8FACC,stroke:#237A57,stroke-width:2px
    classDef ai fill:#FFD8A8,stroke:#C47E00,stroke-width:2px
    classDef data fill:#FFE4E6,stroke:#B02A37,stroke-width:2px
    classDef infra fill:#E2E8F0,stroke:#334155,stroke-width:2px
    classDef dev fill:#F5F3FF,stroke:#5B21B6,stroke-width:2px
```
