# microsoft/chat-copilot architecture

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

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

## Overview

##### Main Components

a. Frontend Layer:
- React Web Application (webapp/)
- Key frontend components:
- Chat Interface
- Authentication UI
- Plugin Management
- Document Management
- User Settings

b. Backend Layer:
- .NET Web API (webapi/)
- Authentication Service
- Chat Processing Service
- Plugin System
- Document Processing
- Storage Services

c. Memory Pipeline:
- Asynchronous Document Processing Service (memorypipeline/)
- Memory Management System

d. External Services:
- Azure OpenAI/OpenAI Integration
- Azure AD (optional)
- Microsoft Graph (optional)
- Azure Content Safety

##### Component Relationships

- Frontend → Backend API (HTTP/REST)
- Backend → LLM Services (Azure OpenAI/OpenAI)
- Backend → Memory Pipeline (Async Processing)
- Backend → Storage Systems
- Memory Pipeline → Storage Systems
- Authentication Flow (when enabled)

##### Detailed Component Breakdown

a. Frontend (Blue Section):

- React Frontend     |

- Chat Components     |
- Plugin Management   |
- Document Upload     |
- User Settings       |
- Authentication UI   |

b. Backend (Green Section):

- .NET Web API         |

- Chat Controllers     |
- Plugin System        |
- Document Processing  |
- Memory Management    |
- Authentication       |

c. Memory Pipeline (Yellow Section):

- Memory Pipeline      |

- Document Processing  |
- Memory Indexing      |
- Async Operations     |

##### External Services (Gray Section)

- External Services    |

- Azure OpenAI         |
- Azure AD             |
- MS Graph API         |
- Content Safety       |

##### Additional Elements

- Version information
- Scaling components
- Optional components (auth, plugins)
- Security boundaries

##### Implementation Notes

- API endpoints grouping
- Data persistence layers
- Real-time communication paths (SignalR)

Remember to include:
- Authentication flows
- Plugin system architecture
- Document processing pipeline
- Memory management system
- Storage systems
- External service integrations
- Real-time communication paths

This will provide a clear understanding of the system's architecture while maintaining the necessary detail level for implementation and maintenance.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        WebApp["React Web App"]
        ChatUI["Chat Interface"]:::component
        AuthUI["Authentication UI"]:::component
        PluginUI["Plugin Management"]:::component
        DocUI["Document Management"]:::component
        Settings["User Settings"]:::component
        
        WebApp --> ChatUI
        WebApp --> AuthUI
        WebApp --> PluginUI
        WebApp --> DocUI
        WebApp --> Settings
    end

    subgraph Backend
        API["ASP.NET Web API"]:::component
        AuthService["Authentication Service"]:::component
        ChatProc["Chat Processing"]:::component
        PluginSystem["Plugin System"]:::component
        DocProc["Document Processing"]:::component
        Storage["Storage Services"]:::component
        
        API --> AuthService
        API --> ChatProc
        API --> PluginSystem
        API --> DocProc
        API --> Storage
    end

    subgraph MemoryPipeline
        AsyncDoc["Async Document Processing"]:::component
        MemoryMgmt["Memory Management"]:::component
        
        AsyncDoc --> MemoryMgmt
    end

    subgraph ExternalServices
        AzureOpenAI["Azure OpenAI"]
        AzureAD["Azure AD"]
        MSGraph["Microsoft Graph"]
        ContentSafety["Azure Content Safety"]:::component
    end

    subgraph Storage
        CosmosDB["Cosmos DB"]:::component
        FileSystem["File System"]:::component
        ChatStore["Chat Storage"]:::component
    end

    %% Frontend to Backend
    WebApp --> API

    %% Backend to External Services
    API --> AzureOpenAI
    API --> AzureAD
    API --> MSGraph
    API --> ContentSafety

    %% Backend to Memory Pipeline
    API --> AsyncDoc
    MemoryMgmt --> Storage

    %% Storage Connections
    Storage --> CosmosDB
    Storage --> FileSystem
    Storage --> ChatStore

    %% Click Events
    click WebApp "https://github.com/microsoft/chat-copilot/tree/main/webapp/src/"
    click ChatUI "https://github.com/microsoft/chat-copilot/tree/main/webapp/src/components/chat/"
    click AuthUI "https://github.com/microsoft/chat-copilot/blob/main/webapp/src/components/views/Login.tsx"
    click PluginUI "https://github.com/microsoft/chat-copilot/tree/main/webapp/src/components/open-api-plugins/"
    click DocUI "https://github.com/microsoft/chat-copilot/blob/main/webapp/src/components/chat/tabs/DocumentsTab.tsx"
    click Settings "https://github.com/microsoft/chat-copilot/tree/main/webapp/src/components/header/settings-dialog/"
    click API "https://github.com/microsoft/chat-copilot/tree/main/webapi/"
    click AuthService "https://github.com/microsoft/chat-copilot/tree/main/webapi/Auth/"
    click ChatProc "https://github.com/microsoft/chat-copilot/blob/main/webapi/Controllers/ChatController.cs"
    click PluginSystem "https://github.com/microsoft/chat-copilot/tree/main/webapi/Plugins/"
    click DocProc "https://github.com/microsoft/chat-copilot/blob/main/webapi/Controllers/DocumentController.cs"
    click Storage "https://github.com/microsoft/chat-copilot/tree/main/webapi/Storage/"
    click AsyncDoc "https://github.com/microsoft/chat-copilot/blob/main/memorypipeline/Program.cs"
    click MemoryMgmt "https://github.com/microsoft/chat-copilot/blob/main/webapi/Plugins/Chat/SemanticChatMemory.cs"
    click ContentSafety "https://github.com/microsoft/chat-copilot/blob/main/webapi/Services/AzureContentSafety.cs"
    click MSGraph "https://github.com/microsoft/chat-copilot/blob/main/webapi/Plugins/Chat/MsGraphOboPlugin.cs"
    click CosmosDB "https://github.com/microsoft/chat-copilot/blob/main/webapi/Storage/CosmosDbContext.cs"
    click FileSystem "https://github.com/microsoft/chat-copilot/blob/main/webapi/Storage/FileSystemContext.cs"
    click ChatStore "https://github.com/microsoft/chat-copilot/blob/main/webapi/Storage/ChatMessageRepository.cs"

    %% Styling
    classDef component fill:#f9f,stroke:#333,stroke-width:2px
    classDef external fill:#gray,stroke:#333
    
    %% Legend
    subgraph Legend
        L1["Component"]:::component
        L2["External Service"]:::external
    end
```
