# paulrobello/par_gpt architecture

> Architecture diagram of the GitHub repository paulrobello/par_gpt, 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/paulrobello/par_gpt
- Repository: https://github.com/paulrobello/par_gpt

## Overview

##### Main Components

a) Core Application Components:
- CLI Interface Layer
- Agent System
- AI Provider Interface
- Tool Management System
- Cache Management
- Voice/TTS Systems

b) External Services:
- AI Providers (OpenAI, Anthropic, Groq, Google, etc.)
- Search Services (Tavily, Google, Brave, etc.)
- Weather API
- GitHub API
- Other External APIs

c) Execution Environments:
- Local REPL Environment
- Docker Sandbox Environment

**User Interface Layer**
**↓**
**Core Processing Layer**
**↓**
**Service Integration Layer**
**↓**
**External Services Layer**

##### Specific Implementation Details

a) CLI Interface Layer:
- Command parser (Typer-based)
- Output formatter (Rich-based)
- Configuration manager

b) Core Processing Layer:
- Agent system (src/par_gpt/agents.py)
- Message handler (src/par_gpt/agent_messages.py)
- Cache manager (src/par_gpt/cache_manager.py)
- Voice/TTS managers (src/par_gpt/tts_manager.py, voice_input_manager.py)

c) Tool Integration Layer:
- AI Tools module (src/par_gpt/ai_tools/)
- Python REPL (src/par_gpt/ai_tools/par_python_repl.py)
- Repository manager (src/par_gpt/repo/)

d) Execution Environments:
- Local REPL environment
- Docker sandbox (sandbox/code_runner/)

##### Key Interactions to Highlight

- How user input flows from CLI through the system
- Demonstrate how the agent system interacts with various tools
- Security boundary between main application and sandbox
- Relationship between cache manager and external services

##### Notes for Implementation

- Keep the main flow clear and centered
- Related components together
- Use clear labels for all components
- Version information
- Notes about optional components

Remember to include a small overview section explaining the main data and control flows, and note any significant architectural decisions (like the separation between local REPL and sandboxed execution environments).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef ui fill:#FFE873,stroke:#333,stroke-width:2px
    classDef core fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef tool fill:#FFA500,stroke:#333,stroke-width:2px
    classDef security fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef external fill:#A9A9A9,stroke:#333,stroke-width:2px
    classDef ai fill:#90EE90,stroke:#333,stroke-width:2px

    %% User Interface Layer
    subgraph UI
        CLI["CLI Interface"]:::ui
        OutFormat["Output Formatter"]:::ui
        Config["Configuration Manager"]:::ui
    end

    %% Core Processing Layer
    subgraph Core
        Agent["Agent System"]:::core
        MsgHandler["Message Handler"]:::core
        Cache["Cache Manager"]:::core
        Voice["Voice/TTS Systems"]:::core
        Utils["Utility Functions"]:::core
    end

    %% Tool Integration Layer
    subgraph Tools
        ToolMgr["Tool Management"]:::tool
        PyREPL["Python REPL"]:::tool
        RepoMgr["Repository Manager"]:::tool
    end

    %% System Prompts
    subgraph Prompts
        MetaPrompt["Meta Prompt"]:::core
        BugAnalysis["Bug Analysis"]:::core
        BlogGen["Blog Generator"]:::core
    end

    %% Execution Environments
    subgraph Execution
        LocalREPL["Local REPL Environment"]:::security
        Docker["Docker Sandbox"]:::security
    end

    %% External Services
    subgraph External
        AIProviders["AI Providers\n(OpenAI/Anthropic/Groq/Google)"]:::ai
        SearchAPI["Search Services\n(Tavily/Google/Brave)"]:::external
        WeatherAPI["Weather API"]:::external
        GitHubAPI["GitHub API"]:::external
    end

    %% Relationships
    CLI --> Agent
    CLI --> Config
    CLI --> OutFormat
    Agent --> MsgHandler
    Agent --> Cache
    Agent --> Voice
    Agent --> ToolMgr
    ToolMgr --> PyREPL
    ToolMgr --> RepoMgr
    PyREPL --> LocalREPL
    PyREPL --> Docker
    Agent --> AIProviders
    ToolMgr --> SearchAPI
    ToolMgr --> WeatherAPI
    RepoMgr --> GitHubAPI
    Agent --> Prompts
    Utils --> Core

    %% Click Events
    click CLI "https://github.com/paulrobello/par_gpt/blob/main/src/par_gpt/__main__.py"
    click Agent "https://github.com/paulrobello/par_gpt/blob/main/src/par_gpt/agents.py"
    click MsgHandler "https://github.com/paulrobello/par_gpt/blob/main/src/par_gpt/agent_messages.py"
    click ToolMgr "https://github.com/paulrobello/par_gpt/blob/main/src/par_gpt/ai_tools/ai_tools.py"
    click Cache "https://github.com/paulrobello/par_gpt/blob/main/src/par_gpt/cache_manger.py"
    click Voice "https://github.com/paulrobello/par_gpt/blob/main/src/par_gpt/tts_manger.py"
    click PyREPL "https://github.com/paulrobello/par_gpt/blob/main/src/par_gpt/ai_tools/par_python_repl.py"
    click RepoMgr "https://github.com/paulrobello/par_gpt/blob/main/src/par_gpt/repo/repo.py"
    click Docker "https://github.com/paulrobello/par_gpt/tree/main/sandbox/code_runner/"
    click MetaPrompt "https://github.com/paulrobello/par_gpt/blob/main/src/par_gpt/prompts/meta_prompt.xml"
    click BugAnalysis "https://github.com/paulrobello/par_gpt/blob/main/src/par_gpt/prompts/prompt_bug_analysis.xml"
    click BlogGen "https://github.com/paulrobello/par_gpt/blob/main/src/par_gpt/prompts/blog_post_from_script_prompt.xml"
    click Utils "https://github.com/paulrobello/par_gpt/blob/main/src/par_gpt/utils.py"

    %% Legend
    subgraph Legend
        UI_L["User Interface"]:::ui
        Core_L["Core Component"]:::core
        Tool_L["Tool Component"]:::tool
        Security_L["Security Component"]:::security
        External_L["External Service"]:::external
        AI_L["AI Service"]:::ai
    end
```
