# wiljav/pr-agent architecture

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

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

## Overview

PR-Agent is an AI-powered pull-request review and automation service. Users invoke it through the CLI, GitHub Actions, or platform webhooks; the agent resolves the requested command, obtains PR data through a Git-provider adapter, prepares diffs and prompts, calls an AI backend, and publishes results through the provider. The graph also preserves README-listed tools and platform integrations. Several tool and server implementations were not excerpted, so their capabilities are documented but only evidenced relationships are connected.

Main entry points: [`pr_agent/agent/pr_agent.py`](https://github.com/wiljav/pr-agent/blob/main/pr_agent/agent/pr_agent.py) (Command agent), [`pr_agent/algo/pr_processing.py`](https://github.com/wiljav/pr-agent/blob/main/pr_agent/algo/pr_processing.py) (Diff preparation), [`pr_agent/tools/pr_reviewer.py`](https://github.com/wiljav/pr-agent/blob/main/pr_agent/tools/pr_reviewer.py) (PR review), [`pr_agent/git_providers/git_provider.py`](https://github.com/wiljav/pr-agent/blob/main/pr_agent/git_providers/git_provider.py) (Provider interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_cli["CLI<br/>[cli.py]"]
  node_webhooks["Webhook servers"]
  node_agent["Command agent<br/>[pr_agent.py]"]
  node_config["Settings<br/>[config_loader.py]"]
end

subgraph group_platform["Git platforms"]
  node_provider_factory["Provider factory<br/>[__init__.py]"]
  node_provider_base["Provider interface<br/>[git_provider.py]"]
  node_provider_adapters["Provider adapters"]
end

subgraph group_analysis["Review preparation"]
  node_pr_processing["Diff preparation<br/>[pr_processing.py]"]
  node_patch_processing["Patch processing"]
  node_file_filter["File filtering<br/>[file_filter.py]"]
  node_language["Language detection"]
  node_tokens["Token handling<br/>[token_handler.py]"]
  node_ai_base["AI handler interface<br/>[base_ai_handler.py]"]
  node_ai_litellm["LiteLLM backend"]
end

subgraph group_tools["PR tools"]
  node_reviewer["PR review<br/>[pr_reviewer.py]"]
  node_description["PR description<br/>[pr_description.py]"]
  node_suggestions["Code suggestions"]
  node_ticket_check["Ticket compliance"]
  node_other_tools["Other PR tools"]
end

node_developer(("User or event"))
node_git_host(("Git hosting service"))
node_llm(("AI model service"))

node_developer -->|"runs command"| node_cli
node_cli -->|"dispatches request"| node_agent
node_developer -->|"sends PR event"| node_webhooks
node_webhooks -->|"handles request"| node_agent
node_agent -->|"loads settings"| node_config
node_agent -->|"dispatches tool"| node_reviewer
node_agent -->|"dispatches tool"| node_description
node_agent -->|"dispatches tool"| node_suggestions
node_agent -->|"dispatches tools"| node_other_tools
node_provider_factory -->|"selects adapter"| node_provider_adapters
node_provider_adapters -->|"implements interface"| node_provider_base
node_provider_adapters -.->|"reads and writes PRs"| node_git_host
node_reviewer -->|"gets PR provider"| node_provider_factory
node_reviewer -->|"prepares diff"| node_pr_processing
node_pr_processing -->|"filters files"| node_file_filter
node_pr_processing -->|"processes patches"| node_patch_processing
node_pr_processing -->|"detects languages"| node_language
node_pr_processing -->|"counts tokens"| node_tokens
node_reviewer -->|"requests completion"| node_ai_base
node_ai_litellm -->|"implements interface"| node_ai_base
node_ai_litellm -.->|"requests completion"| node_llm
node_reviewer -.->|"publishes review"| node_provider_base
node_description -->|"prepares PR context"| node_pr_processing
node_description -->|"checks compliance"| node_ticket_check
node_suggestions -->|"prepares code context"| node_pr_processing
node_suggestions -.->|"publishes suggestions"| node_provider_base
node_ticket_check -->|"gets PR provider"| node_provider_factory
node_other_tools -.->|"uses PR data"| node_provider_base

click node_cli "https://github.com/wiljav/pr-agent/blob/main/pr_agent/cli.py"
click node_webhooks "https://github.com/wiljav/pr-agent/tree/main/pr_agent/servers"
click node_agent "https://github.com/wiljav/pr-agent/blob/main/pr_agent/agent/pr_agent.py"
click node_config "https://github.com/wiljav/pr-agent/blob/main/pr_agent/config_loader.py"
click node_provider_factory "https://github.com/wiljav/pr-agent/blob/main/pr_agent/git_providers/__init__.py"
click node_provider_base "https://github.com/wiljav/pr-agent/blob/main/pr_agent/git_providers/git_provider.py"
click node_provider_adapters "https://github.com/wiljav/pr-agent/tree/main/pr_agent/git_providers"
click node_pr_processing "https://github.com/wiljav/pr-agent/blob/main/pr_agent/algo/pr_processing.py"
click node_patch_processing "https://github.com/wiljav/pr-agent/blob/main/pr_agent/algo/git_patch_processing.py"
click node_file_filter "https://github.com/wiljav/pr-agent/blob/main/pr_agent/algo/file_filter.py"
click node_language "https://github.com/wiljav/pr-agent/blob/main/pr_agent/algo/language_handler.py"
click node_tokens "https://github.com/wiljav/pr-agent/blob/main/pr_agent/algo/token_handler.py"
click node_ai_base "https://github.com/wiljav/pr-agent/blob/main/pr_agent/algo/ai_handlers/base_ai_handler.py"
click node_ai_litellm "https://github.com/wiljav/pr-agent/blob/main/pr_agent/algo/ai_handlers/litellm_ai_handler.py"
click node_reviewer "https://github.com/wiljav/pr-agent/blob/main/pr_agent/tools/pr_reviewer.py"
click node_description "https://github.com/wiljav/pr-agent/blob/main/pr_agent/tools/pr_description.py"
click node_suggestions "https://github.com/wiljav/pr-agent/blob/main/pr_agent/tools/pr_code_suggestions.py"
click node_ticket_check "https://github.com/wiljav/pr-agent/blob/main/pr_agent/tools/ticket_pr_compliance_check.py"
click node_other_tools "https://github.com/wiljav/pr-agent/tree/main/pr_agent/tools"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_webhooks,node_agent,node_config,node_developer toneBlue
class node_provider_factory,node_provider_base,node_provider_adapters toneAmber
class node_pr_processing,node_patch_processing,node_file_filter,node_language,node_tokens,node_ai_base,node_ai_litellm toneMint
class node_reviewer,node_description,node_suggestions,node_ticket_check,node_other_tools toneRose
class node_git_host,node_llm toneIndigo
```

## Components

### Entry points

- [CLI](https://github.com/wiljav/pr-agent/blob/main/pr_agent/cli.py): `pr_agent/cli.py`
- [Webhook servers](https://github.com/wiljav/pr-agent/tree/main/pr_agent/servers): `pr_agent/servers`
- [Command agent](https://github.com/wiljav/pr-agent/blob/main/pr_agent/agent/pr_agent.py): `pr_agent/agent/pr_agent.py`
- [Settings](https://github.com/wiljav/pr-agent/blob/main/pr_agent/config_loader.py): `pr_agent/config_loader.py`

### Git platforms

- [Provider factory](https://github.com/wiljav/pr-agent/blob/main/pr_agent/git_providers/__init__.py): `pr_agent/git_providers/__init__.py`
- [Provider interface](https://github.com/wiljav/pr-agent/blob/main/pr_agent/git_providers/git_provider.py): `pr_agent/git_providers/git_provider.py`
- [Provider adapters](https://github.com/wiljav/pr-agent/tree/main/pr_agent/git_providers): `pr_agent/git_providers`

### Review preparation

- [Diff preparation](https://github.com/wiljav/pr-agent/blob/main/pr_agent/algo/pr_processing.py): `pr_agent/algo/pr_processing.py`
- [Patch processing](https://github.com/wiljav/pr-agent/blob/main/pr_agent/algo/git_patch_processing.py): `pr_agent/algo/git_patch_processing.py`
- [File filtering](https://github.com/wiljav/pr-agent/blob/main/pr_agent/algo/file_filter.py): `pr_agent/algo/file_filter.py`
- [Language detection](https://github.com/wiljav/pr-agent/blob/main/pr_agent/algo/language_handler.py): `pr_agent/algo/language_handler.py`
- [Token handling](https://github.com/wiljav/pr-agent/blob/main/pr_agent/algo/token_handler.py): `pr_agent/algo/token_handler.py`
- [AI handler interface](https://github.com/wiljav/pr-agent/blob/main/pr_agent/algo/ai_handlers/base_ai_handler.py): `pr_agent/algo/ai_handlers/base_ai_handler.py`
- [LiteLLM backend](https://github.com/wiljav/pr-agent/blob/main/pr_agent/algo/ai_handlers/litellm_ai_handler.py): `pr_agent/algo/ai_handlers/litellm_ai_handler.py`

### PR tools

- [PR review](https://github.com/wiljav/pr-agent/blob/main/pr_agent/tools/pr_reviewer.py): `pr_agent/tools/pr_reviewer.py`
- [PR description](https://github.com/wiljav/pr-agent/blob/main/pr_agent/tools/pr_description.py): `pr_agent/tools/pr_description.py`
- [Code suggestions](https://github.com/wiljav/pr-agent/blob/main/pr_agent/tools/pr_code_suggestions.py): `pr_agent/tools/pr_code_suggestions.py`
- [Ticket compliance](https://github.com/wiljav/pr-agent/blob/main/pr_agent/tools/ticket_pr_compliance_check.py): `pr_agent/tools/ticket_pr_compliance_check.py`
- [Other PR tools](https://github.com/wiljav/pr-agent/tree/main/pr_agent/tools): `pr_agent/tools`

### Other components

- **User or event**
- **Git hosting service**
- **AI model service**

## Connections

- User or event → CLI: runs command
- CLI → Command agent: dispatches request (evidence: `pr_agent/cli.py`)
- User or event → Webhook servers: sends PR event
- Webhook servers → Command agent: handles request (evidence: `pr_agent/servers/gitlab_webhook.py`)
- Command agent → Settings: loads settings (evidence: `pr_agent/agent/pr_agent.py`)
- Command agent → PR review: dispatches tool (evidence: `pr_agent/agent/pr_agent.py`)
- Command agent → PR description: dispatches tool (evidence: `pr_agent/agent/pr_agent.py`)
- Command agent → Code suggestions: dispatches tool (evidence: `pr_agent/agent/pr_agent.py`)
- Command agent → Other PR tools: dispatches tools (evidence: `pr_agent/agent/pr_agent.py`)
- Provider factory → Provider adapters: selects adapter (evidence: `pr_agent/git_providers/__init__.py`)
- Provider adapters → Provider interface: implements interface (evidence: `pr_agent/git_providers/__init__.py`)
- Provider adapters → Git hosting service: reads and writes PRs
- PR review → Provider factory: gets PR provider (evidence: `pr_agent/tools/pr_reviewer.py`)
- PR review → Diff preparation: prepares diff (evidence: `pr_agent/tools/pr_reviewer.py`)
- Diff preparation → File filtering: filters files (evidence: `pr_agent/algo/pr_processing.py`)
- Diff preparation → Patch processing: processes patches (evidence: `pr_agent/algo/pr_processing.py`)
- Diff preparation → Language detection: detects languages (evidence: `pr_agent/algo/pr_processing.py`)
- Diff preparation → Token handling: counts tokens (evidence: `pr_agent/algo/pr_processing.py`)
- PR review → AI handler interface: requests completion (evidence: `pr_agent/tools/pr_reviewer.py`)
- LiteLLM backend → AI handler interface: implements interface (evidence: `pr_agent/algo/ai_handlers/litellm_ai_handler.py`)
- LiteLLM backend → AI model service: requests completion
- PR review → Provider interface: publishes review (evidence: `pr_agent/tools/pr_reviewer.py`)
- PR description → Diff preparation: prepares PR context (evidence: `pr_agent/tools/pr_description.py`)
- PR description → Ticket compliance: checks compliance (evidence: `pr_agent/tools/pr_description.py`)
- Code suggestions → Diff preparation: prepares code context (evidence: `pr_agent/tools/pr_code_suggestions.py`)
- Code suggestions → Provider interface: publishes suggestions (evidence: `pr_agent/tools/pr_code_suggestions.py`)
- Ticket compliance → Provider factory: gets PR provider (evidence: `pr_agent/tools/ticket_pr_compliance_check.py`)
- Other PR tools → Provider interface: uses PR data (evidence: `pr_agent/tools/pr_reviewer.py`)
