# langchain-ai/opengpts architecture

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

- Interactive diagram: https://gitdiagram.com/langchain-ai/opengpts
- Repository: https://github.com/langchain-ai/opengpts

## Overview

##### High-Level Architecture Components

The system should be represented as a microservices architecture with these main components:

a. Frontend Layer:
- React-based web application (TypeScript)
- Components for chat interface, configuration, and file uploads
- API integration layer

b. Backend Layer:
- FastAPI-based server
- Agent runtime system
- Authentication service
- Multiple cognitive architectures
- LLM integration layer
- Tools integration layer

c. Database Layer:
- PostgreSQL with pgvector extension
- Migrations system

##### Key Relationships to Highlight

- Frontend to Backend API communication
- Backend to Database interactions
- LLM service connections
- Tool integrations
- File storage flows

##### Cognitive Architecture Subsystems

Create three distinct sections showing the supported architectures:

a. Assistant Architecture:
- Tool selection loop
- LLM decision making process
- Action execution flow

b. RAGBot Architecture:
- Document retrieval flow
- Context integration
- Response generation

c. ChatBot Architecture:
- Simple LLM interaction flow
- System message handling

##### Integration Points

Connections to external services:
- LangChain
- LangGraph
- LangSmith
- Various LLM providers (OpenAI, Anthropic, Azure)
- Tool providers (Tavily, Kay.ai, etc.)

##### Specific Implementation Details

- Core services (blue)
- External integrations (green)
- Database components (yellow)
- Authentication flows (red)

##### Component Details

Frontend Components:
- Chat Interface
- Configuration Management
- File Upload System
- Message Management
- Tool Integration UI

Backend Components:
- API Layer
- Agent Types
- Authentication
- Message Handling
- Storage Management
- Tool Integration

##### Data Flow Patterns

Following flows:
- User request handling
- File upload and processing
- Chat message flow
- Tool execution flow
- Authentication flow

##### Deployment Architecture

Deployment options:
- Docker container structure
- Kubernetes deployment pattern
- Cloud Run deployment flow

- Rectangles for services
- Clouds for external services

- Top level: User interface
- Middle level: Application services
- Bottom level: Data storage and external services

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        CI["Chat Interface"]:::frontend
        CU["Configuration UI"]:::frontend
        FU["File Upload System"]:::frontend
        MM["Message Management"]:::frontend
        TI["Tool Integration UI"]:::frontend
        CS["Chat State"]:::frontend
        COS["Configuration State"]:::frontend
        TS["Tools State"]:::frontend
    end

    subgraph Backend
        FS["FastAPI Server"]:::backend
        AR["Agent Runtime"]:::backend
        AS["Authentication Service"]:::backend
        LI["LLM Integration"]:::backend
        TL["Tools Integration"]:::backend
        
        subgraph "API Layer"
            AA["Assistants API"]:::api
            TA["Threads API"]:::api
            RA["Runs API"]:::api
        end
        
        subgraph "Cognitive Architectures"
            AAR["Assistant Architecture"]:::cognitive
            CA["ChatBot Architecture"]:::cognitive
            RAG["RAG Components"]:::cognitive
        end
        
        FP["File Processing"]:::integration
        MP["Message Parsing"]:::integration
        SH["Stream Handling"]:::integration
        UM["Upload Management"]:::integration
    end

    subgraph "Database Layer"
        DB[(PostgreSQL)]:::database
        MIG["Migrations"]:::database
        SM["Storage Management"]:::database
    end

    subgraph "External Services"
        LC["LangChain"]:::external
        LG["LangGraph"]:::external
        LS["LangSmith"]:::external
        LLM["LLM Providers"]:::external
        TP["Tool Providers"]:::external
    end

    CI --> FS
    CU --> FS
    FU --> FS
    MM --> FS
    TI --> FS

    CS --> CI
    COS --> CU
    TS --> TI

    FS --> AR
    AR --> AS
    AR --> LI
    AR --> TL

    AA --> AR
    TA --> AR
    RA --> AR

    AAR --> LI
    CA --> LI
    RAG --> LI

    FP --> SM
    MP --> SH
    UM --> SM

    AR --> DB
    SM --> DB

    LI --> LLM
    TL --> TP
    AR --> LC
    AR --> LG
    AR --> LS

    classDef frontend fill:#e1f5fe,stroke:#01579b
    classDef backend fill:#e8f5e9,stroke:#1b5e20
    classDef api fill:#fff3e0,stroke:#e65100
    classDef cognitive fill:#f3e5f5,stroke:#4a148c
    classDef integration fill:#fce4ec,stroke:#880e4f
    classDef database fill:#fff8e1,stroke:#ff6f00
    classDef external fill:#f1f8e9,stroke:#33691e

    click CI "https://github.com/langchain-ai/opengpts/blob/main/frontend/src/components/Chat.tsx"
    click CU "https://github.com/langchain-ai/opengpts/blob/main/frontend/src/components/Config.tsx"
    click FU "https://github.com/langchain-ai/opengpts/blob/main/frontend/src/components/FileUpload.tsx"
    click MM "https://github.com/langchain-ai/opengpts/blob/main/frontend/src/components/Message.tsx"
    click TI "https://github.com/langchain-ai/opengpts/blob/main/frontend/src/components/Tool.tsx"
    click FS "https://github.com/langchain-ai/opengpts/blob/main/backend/app/server.py"
    click AR "https://github.com/langchain-ai/opengpts/blob/main/backend/app/agent.py"
    click AS "https://github.com/langchain-ai/opengpts/blob/main/backend/app/auth/handlers.py"
    click LI "https://github.com/langchain-ai/opengpts/blob/main/backend/app/llms.py"
    click TL "https://github.com/langchain-ai/opengpts/blob/main/backend/app/tools.py"
    click AAR "https://github.com/langchain-ai/opengpts/blob/main/backend/app/agent_types/tools_agent.py"
    click CA "https://github.com/langchain-ai/opengpts/blob/main/backend/app/chatbot.py"
    click RAG "https://github.com/langchain-ai/opengpts/blob/main/backend/app/retrieval.py"
    click AA "https://github.com/langchain-ai/opengpts/blob/main/backend/app/api/assistants.py"
    click TA "https://github.com/langchain-ai/opengpts/blob/main/backend/app/api/threads.py"
    click RA "https://github.com/langchain-ai/opengpts/blob/main/backend/app/api/runs.py"
    click MIG "https://github.com/langchain-ai/opengpts/blob/main/backend/migrations/000001_create_extensions_and_first_tables.up.sql"
    click SM "https://github.com/langchain-ai/opengpts/blob/main/backend/app/storage.py"
    click FP "https://github.com/langchain-ai/opengpts/blob/main/backend/app/ingest.py"
    click MP "https://github.com/langchain-ai/opengpts/blob/main/backend/app/parsing.py"
    click SH "https://github.com/langchain-ai/opengpts/blob/main/backend/app/stream.py"
    click UM "https://github.com/langchain-ai/opengpts/blob/main/backend/app/upload.py"
    click CS "https://github.com/langchain-ai/opengpts/blob/main/frontend/src/hooks/useChatMessages.ts"
    click COS "https://github.com/langchain-ai/opengpts/blob/main/frontend/src/hooks/useConfigList.ts"
    click TS "https://github.com/langchain-ai/opengpts/blob/main/frontend/src/hooks/useToolsSchemas.ts"
```
