# mirzasayzz/prpilot architecture

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

- Interactive diagram: https://gitdiagram.com/mirzasayzz/prpilot
- Repository: https://github.com/mirzasayzz/prpilot

## Overview

1. **Overall shape**
   PRPilot is a **Python GitHub App** deployed as **Vercel serverless functions**. Its core job is to react to GitHub Pull Request webhooks, analyze changed code with AI, and post a review comment back to the PR.

2. **Primary runtime boundary**
   The backend lives under `api/` and is the operational entry point in production:
   - `api/webhook.py` handles GitHub webhook traffic
   - `api/config.py` serves repository/app configuration
   - `api/index.py` is the health check
   `vercel.json` is the deployment/routing layer that exposes these functions.

3. **GitHub event flow**
   The main data flow is: **GitHub PR event → webhook endpoint → signature verification → repository/config lookup → diff fetch → AI analysis → synthesized review → GitHub comment**.  
   The GitHub-facing integration is split between `github/client.py` and `github/webhook_handler.py`, which likely isolate API calls and payload/event parsing from the rest of the app.

4. **State and persistence**
   Persistent configuration is backed by **Supabase/Postgres**, with schema in `db/schema.sql` and database access in `db/client.py`.  
   The database stores installation/repository configuration and encrypted credentials needed for automated reviews.

5. **Secret handling**
   The security boundary is important: `agents/key_manager.py` indicates API keys are encrypted before storage and decrypted only at runtime. The README says the encryption is **AES-256** with a base64-encoded application encryption key supplied via environment variables.

6. **AI analysis subsystem**
   The `agents/` package is the main intelligence layer. It contains:
   - `base.py` for shared agent behavior
   - `style_agent.py`
   - `security_agent.py`
   - `performance_agent.py`
   - `logic_agent.py`
   These run as specialized analyzers over the same code diff, each producing domain-specific findings.

7. **LLM abstraction**
   `agents/llm_client.py` is the provider boundary for model access. The README positions **Gemini 2.0 Flash** as the primary model, and the client layer appears to support provider abstraction/fallback so the rest of the system does not depend on a specific LLM vendor.

8. **Review synthesis**
   After all agents finish, their outputs are combined into a single review artifact. The architecture described in the README implies a synthesis step that deduplicates findings, normalizes severity/content, and formats the result as **Markdown** before it is posted to GitHub.

9. **User-facing configuration**
   `public/index.html` and `public/config.html` are static UI assets served separately from the webhook path. They support the landing page and repository/app configuration experience, while the actual automation remains server-side.

10. **Local/test path**
   The repo also includes a non-GitHub execution path for validation:
   - `test_local.py` runs the agents locally
   - `test_samples/sample_code.py` provides a sample input
   - `docs/TESTING_GUIDE.md` documents end-to-end verification
   This makes the agent pipeline testable without deploying the GitHub App.

11. **Operational dependencies**
   The architecture depends on three external systems that shape the design:
   - **GitHub** for webhooks, PR diffs, and posting comments
   - **Supabase** for persistent configuration/storage
   - **Google AI Studio/Gemini** for code analysis
   Vercel provides the serverless execution environment, which influences the stateless request/response design.

12. **Diagram boundaries to show**
   An accurate architecture diagram should separate:
   - GitHub event source and comment sink
   - Vercel serverless API layer
   - Database/configuration storage in Supabase
   - The four parallel AI agents
   - The LLM provider boundary
   - Local testing utilities as a separate, non-production path

