# azure-samples/contoso-creative-writer architecture

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

- Interactive diagram: https://gitdiagram.com/azure-samples/contoso-creative-writer
- Repository: https://github.com/azure-samples/contoso-creative-writer

## Overview

##### Main Components

a. Client Layer:
- React/TypeScript Web Application (src/web)
- Components for article display, debugging, and task management
- Redux store for state management

b. API Layer:
- FastAPI Backend (src/api)
- Agent Orchestrator
- Multiple AI Agents:
- Researcher Agent
- Product Agent
- Writer Agent
- Editor Agent

c. Azure Services:
- Azure OpenAI Service (GPT-4)
- Bing Search API
- Azure AI Search
- Azure Container Apps (hosting)
- Azure Monitor/Application Insights
- Azure Key Vault

##### User Interface → API Layer
- HTTP/REST communication
- Request/response flow for article generation

##### API Layer → Agents
- Orchestrator's control flow
- Sequential agent execution
- Data passing between agents

##### Agents → External Services
- Researcher → Bing Search API
- Product Agent → Azure AI Search
- All Agents → Azure OpenAI

##### Infrastructure Components
- Container Apps hosting both frontend and backend
- Key Vault securing credentials
- Application Insights for monitoring

##### Important Details to Highlight

a. Security Layer:
- Managed Identity connections
- Key Vault integration
- API security

b. Deployment Architecture:
- Container Apps environment
- Networking setup
- Service connections

c. Agent Workflow:
- Sequential processing
- Data transformation between agents
- Integration points

##### Infrastructure Layer

- Component types
- Security boundaries
- Service relationships

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Infrastructure Configuration Flow"
        Parameters["/infra/main.parameters.json"]:::config
        MainBicep["/infra/main.bicep"]:::config
        AzdConfig["/azure.yaml"]:::config
        
        Parameters --> MainBicep
        AzdConfig --> MainBicep
    end

    subgraph "Azure Resources"
        subgraph "Security Layer"
            KeyVault[Azure Key Vault]:::security
            ManagedId[Managed Identity]:::security
        end

        subgraph "Core Services"
            ContainerApps[Azure Container Apps]:::core
            CosmosDB[Azure Cosmos DB]:::core
            Monitor[Azure Monitor]:::core
            AppInsights[Application Insights]:::core
        end

        subgraph "AI Services Layer"
            OpenAI[Azure OpenAI]:::ai
            BingSearch[Azure Bing Search]:::ai
            AISearch[Azure AI Search]:::ai
        end
    end

    subgraph "Application Layer"
        subgraph "Frontend"
            WebApp[Web Application]:::app
        end

        subgraph "Backend"
            API[FastAPI Backend]:::app
            subgraph "Agent System"
                ResearchAgent[Research Agent]:::agent
                ProductAgent[Product Agent]:::agent
                WriterAgent[Writer Agent]:::agent
                EditorAgent[Editor Agent]:::agent
            end
        end
    end

    %% Infrastructure Configuration Relationships
    MainBicep --> ContainerApps
    MainBicep --> KeyVault
    MainBicep --> OpenAI
    MainBicep --> BingSearch
    MainBicep --> AISearch
    MainBicep --> CosmosDB
    MainBicep --> Monitor
    MainBicep --> AppInsights

    %% Security Relationships
    KeyVault --> ContainerApps
    ManagedId --> KeyVault
    ManagedId --> OpenAI
    ManagedId --> BingSearch
    ManagedId --> AISearch
    ManagedId --> CosmosDB

    %% Application Relationships
    ContainerApps --> WebApp
    ContainerApps --> API
    API --> ResearchAgent
    API --> ProductAgent
    API --> WriterAgent
    API --> EditorAgent

    %% Monitoring Relationships
    AppInsights --> WebApp
    AppInsights --> API
    Monitor --> AppInsights

    %% Agent Service Dependencies
    ResearchAgent --> OpenAI
    ResearchAgent --> BingSearch
    ProductAgent --> OpenAI
    ProductAgent --> AISearch
    WriterAgent --> OpenAI
    EditorAgent --> OpenAI

    %% Click Events
    click ContainerApps "https://github.com/Azure-Samples/contoso-creative-writer/blob/main/infra/core/host/container-apps.bicep"
    click OpenAI "https://github.com/Azure-Samples/contoso-creative-writer/blob/main/infra/core/ai/cognitiveservices.bicep"
    click BingSearch "https://github.com/Azure-Samples/contoso-creative-writer/blob/main/infra/core/bing/bing-search.bicep"
    click AISearch "https://github.com/Azure-Samples/contoso-creative-writer/blob/main/infra/core/search/search-services.bicep"
    click KeyVault "https://github.com/Azure-Samples/contoso-creative-writer/blob/main/infra/core/security/keyvault.bicep"
    click AppInsights "https://github.com/Azure-Samples/contoso-creative-writer/blob/main/infra/core/monitor/applicationinsights.bicep"
    click CosmosDB "https://github.com/Azure-Samples/contoso-creative-writer/blob/main/infra/core/database/cosmos/sql/cosmos-sql-account.bicep"
    click WebApp "https://github.com/Azure-Samples/contoso-creative-writer/tree/main/src/web"
    click API "https://github.com/Azure-Samples/contoso-creative-writer/tree/main/src/api"
    click ResearchAgent "https://github.com/Azure-Samples/contoso-creative-writer/tree/main/src/api/agents/researcher"
    click ProductAgent "https://github.com/Azure-Samples/contoso-creative-writer/tree/main/src/api/agents/product"
    click WriterAgent "https://github.com/Azure-Samples/contoso-creative-writer/tree/main/src/api/agents/writer"
    click EditorAgent "https://github.com/Azure-Samples/contoso-creative-writer/tree/main/src/api/agents/editor"
    click MainBicep "https://github.com/Azure-Samples/contoso-creative-writer/blob/main/infra/main.bicep"
    click Parameters "https://github.com/Azure-Samples/contoso-creative-writer/blob/main/infra/main.parameters.json"
    click AzdConfig "https://github.com/Azure-Samples/contoso-creative-writer/blob/main/azure.yaml"

    %% Styling
    classDef config fill:#f9f,stroke:#333,stroke-width:2px
    classDef security fill:#ff9,stroke:#333,stroke-width:2px
    classDef core fill:#9cf,stroke:#333,stroke-width:2px
    classDef ai fill:#c9f,stroke:#333,stroke-width:2px
    classDef app fill:#9fc,stroke:#333,stroke-width:2px
    classDef agent fill:#fcf,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[Configuration]:::config
        L2[Security]:::security
        L3[Core Services]:::core
        L4[AI Services]:::ai
        L5[Applications]:::app
        L6[Agents]:::agent
    end
```
