# microsoft/ai-red-teaming-playground-labs architecture

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

- Interactive diagram: https://gitdiagram.com/microsoft/ai-red-teaming-playground-labs
- Repository: https://github.com/microsoft/ai-red-teaming-playground-labs

## Overview

##### Project Type and Purpose
- This is a full-stack, multi‐service “playground” environment for AI Red Teaming labs.
- It uses Docker Compose (and optional Kubernetes manifests) to spin up a set of challenge microservices, a landing‐page front end, optional scoring and submission apps, plus a load‐balancer.
- The purpose is to host interactive AI security challenges against Chat Copilot instances, track flags via CTFd, and optionally score conversations and picture submissions.

##### Key Architectural Patterns
- Microservices: each challenge (“chat-copilot”, “picture-submission”, “chat-score”, “ctfd”, plus “challenge-home”) runs as an independent service/container.
- API‐driven front ends: single‐page React front ends talk to REST/WebSocket backends.
- Orchestration: Docker Compose for local development, Kubernetes manifests for production.
- External API integration: Azure OpenAI endpoints accessed via a reverse‐proxy load balancer.
- Optional “score” and “CTFd” services integrate via HTTP/flag‐submission APIs.

##### Main Components
- Frontends (React apps):
- challenge-home webapp (list of labs)
- chat-copilot webapp
- chat-score webapp
- picture-submission webapp
- Backends:
- challenge-home API (Python/Flask)
- chat-copilot WebAPI (ASP.NET Core C#; SignalR + REST controllers)
- chat-score WebAPI & worker (Python/FastAPI + background tasks)
- picture-submission API (Python/FastAPI)
- Supporting services:
- CTFd platform (Python/CTFd)
- Load balancer (Go reverse proxy with Azure OpenAI endpoint orchestration)
- Data stores:
- Cosmos DB (via chat-copilot’s CosmosDbContext)
- File system (fallback memory store, uploads)
- In‐memory/volatile contexts (for ephemeral lab state)
- External dependencies:
- Azure OpenAI endpoints (multiple)
- GitHub/Jira or other OpenAPI plugins
- Prometheus metrics, AppInsights telemetry

##### Interactions and Data Flow
- Users → challenge-home UI → challenge-home API → returns challenge metadata JSON.
- Users select a challenge → challenge-home UI loads corresponding chat-copilot or other service endpoint.
- chat-copilot UI → WebAPI (SignalR for chat, REST for metadata/plugins) → communicates with:
- Cognitive services (Azure OpenAI APIs via load balancer)
- Persistence (Cosmos DB, file system)
- Ctfd API (flag validation/submission)
- Semantic Kernel, plugins (HTTP, RCE, OpenAPI)
- Optionally, chat-score UI → chat-score API → WebSocket/SSE or polling for scoring queues → worker tasks evaluate transcripts.
- picture-submission UI → picture-submission API → stores images, invokes scoring (chat-score), submits flags.
- CTFd UI → users see flags/leaderboard; CTFd API is driven by automated challenge‐creation scripts.

##### Summary
- Break the system into Frontend UIs, Backend APIs, Data Stores, and External Dependencies.
- How the “challenge-home” directs users to individual challenge containers.
- Multi‐tenant nature of chat-copilot (one per challenge), the optional scoring/picture‐submission pipelines, and the centralized CTFd platform.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Users
    User["User"]:::external

    subgraph "Local Development (Docker Compose)" 
        direction TB

        subgraph "Frontend UIs"
            CHomeUI["challenge-home WebApp<br/>(React+TS)"]:::frontend
            CCopUI["chat-copilot WebApp<br/>(React+TS)"]:::frontend
            CScoreUI["chat-score WebApp<br/>(React+TS)"]:::frontend
            PSubUI["picture-submission WebApp<br/>(React+TS)"]:::frontend
        end

        subgraph "Backend APIs & Services"
            CHomeAPI["challenge-home API<br/>(Flask)"]:::backend
            CCopAPI["chat-copilot WebAPI<br/>(ASP.NET Core + SignalR)"]:::backend
            CScoreAPI["chat-score API<br/>(FastAPI)"]:::backend
            CScoreWorker["chat-score Worker<br/>(Background Tasks)"]:::backend
            PSubAPI["picture-submission API<br/>(FastAPI)"]:::backend
            CTFd["CTFd Platform"]:::backend
            LB["Load Balancer<br/>(Go Reverse Proxy)"]:::infra
        end

        subgraph "Data Stores"
            Cosmos["Cosmos DB"]:::datastore
            FileSys["File System / Volatile Store"]:::datastore
        end

        %% Frontend to Backend
        User -->|"HTTP/REST"| CHomeUI
        CHomeUI -->|"HTTP/REST"| CHomeAPI

        User -->|"HTTP/REST"| CCopUI
        CCopUI -->|"SignalR/WebSocket<br/>REST"| CCopAPI

        User -->|"HTTP/REST"| CScoreUI
        CScoreUI -->|"HTTP/REST / SSE"| CScoreAPI

        User -->|"HTTP/REST"| PSubUI
        PSubUI -->|"HTTP/REST"| PSubAPI

        %% Backend interactions
        CHomeAPI -->|"Docker Network"| LB
        CCopAPI -->|"Docker Network"| LB
        CCopAPI -->|"SDK/API"| Cosmos
        CCopAPI -->|"FS I/O"| FileSys
        CCopAPI -->|"HTTP/REST"| CTFd
        CCopAPI -->|"Plugin Calls"| HTTPPlugin
        CCopAPI -->|"Plugin Calls"| RCEPlugin

        CScoreAPI -->|"Queue"| CScoreWorker
        CScoreWorker -->|"DB/FS"| FileSys
        CScoreWorker -->|"HTTP/REST"| CTFd

        PSubAPI -->|"Store Images"| FileSys
        PSubAPI -->|"Trigger Scoring"| CScoreAPI
        PSubAPI -->|"Flag Submission"| CTFd

        %% Load Balancer to External AI
        LB -->|"HTTP/REST"| AzureAI["Azure OpenAI"]:::external

    end

    subgraph "Production (Kubernetes Cluster)"
        direction TB
        subgraph "Ingress & Services"
            KIngress["K8s Ingress"]:::infra
        end
        KIngress --> LB
    end

    %% Plugins as separate nodes
    HTTPPlugin["HTTP Plugin"]:::backend
    RCEPlugin["RCE Plugin"]:::backend

    %% External Services
    GitHub["GitHub/Jira Plugins"]:::external
    Prometheus["Prometheus Metrics"]:::external
    AppInsights["AppInsights Telemetry"]:::external

    %% External integrations
    CCopAPI -->|"OpenAPI Plugin"| GitHub
    CCopAPI -->|"Metrics"| Prometheus
    CCopAPI -->|"Telemetry"| AppInsights

    %% Click events
    click CHomeUI "https://github.com/microsoft/ai-red-teaming-playground-labs/tree/main/src/challenge-home/webapp"
    click CHomeAPI "https://github.com/microsoft/ai-red-teaming-playground-labs/blob/main/src/challenge-home/webapi/app.py"
    click CCopUI "https://github.com/microsoft/ai-red-teaming-playground-labs/tree/main/src/chat-copilot/webapp"
    click CCopAPI "https://github.com/microsoft/ai-red-teaming-playground-labs/tree/main/src/chat-copilot/webapi"
    click Cosmos "https://github.com/microsoft/ai-red-teaming-playground-labs/blob/main/src/chat-copilot/webapi/Storage/CosmosDbContext.cs"
    click FileSys "https://github.com/microsoft/ai-red-teaming-playground-labs/blob/main/src/chat-copilot/webapi/Storage/FileSystemContext.cs"
    click FileSys "https://github.com/microsoft/ai-red-teaming-playground-labs/blob/main/src/chat-copilot/webapi/Storage/VolatileContext.cs"
    click HTTPPlugin "https://github.com/microsoft/ai-red-teaming-playground-labs/tree/main/src/chat-copilot/plugins/http-plugin"
    click RCEPlugin "https://github.com/microsoft/ai-red-teaming-playground-labs/tree/main/src/chat-copilot/plugins/rce-plugin"
    click CScoreUI "https://github.com/microsoft/ai-red-teaming-playground-labs/tree/main/src/chat-score/webapp"
    click CScoreAPI "https://github.com/microsoft/ai-red-teaming-playground-labs/blob/main/src/chat-score/webapi/app.py"
    click CScoreWorker "https://github.com/microsoft/ai-red-teaming-playground-labs/tree/main/src/chat-score/webapi/worker"
    click PSubUI "https://github.com/microsoft/ai-red-teaming-playground-labs/tree/main/src/picture-submission/webapp"
    click PSubAPI "https://github.com/microsoft/ai-red-teaming-playground-labs/blob/main/src/picture-submission/webapi/app.py"
    click CTFd "https://github.com/microsoft/ai-red-teaming-playground-labs/tree/main/docker/ctfd/Dockerfile"
    click LB "https://github.com/microsoft/ai-red-teaming-playground-labs/tree/main/src/loadbalancer"
    click PSubAPI "https://github.com/microsoft/ai-red-teaming-playground-labs/blob/main/src/picture-submission/webapi/server/middleware/ctfd_auth.py"
    click PSubAPI "https://github.com/microsoft/ai-red-teaming-playground-labs/blob/main/src/picture-submission/webapi/server/middleware/ctfd_auth.py"
    click CTFd "https://github.com/microsoft/ai-red-teaming-playground-labs/blob/main/docker/ctfd/docker-compose-dev.yml"
    click KIngress "https://github.com/microsoft/ai-red-teaming-playground-labs/tree/main/k8s/conf/prod"

    %% Styles
    classDef frontend fill:#8ecae6,stroke:#023047,color:#000;
    classDef backend fill:#a8dadc,stroke:#065a60,color:#000;
    classDef datastore fill:#ffddd2,stroke:#9b2226,color:#000;
    classDef external fill:#ffd6a5,stroke:#bb3e03,color:#000;
    classDef infra fill:#cdb4db,stroke:#6a0dad,color:#000;
```
