# codium-ai/pr-agent architecture

> Architecture diagram of the GitHub repository codium-ai/pr-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/codium-ai/pr-agent
- Repository: https://github.com/codium-ai/pr-agent

## Overview

##### Main System Components

a) Core Components:
- PR Agent Core (pr_agent/agent)
- AI Handlers Layer (pr_agent/algo/ai_handlers)
- Git Providers Layer (pr_agent/git_providers)
- Tools Layer (pr_agent/tools)
- Configuration System (pr_agent/settings)

b) Server Components:
- Multiple Server Implementations (pr_agent/servers)
- Identity Providers (pr_agent/identity_providers)
- Secret Providers (pr_agent/secret_providers)

##### Component Relationships

**[Git Platforms] <---> [Server Layer] <---> [PR Agent Core] <---> [AI Handlers]**

- v
- [Tools Layer]

- v
- [Configuration System]

##### Detailed Component Breakdown

a) Git Platform Integration Layer:
- Supported platforms: GitHub, GitLab, Bitbucket, Azure DevOps
- Connection methods: webhooks, apps, actions

b) Server Layer:
- Different server types: GitHub App, GitLab Webhook, etc.
- Authentication flow with identity providers

c) Core Processing:
- PR processing flow
- Token handling and compression strategy
- Patch processing system

d) Tools System:
- Tools by category (Review, Describe, Improve, etc.)
- Tool dependencies and interactions

e) AI Integration:
- Supported AI models
- Prompt handling and response processing

##### Additional Elements

Include:
- Version information
- Integration points for Pro features (marked with 💎)
- System requirements and dependencies
- Data flow direction indicators

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph GitPlatforms["Git Platforms"]
        direction TB
        GitHub["GitHub"]:::git
        GitLab["GitLab"]:::git
        Bitbucket["Bitbucket"]:::git
        Azure["Azure DevOps"]:::git
    end

    subgraph ServerLayer["Server Layer"]
        direction TB
        GHApp["GitHub App"]:::server
        GLWebhook["GitLab Webhook"]:::server
        BBApp["Bitbucket App"]:::server
        
        subgraph IdentityProviders["Identity Providers"]
            BaseIdentity["Base Identity Provider"]:::identity
            DefaultIdentity["Default Identity Provider"]:::identity
        end
        
        subgraph SecretProviders["Secret Providers"]
            BaseSecret["Base Secret Provider"]:::secret
            GCloudSecret["Google Cloud Storage"]:::secret
        end
    end

    subgraph CoreLayer["Core Layer"]
        PRAgent["PR Agent Core"]:::core
    end

    subgraph AILayer["AI Handlers Layer"]
        direction TB
        BaseAI["Base AI Handler"]:::ai
        OpenAI["OpenAI Handler"]:::ai
        LangChain["LangChain Handler"]:::ai
    end

    subgraph ToolsLayer["Tools Layer"]
        direction TB
        Review["PR Reviewer"]:::tool
        Describe["PR Description"]:::tool
        Improve["PR Code Suggestions"]:::tool
        Docs["PR Documentation"]:::tool
    end

    subgraph ConfigSystem["Configuration System"]
        direction TB
        MainConfig["Main Configuration"]:::config
        Prompts["PR Reviewer Prompts"]:::config
    end

    GitPlatforms --> ServerLayer
    ServerLayer --> CoreLayer
    CoreLayer --> AILayer
    CoreLayer --> ToolsLayer
    ToolsLayer --> ConfigSystem

    %% Click events for components
    click PRAgent "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/agent/pr_agent.py"
    click BaseAI "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/algo/ai_handlers/base_ai_handler.py"
    click OpenAI "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/algo/ai_handlers/openai_ai_handler.py"
    click LangChain "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/algo/ai_handlers/langchain_ai_handler.py"
    click GitHub "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/git_providers/github_provider.py"
    click GitLab "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/git_providers/gitlab_provider.py"
    click Bitbucket "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/git_providers/bitbucket_provider.py"
    click Azure "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/git_providers/azuredevops_provider.py"
    click Review "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/tools/pr_reviewer.py"
    click Describe "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/tools/pr_description.py"
    click Improve "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/tools/pr_code_suggestions.py"
    click Docs "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/tools/pr_add_docs.py"
    click MainConfig "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml"
    click Prompts "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/pr_reviewer_prompts.toml"
    click GHApp "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/servers/github_app.py"
    click GLWebhook "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/servers/gitlab_webhook.py"
    click BBApp "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/servers/bitbucket_app.py"
    click BaseIdentity "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/identity_providers/identity_provider.py"
    click DefaultIdentity "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/identity_providers/default_identity_provider.py"
    click BaseSecret "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/secret_providers/secret_provider.py"
    click GCloudSecret "https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/secret_providers/google_cloud_storage_secret_provider.py"

    classDef git fill:#90EE90,stroke:#333,stroke-width:2px
    classDef server fill:#ADD8E6,stroke:#333,stroke-width:2px
    classDef identity fill:#FFB6C1,stroke:#333,stroke-width:2px
    classDef secret fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef core fill:#4169E1,stroke:#333,stroke-width:2px
    classDef ai fill:#FFD700,stroke:#333,stroke-width:2px
    classDef tool fill:#9370DB,stroke:#333,stroke-width:2px
    classDef config fill:#A9A9A9,stroke:#333,stroke-width:2px
```
