# erikbjare/gptme architecture

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

- Interactive diagram: https://gitdiagram.com/erikbjare/gptme
- Repository: https://github.com/erikbjare/gptme

## Overview

##### Main Components

a) Core System Components:
- CLI Interface (Entry Point)
- LLM Provider Integration Layer
- Tool Management System
- Message/Chat Management
- Configuration System
- Web Server (Optional Component)

b) External Integrations:
- LLM Providers (OpenAI, Anthropic, OpenRouter)
- Browser Integration (Playwright)
- File System
- Shell Environment
- Vision Processing
- GitHub Integration

##### Component Relationships

**┌─ User Interface Layer ─────────────────────┐**
- CLI Interface                            │
- Web UI (Optional)                        │
- ┬────────────────────────┘
- ↓
**┌─ Core Service Layer ──────────────────────┐**
- Chat Manager                            │
- Tool Orchestrator                       │
- Configuration Manager                   │
- ┬────────────────────────┘
- ↓
**┌─ Tool Layer ──────────────────────────────┐**
- Shell   Python   Browser   Vision   Patch  │
- GitHub  RAG      TMux     Save     Read   │
- ┬────────────────────────┘
- ↓
**┌─ Integration Layer ─────────────────────────┐**
- LLM Providers (OpenAI, Anthropic, etc.)   │
- External Services (GitHub, Browser)        │
- ┘

##### Key Architectural Patterns to Highlight

a) Plugin Architecture:
- How the tool system is extensible
- Demonstrate tool registration and management

b) Message Flow:
- User input → CLI → Chat Manager → LLM → Tool Execution → Response

c) Configuration Management:
- How configuration flows through the system
- Environment variable handling

##### Specific Implementation Details

- Evaluation system architecture
- GitHub bot integration
- Demonstrate the computer use tool architecture
- Conversation persistence system

##### Component Details

CLI Interface:
**┌─ CLI (gptme/cli.py) ─────────┐**
- Command parsing            │
- Interactive mode           │
- Non-interactive mode       │
- Tool management           │
- ┬───────────────┘
- ↓
**┌─ Chat Manager (gptme/chat.py) ┐**
- Message handling            │
- Conversation management     │
- Tool coordination          │
- ┘

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef tool fill:#2ecc71,stroke:#27ae60,color:white
    classDef external fill:#e67e22,stroke:#d35400,color:white
    classDef optional fill:#9b59b6,stroke:#8e44ad,color:white
    classDef infra fill:#95a5a6,stroke:#7f8c8d,color:white

    %% User Interface Layer
    subgraph UI
        CLI["CLI Interface"]:::core
        WebUI["Web UI"]:::optional
    end

    %% Core Service Layer
    subgraph Core
        ChatMgr["Chat Manager"]:::core
        ToolOrch["Tool Orchestrator"]:::core
        ConfigMgr["Configuration Manager"]:::core
        MsgSystem["Message System"]:::core
        PromptMgr["Prompt Manager"]:::core
        LogSystem["Logging System"]:::core
        DirMgr["Directory Manager"]:::core
        Constants["Constants"]:::core
    end

    %% Tool Layer
    subgraph Tools
        direction TB
        ShellTool["Shell Tool"]:::tool
        PythonTool["Python Tool"]:::tool
        BrowserTool["Browser Tool"]:::tool
        VisionTool["Vision Tool"]:::tool
        PatchTool["Patch Tool"]:::tool
        GitHubTool["GitHub Tool"]:::tool
        RAGTool["RAG Tool"]:::tool
        TMuxTool["TMux Tool"]:::tool
    end

    %% Integration Layer
    subgraph Integrations
        direction TB
        LLMBase["LLM Base"]:::external
        OpenAI["OpenAI Integration"]:::external
        Anthropic["Anthropic Integration"]:::external
        EvalSystem["Evaluation System"]:::external
        Utils["Utility Layer"]:::infra
    end

    %% Relationships
    CLI --> ChatMgr
    CLI --> ConfigMgr
    WebUI --> ChatMgr
    ChatMgr --> ToolOrch
    ChatMgr --> MsgSystem
    ToolOrch --> Tools
    ConfigMgr --> Constants
    MsgSystem --> PromptMgr
    Tools --> LLMBase
    LLMBase --> OpenAI
    LLMBase --> Anthropic
    ChatMgr --> EvalSystem
    LogSystem --> Utils
    DirMgr --> Utils

    %% Click events for component mapping
    click CLI "https://github.com/ErikBjare/gptme/blob/master/gptme/cli.py"
    click ChatMgr "https://github.com/ErikBjare/gptme/blob/master/gptme/chat.py"
    click ConfigMgr "https://github.com/ErikBjare/gptme/blob/master/gptme/config.py"
    click WebUI "https://github.com/ErikBjare/gptme/tree/master/gptme/server/"
    click LLMBase "https://github.com/ErikBjare/gptme/tree/master/gptme/llm/"
    click OpenAI "https://github.com/ErikBjare/gptme/blob/master/gptme/llm/llm_openai.py"
    click Anthropic "https://github.com/ErikBjare/gptme/blob/master/gptme/llm/llm_anthropic.py"
    click ToolOrch "https://github.com/ErikBjare/gptme/blob/master/gptme/tools/base.py"
    click ShellTool "https://github.com/ErikBjare/gptme/blob/master/gptme/tools/shell.py"
    click PythonTool "https://github.com/ErikBjare/gptme/blob/master/gptme/tools/python.py"
    click BrowserTool "https://github.com/ErikBjare/gptme/blob/master/gptme/tools/browser.py"
    click VisionTool "https://github.com/ErikBjare/gptme/blob/master/gptme/tools/vision.py"
    click PatchTool "https://github.com/ErikBjare/gptme/blob/master/gptme/tools/patch.py"
    click GitHubTool "https://github.com/ErikBjare/gptme/blob/master/gptme/tools/gh.py"
    click RAGTool "https://github.com/ErikBjare/gptme/blob/master/gptme/tools/rag.py"
    click TMuxTool "https://github.com/ErikBjare/gptme/blob/master/gptme/tools/tmux.py"
    click MsgSystem "https://github.com/ErikBjare/gptme/blob/master/gptme/message.py"
    click EvalSystem "https://github.com/ErikBjare/gptme/tree/master/gptme/eval/"
    click Utils "https://github.com/ErikBjare/gptme/tree/master/gptme/util/"
    click PromptMgr "https://github.com/ErikBjare/gptme/blob/master/gptme/prompts.py"
    click Constants "https://github.com/ErikBjare/gptme/blob/master/gptme/constants.py"
    click DirMgr "https://github.com/ErikBjare/gptme/blob/master/gptme/dirs.py"
    click LogSystem "https://github.com/ErikBjare/gptme/blob/master/gptme/logmanager.py"
```