Main entry points: [`api/webhook.py`](https://github.com/mirzasayzz/prpilot/blob/main/api/webhook.py) (Webhook), [`agents/base.py`](https://github.com/mirzasayzz/prpilot/blob/main/agents/base.py) (Agent base), [`db/client.py`](https://github.com/mirzasayzz/prpilot/blob/main/db/client.py) (DB client), [`agents/llm_client.py`](https://github.com/mirzasayzz/prpilot/blob/main/agents/llm_client.py) (LLM client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Vercel API"]
  node_api_webhook["Webhook<br/>serverless handler<br/>[webhook.py]"]
  node_api_config["Config API<br/>serverless handler<br/>[config.py]"]
  node_api_install["Install API<br/>serverless handler<br/>[install.py]"]
  node_api_index["Health check<br/>serverless handler<br/>[index.py]"]
  node_vercel["Vercel routing<br/>deploy config<br/>[vercel.json]"]
end

subgraph group_integration["GitHub integration"]
  node_gh_handler["Event parser<br/>webhook adapter<br/>[webhook_handler.py]"]
  node_gh_client["GitHub client<br/>api client<br/>[client.py]"]
end

subgraph group_analysis["AI analysis"]
  node_review_pipeline{{"Review pipeline<br/>orchestrator"}}
  node_agent_base["Agent base<br/>shared agent<br/>[base.py]"]
  node_style_agent["Style<br/>review agent<br/>[style_agent.py]"]
  node_security_agent["Security<br/>review agent<br/>[security_agent.py]"]
  node_performance_agent["Performance<br/>review agent"]
  node_logic_agent["Logic<br/>review agent<br/>[logic_agent.py]"]
  node_llm_client["LLM client<br/>model gateway<br/>[llm_client.py]"]
  node_key_manager["Key manager<br/>crypto boundary<br/>[key_manager.py]"]
end

subgraph group_storage["Persistence"]
  node_db_client[("DB client<br/>data access<br/>[client.py]")]
  node_db_schema["Schema<br/>[schema.sql]"]
end

subgraph group_ui["User UI"]
  node_public_index["Landing page<br/>static page<br/>[index.html]"]
  node_public_config["Config page<br/>static page<br/>[config.html]"]
end

subgraph group_local["Local validation"]
  node_test_local["Local runner<br/>validation script<br/>[test_local.py]"]
  node_sample_code["Sample input<br/>fixture<br/>[sample_code.py]"]
  node_testing_guide["Testing guide<br/>docs<br/>[TESTING_GUIDE.md]"]
end

node_github(("GitHub<br/>external platform"))
node_supabase[("Supabase<br/>external storage")]
node_gemini(("Gemini<br/>external model"))

node_vercel -->|"routes"| node_api_webhook
node_vercel -->|"routes"| node_api_config
node_vercel -->|"routes"| node_api_install
node_vercel -->|"routes"| node_api_index
node_api_webhook -->|"parses"| node_gh_handler
node_api_webhook -->|"loads config"| node_db_client
node_api_webhook -->|"starts"| node_review_pipeline
node_api_config -->|"serves config"| node_db_client
node_api_install -->|"stores install"| node_db_client
node_gh_handler -->|"uses"| node_gh_client
node_review_pipeline -->|"fetches diff / posts review"| node_gh_client
node_review_pipeline -->|"coordinates"| node_agent_base
node_agent_base -->|"runs"| node_style_agent
node_agent_base -->|"runs"| node_security_agent
node_agent_base -->|"runs"| node_performance_agent
node_agent_base -->|"runs"| node_logic_agent
node_style_agent -->|"calls"| node_llm_client
node_security_agent -->|"calls"| node_llm_client
node_performance_agent -->|"calls"| node_llm_client
node_logic_agent -->|"calls"| node_llm_client
node_review_pipeline -->|"decrypts"| node_key_manager
node_db_client -->|"implements"| node_db_schema
node_db_client -->|"persists"| node_supabase
node_llm_client -->|"invokes"| node_gemini
node_public_index -.->|"links"| node_public_config
node_test_local -->|"loads"| node_sample_code
node_test_local -->|"exercises"| node_review_pipeline
node_testing_guide -.->|"documents"| node_test_local
node_api_webhook -->|"receives from"| node_github
node_gh_client -->|"calls"| node_github

click node_api_webhook "https://github.com/mirzasayzz/prpilot/blob/main/api/webhook.py"
click node_api_config "https://github.com/mirzasayzz/prpilot/blob/main/api/config.py"
click node_api_install "https://github.com/mirzasayzz/prpilot/blob/main/api/install.py"
click node_api_index "https://github.com/mirzasayzz/prpilot/blob/main/api/index.py"
click node_vercel "https://github.com/mirzasayzz/prpilot/blob/main/vercel.json"
click node_gh_handler "https://github.com/mirzasayzz/prpilot/blob/main/github/webhook_handler.py"
click node_gh_client "https://github.com/mirzasayzz/prpilot/blob/main/github/client.py"
click node_db_client "https://github.com/mirzasayzz/prpilot/blob/main/db/client.py"
click node_db_schema "https://github.com/mirzasayzz/prpilot/blob/main/db/schema.sql"
click node_agent_base "https://github.com/mirzasayzz/prpilot/blob/main/agents/base.py"
click node_style_agent "https://github.com/mirzasayzz/prpilot/blob/main/agents/style_agent.py"
click node_security_agent "https://github.com/mirzasayzz/prpilot/blob/main/agents/security_agent.py"
click node_performance_agent "https://github.com/mirzasayzz/prpilot/blob/main/agents/performance_agent.py"
click node_logic_agent "https://github.com/mirzasayzz/prpilot/blob/main/agents/logic_agent.py"
click node_llm_client "https://github.com/mirzasayzz/prpilot/blob/main/agents/llm_client.py"
click node_key_manager "https://github.com/mirzasayzz/prpilot/blob/main/agents/key_manager.py"
click node_public_index "https://github.com/mirzasayzz/prpilot/blob/main/public/index.html"
click node_public_config "https://github.com/mirzasayzz/prpilot/blob/main/public/config.html"
click node_test_local "https://github.com/mirzasayzz/prpilot/blob/main/test_local.py"
click node_sample_code "https://github.com/mirzasayzz/prpilot/blob/main/test_samples/sample_code.py"
click node_testing_guide "https://github.com/mirzasayzz/prpilot/blob/main/docs/TESTING_GUIDE.md"

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_api_webhook,node_api_config,node_api_install,node_api_index,node_vercel toneBlue
class node_gh_handler,node_gh_client toneAmber
class node_review_pipeline,node_agent_base,node_style_agent,node_security_agent,node_performance_agent,node_logic_agent,node_llm_client,node_key_manager toneMint
class node_db_client,node_db_schema toneRose
class node_public_index,node_public_config toneIndigo
class node_test_local,node_sample_code,node_testing_guide toneTeal
class node_github,node_supabase,node_gemini toneNeutral
```

## Components

### Vercel API

Serverless entrypoints and deployment routing

- [Webhook](https://github.com/mirzasayzz/prpilot/blob/main/api/webhook.py): serverless handler · Receives GitHub PR webhooks and starts the review flow · `api/webhook.py`
- [Config API](https://github.com/mirzasayzz/prpilot/blob/main/api/config.py): serverless handler · Serves repository and app configuration · `api/config.py`
- [Install API](https://github.com/mirzasayzz/prpilot/blob/main/api/install.py): serverless handler · Handles GitHub App installation setup · `api/install.py`
- [Health check](https://github.com/mirzasayzz/prpilot/blob/main/api/index.py): serverless handler · Simple operational endpoint · `api/index.py`
- [Vercel routing](https://github.com/mirzasayzz/prpilot/blob/main/vercel.json): deploy config · Exposes the API functions in production · `vercel.json`

### GitHub integration

Webhook parsing and GitHub API access

- [Event parser](https://github.com/mirzasayzz/prpilot/blob/main/github/webhook_handler.py): webhook adapter · Normalizes GitHub webhook payloads and event flow · `github/webhook_handler.py`
- [GitHub client](https://github.com/mirzasayzz/prpilot/blob/main/github/client.py): api client · Fetches diffs and posts review comments · `github/client.py`

### AI analysis

Agent pipeline and model access

- **Review pipeline**: orchestrator · Coordinates diff analysis, synthesis, and publishing
- [Agent base](https://github.com/mirzasayzz/prpilot/blob/main/agents/base.py): shared agent · Common agent behavior and interfaces · `agents/base.py`
- [Style](https://github.com/mirzasayzz/prpilot/blob/main/agents/style_agent.py): review agent · Checks readability and code style · `agents/style_agent.py`
- [Security](https://github.com/mirzasayzz/prpilot/blob/main/agents/security_agent.py): review agent · Finds security issues in changes · `agents/security_agent.py`
- [Performance](https://github.com/mirzasayzz/prpilot/blob/main/agents/performance_agent.py): review agent · Flags performance regressions and inefficiencies · `agents/performance_agent.py`
- [Logic](https://github.com/mirzasayzz/prpilot/blob/main/agents/logic_agent.py): review agent · Detects functional bugs and correctness issues · `agents/logic_agent.py`
- [LLM client](https://github.com/mirzasayzz/prpilot/blob/main/agents/llm_client.py): model gateway · Abstracts Gemini and other model providers · `agents/llm_client.py`
- [Key manager](https://github.com/mirzasayzz/prpilot/blob/main/agents/key_manager.py): crypto boundary · Encrypts and decrypts stored API keys at runtime · `agents/key_manager.py`

### Persistence

Database schema and access layer

- [DB client](https://github.com/mirzasayzz/prpilot/blob/main/db/client.py): data access · Reads and writes configuration and credentials · `db/client.py`
- [Schema](https://github.com/mirzasayzz/prpilot/blob/main/db/schema.sql): postgres schema · Defines persisted configuration and secret storage · `db/schema.sql`

### User UI

Static pages for app and configuration

- [Landing page](https://github.com/mirzasayzz/prpilot/blob/main/public/index.html): static page · Public-facing entry page · `public/index.html`
- [Config page](https://github.com/mirzasayzz/prpilot/blob/main/public/config.html): static page · Repository and app configuration UI · `public/config.html`

### Local validation

Non-production execution and sample input

- [Local runner](https://github.com/mirzasayzz/prpilot/blob/main/test_local.py): validation script · Runs the agent pipeline outside GitHub · `test_local.py`
- [Sample input](https://github.com/mirzasayzz/prpilot/blob/main/test_samples/sample_code.py): fixture · Example code used for local testing · `test_samples/sample_code.py`
- [Testing guide](https://github.com/mirzasayzz/prpilot/blob/main/docs/TESTING_GUIDE.md): docs · Documents end-to-end validation steps · `docs/TESTING_GUIDE.md`

### Other components

- **GitHub**: external platform · Webhook source, PR diff source, and comment sink
- **Supabase**: external storage · Postgres-backed persistence for config and secrets
- **Gemini**: external model · Primary AI model provider

## Connections

- Vercel routing → Webhook: routes · Deployment exposes the webhook handler
- Vercel routing → Config API: routes · Deployment exposes configuration endpoint
- Vercel routing → Install API: routes · Deployment exposes install endpoint
- Vercel routing → Health check: routes · Deployment exposes health endpoint
- Webhook → Event parser: parses · Webhook handler normalizes incoming GitHub events
- Webhook → DB client: loads config · Reads installation and repository settings
- Webhook → Review pipeline: starts · Kicks off analysis and review generation
- Config API → DB client: serves config · Fetches persisted configuration for the UI and app
- Install API → DB client: stores install · Persists installation state and settings
- Event parser → GitHub client: uses · Delegates GitHub API interactions
- Review pipeline → GitHub client: fetches diff / posts review · Reads PR changes and publishes the final comment
- Review pipeline → Agent base: coordinates · Shares common agent behavior and execution flow
- Agent base → Style: runs · Executes the style review pass
- Agent base → Security: runs · Executes the security review pass
- Agent base → Performance: runs · Executes the performance review pass
- Agent base → Logic: runs · Executes the logic review pass
- Style → LLM client: calls · Uses model access for analysis
- Security → LLM client: calls · Uses model access for analysis
- Performance → LLM client: calls · Uses model access for analysis
- Logic → LLM client: calls · Uses model access for analysis
- Review pipeline → Key manager: decrypts · Protects stored API keys at runtime
- DB client → Schema: implements · Database access follows the defined schema
- DB client → Supabase: persists · Stores and retrieves application state
- LLM client → Gemini: invokes · Primary model provider boundary
- Landing page → Config page: links · Static UI provides navigation to configuration
- Local runner → Sample input: loads · Uses sample input for local validation
- Local runner → Review pipeline: exercises · Runs the analysis pipeline without GitHub
- Testing guide → Local runner: documents · Explains local and end-to-end verification
- Webhook → GitHub: receives from · Incoming webhook requests originate from GitHub
- GitHub client → GitHub: calls · Posts comments and fetches pull request data
