# microsoft/azuretre architecture

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

- Interactive diagram: https://gitdiagram.com/microsoft/azuretre
- Repository: https://github.com/microsoft/azuretre

## Overview

##### Project type and purpose
- This is a full-stack, cloud-native accelerator (Azure TRE) combining infrastructure-as-code (Terraform), microservices (API, functions, processors), client applications (web UI, CLI), and DevOps pipelines. Its goal is to enable self-service provisioning of secure research workspaces on Azure, with extensible “shared services,” workspace templates, airlock import/export, cost reporting, and AAD integration.

##### File structure
- Top-level components:
- core/terraform & templates/…: Terraform modules for core resources, shared services, workspace services, workspace templates
- api_app: Python FastAPI-based REST API, DB repositories, Pydantic schemas, service bus and event grid integrations, tests
- airlock_processor: Azure Functions triggered by Blob, Queue, and Service Bus events for airlock import/export
- resource_processor: VMSS Porter Runner service handling Service Bus messages to provision resources
- cli: Python-based command-line interface that wraps API calls
- ui: React + TypeScript single-page app (Vite) calling the API
- devops & .github: CI/CD pipelines, GitHub Actions, DevOps/Terraform bootstrap scripts
- e2e_tests: pytest-based end-to-end tests against deployed endpoints
- docs: Architecture, usage guides, templates documentation

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        UI["React SPA"]:::client
        CLI["Python CLI"]:::client
    end

    %% API Layer
    subgraph "API Layer"
        API["FastAPI REST API"]:::api
        EGInt["Event Grid Integration"]:::api
        SBInt["Service Bus Integration"]:::api
    end

    %% Event / Messaging Layer
    subgraph "Event / Messaging Layer"
        SBTopic["Azure Service Bus"]:::message
        EGTopic["Azure Event Grid"]:::message
    end

    %% Function Layer
    subgraph "Function Layer"
        BlobFunction["Azure Function: BlobCreatedTrigger"]:::function
        StatusFunction["Azure Function: StatusChangedQueueTrigger"]:::function
        ScanFunction["Azure Function: ScanResultTrigger"]:::function
        DeleteFunction["Azure Function: DataDeletionTrigger"]:::function
    end

    %% Processor Layer
    subgraph "Processor Layer"
        ResourceProc["VMSS Porter Runner"]:::processor
    end

    %% Data Layer
    subgraph "Data Layer"
        CosmosDB["Azure Cosmos DB"]:::data
        BlobStorage["Azure Blob Storage"]:::data
    end

    %% Infrastructure (IaC)
    subgraph "Infrastructure (IaC)"
        Terraform["Terraform Modules"]:::infra
        TemplateModules["Workspace & Service Templates"]:::infra
    end

    %% DevOps Layer
    subgraph "DevOps"
        Pipelines["DevOps Pipelines & Scripts"]:::devops
    end

    %% Connections
    UI -->|"HTTPS/AAD"| API
    CLI -->|"HTTPS/AAD"| API
    API -->|"CRUD"| CosmosDB
    API -->|"send AMQP"| SBTopic
    API -->|"publish HTTP"| EGTopic
    SBTopic -->|"Service Bus Trigger"| ResourceProc
    ResourceProc -->|"update via API"| API
    BlobStorage -->|"BlobCreated"| BlobFunction
    BlobFunction -->|"calls API"| API
    SBTopic -->|"Queue Trigger"| StatusFunction
    StatusFunction -->|"update status"| API
    EGTopic -->|"Event Subscription"| ScanFunction
    EGTopic -->|"Event Subscription"| DeleteFunction
    Terraform -->|"provisions"| API
    Terraform -->|"provisions"| BlobFunction
    Terraform -->|"provisions"| ResourceProc
    Terraform -->|"provisions"| SBTopic
    Terraform -->|"provisions"| EGTopic
    Terraform -->|"provisions"| CosmosDB
    Terraform -->|"provisions"| BlobStorage
    Pipelines -->|"runs IaC & tests"| Terraform
    Pipelines -->|"runs tests"| e2eTests([End-to-End Tests]):::test

    %% Click Events
    click UI "https://github.com/microsoft/azuretre/tree/main/ui/app"
    click CLI "https://github.com/microsoft/azuretre/tree/main/cli/tre"
    click API "https://github.com/microsoft/azuretre/blob/main/api_app/main.py"
    click EGInt "https://github.com/microsoft/azuretre/blob/main/api_app/event_grid/event_sender.py"
    click SBInt "https://github.com/microsoft/azuretre/tree/main/api_app/service_bus/"
    click BlobFunction "https://github.com/microsoft/azuretre/tree/main/airlock_processor/BlobCreatedTrigger/"
    click StatusFunction "https://github.com/microsoft/azuretre/tree/main/airlock_processor/StatusChangedQueueTrigger/"
    click ScanFunction "https://github.com/microsoft/azuretre/tree/main/airlock_processor/ScanResultTrigger/"
    click DeleteFunction "https://github.com/microsoft/azuretre/tree/main/airlock_processor/DataDeletionTrigger/"
    click ResourceProc "https://github.com/microsoft/azuretre/blob/main/resource_processor/vmss_porter/runner.py"
    click Terraform "https://github.com/microsoft/azuretre/tree/main/core/terraform/"
    click TemplateModules "https://github.com/microsoft/azuretre/tree/main/templates/shared_services/"
    click Pipelines "https://github.com/microsoft/azuretre/tree/main/devops/scripts/"
    click e2eTests "https://github.com/microsoft/azuretre/tree/main/e2e_tests/"

    %% Styles
    classDef client fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef api fill:#DFFFE0,stroke:#28A745,color:#22863A
    classDef message fill:#F0E0FF,stroke:#6F42C1,color:#5A32A3
    classDef function fill:#FFEFD5,stroke:#D2691E,color:#A0522D
    classDef processor fill:#FFDAB9,stroke:#FF8C00,color:#D2691E
    classDef data fill:#F0F4C3,stroke:#A9A9A9,color:#6B6B47
    classDef infra fill:#EDEDED,stroke:#636363,color:#2E2E2E
    classDef devops fill:#FFF5B1,stroke:#DBAB09,color:#735C0F
    classDef test fill:#FCEAEA,stroke:#D73A49,color:#B31D28
```
