# wufei-png/ai-codereview-agent architecture

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

- Interactive diagram: https://gitdiagram.com/wufei-png/ai-codereview-agent
- Repository: https://github.com/wufei-png/ai-codereview-agent

## Overview

AI-CodeReview-Agent accepts GitHub, GitLab, and Gitea webhook events and can run its built-in diff reviewer, External Agent Review, or both. The built-in path reviews changes and reports results to the platform; review events also persist dashboard records and can notify chat services. The External Agent path authenticates and enqueues a normalized request, then a separate worker executes it in an isolated workspace through one configured backend and records delivery status. Major README capabilities such as daily reports, automated repair, and incremental reviews are represented where their implementation is not sampled; those links rely on README evidence.

Main entry points: [`biz/agent/service.py`](https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/agent/service.py) (Agent job orchestration), [`biz/platforms`](https://github.com/wufei-png/ai-codereview-agent/tree/main/biz/platforms) (Platform event handlers), [`biz/api/routes/webhook.py`](https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/api/routes/webhook.py) (Webhook routes), [`biz/agent/backends.py`](https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/agent/backends.py) (Agent backends)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_intake["Webhook intake"]
  node_webhook["Webhook routes<br/>[webhook.py]"]
  node_security["Signature verification"]
end

subgraph group_builtin["Built-in review"]
  node_builtin_review["Diff review<br/>[code_reviewer.py]"]
  node_llm_factory["LLM provider factory<br/>[factory.py]"]
end

subgraph group_agent["External Agent review"]
  node_agent_config["Agent configuration<br/>[config.py]"]
  node_agent_service["Agent job orchestration<br/>[service.py]"]
  node_agent_queue[("Durable job store<br/>[job_store.py]")]
  node_agent_worker["Agent worker<br/>[worker.py]"]
  node_workspace["Isolated workspace<br/>[workspace.py]"]
  node_backend["Agent backends<br/>[backends.py]"]
  node_delivery["Delivery receipt"]
  node_agent_tools["Review tools"]
end

subgraph group_records["Records and reporting"]
  node_review_entity["Review records<br/>[review_entity.py]"]
  node_event_manager["Review event handlers<br/>[event_manager.py]"]
  node_review_db[("Review log database<br/>[review_service.py]")]
  node_dashboard["Review dashboard<br/>[ui.py]"]
  node_daily_reports["Daily reports<br/>[daily_report.py]"]
end

subgraph group_integrations["Platform and chat integrations"]
  node_platform_events["Platform event handlers"]
  node_platform_api["Platform API transport<br/>[http.py]"]
  node_chat_notify["Chat notifications<br/>[notifier.py]"]
  node_agent_platform_cli["Platform CLI"]
  node_chat_services["DingTalk, WeCom, Feishu"]
end

node_caller(("Platform webhook"))

node_caller -->|"posts event"| node_webhook
node_webhook -->|"verifies signature"| node_security
node_webhook -->|"dispatches event"| node_platform_events
node_webhook -->|"enqueues review"| node_agent_service
node_webhook -->|"queues built-in review"| node_builtin_review
node_platform_events -->|"fetches changes"| node_platform_api
node_platform_events -->|"submits changes"| node_builtin_review
node_builtin_review -->|"selects model"| node_llm_factory
node_platform_events -->|"posts review"| node_platform_api
node_platform_events -.->|"creates review record"| node_review_entity
node_review_entity -->|"emits review event"| node_event_manager
node_event_manager -->|"stores review"| node_review_db
node_event_manager -->|"sends notification"| node_chat_notify
node_review_db -->|"provides review logs"| node_dashboard
node_daily_reports -.->|"reads commit history"| node_platform_events
node_chat_notify -->|"sends messages"| node_chat_services
node_agent_service -->|"loads settings"| node_agent_config
node_agent_service -->|"persists job"| node_agent_queue
node_agent_worker -->|"claims job"| node_agent_queue
node_agent_worker -->|"runs job"| node_agent_service
node_agent_service -->|"prepares workspace"| node_workspace
node_agent_service -->|"runs backend"| node_backend
node_agent_service -->|"records delivery"| node_delivery
node_backend -.->|"uses review tools"| node_agent_tools
node_backend -->|"delivers review"| node_agent_platform_cli
node_workspace -.->|"records workspace"| node_agent_queue

click node_webhook "https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/api/routes/webhook.py"
click node_security "https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/utils/webhook_security.py"
click node_platform_events "https://github.com/wufei-png/ai-codereview-agent/tree/main/biz/platforms"
click node_builtin_review "https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/utils/code_reviewer.py"
click node_llm_factory "https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/llm/factory.py"
click node_platform_api "https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/platforms/http.py"
click node_review_entity "https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/entity/review_entity.py"
click node_event_manager "https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/event/event_manager.py"
click node_review_db "https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/service/review_service.py"
click node_dashboard "https://github.com/wufei-png/ai-codereview-agent/blob/main/ui.py"
click node_daily_reports "https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/api/routes/daily_report.py"
click node_chat_notify "https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/utils/im/notifier.py"
click node_agent_config "https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/agent/config.py"
click node_agent_service "https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/agent/service.py"
click node_agent_queue "https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/agent/job_store.py"
click node_agent_worker "https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/agent/worker.py"
click node_workspace "https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/agent/workspace.py"
click node_backend "https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/agent/backends.py"
click node_delivery "https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/agent/delivery_receipt.py"
click node_agent_tools "https://github.com/wufei-png/ai-codereview-agent/tree/main/biz/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_webhook,node_security toneBlue
class node_builtin_review,node_llm_factory toneAmber
class node_agent_config,node_agent_service,node_agent_queue,node_agent_worker,node_workspace,node_backend,node_delivery,node_agent_tools,node_caller toneMint
class node_review_entity,node_event_manager,node_review_db,node_dashboard,node_daily_reports toneRose
class node_platform_events,node_platform_api,node_chat_notify,node_agent_platform_cli,node_chat_services toneIndigo
```

## Components

### Webhook intake

- [Webhook routes](https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/api/routes/webhook.py): `biz/api/routes/webhook.py`
- [Signature verification](https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/utils/webhook_security.py): `biz/utils/webhook_security.py`

### Built-in review

- [Diff review](https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/utils/code_reviewer.py): `biz/utils/code_reviewer.py`
- [LLM provider factory](https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/llm/factory.py): `biz/llm/factory.py`

### External Agent review

- [Agent configuration](https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/agent/config.py): `biz/agent/config.py`
- [Agent job orchestration](https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/agent/service.py): `biz/agent/service.py`
- [Durable job store](https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/agent/job_store.py): `biz/agent/job_store.py`
- [Agent worker](https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/agent/worker.py): `biz/agent/worker.py`
- [Isolated workspace](https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/agent/workspace.py): `biz/agent/workspace.py`
- [Agent backends](https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/agent/backends.py): `biz/agent/backends.py`
- [Delivery receipt](https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/agent/delivery_receipt.py): `biz/agent/delivery_receipt.py`
- [Review tools](https://github.com/wufei-png/ai-codereview-agent/tree/main/biz/agent/tools): `biz/agent/tools`

### Records and reporting

- [Review records](https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/entity/review_entity.py): `biz/entity/review_entity.py`
- [Review event handlers](https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/event/event_manager.py): `biz/event/event_manager.py`
- [Review log database](https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/service/review_service.py): `biz/service/review_service.py`
- [Review dashboard](https://github.com/wufei-png/ai-codereview-agent/blob/main/ui.py): `ui.py`
- [Daily reports](https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/api/routes/daily_report.py): `biz/api/routes/daily_report.py`

### Platform and chat integrations

- [Platform event handlers](https://github.com/wufei-png/ai-codereview-agent/tree/main/biz/platforms): `biz/platforms`
- [Platform API transport](https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/platforms/http.py): `biz/platforms/http.py`
- [Chat notifications](https://github.com/wufei-png/ai-codereview-agent/blob/main/biz/utils/im/notifier.py): `biz/utils/im/notifier.py`
- **Platform CLI**
- **DingTalk, WeCom, Feishu**

### Other components

- **Platform webhook**

## Connections

- Platform webhook → Webhook routes: posts event (evidence: `README.md`)
- Webhook routes → Signature verification: verifies signature (evidence: `biz/api/routes/webhook.py`)
- Webhook routes → Platform event handlers: dispatches event (evidence: `README.md`)
- Webhook routes → Agent job orchestration: enqueues review (evidence: `biz/api/routes/webhook.py`)
- Webhook routes → Diff review: queues built-in review (evidence: `README.md`)
- Platform event handlers → Platform API transport: fetches changes (evidence: `biz/platforms/gitlab/webhook_handler.py`)
- Platform event handlers → Diff review: submits changes (evidence: `README.md`)
- Diff review → LLM provider factory: selects model (evidence: `biz/utils/code_reviewer.py`)
- Platform event handlers → Platform API transport: posts review (evidence: `biz/platforms/gitlab/webhook_handler.py`)
- Platform event handlers → Review records: creates review record
- Review records → Review event handlers: emits review event (evidence: `biz/event/event_manager.py`)
- Review event handlers → Review log database: stores review (evidence: `biz/event/event_manager.py`)
- Review event handlers → Chat notifications: sends notification (evidence: `biz/event/event_manager.py`)
- Review log database → Review dashboard: provides review logs (evidence: `ui.py`)
- Daily reports → Platform event handlers: reads commit history
- Chat notifications → DingTalk, WeCom, Feishu: sends messages (evidence: `README.md`)
- Agent job orchestration → Agent configuration: loads settings (evidence: `biz/agent/service.py`)
- Agent job orchestration → Durable job store: persists job (evidence: `biz/agent/service.py`)
- Agent worker → Durable job store: claims job (evidence: `biz/agent/worker.py`)
- Agent worker → Agent job orchestration: runs job (evidence: `biz/agent/worker.py`)
- Agent job orchestration → Isolated workspace: prepares workspace (evidence: `biz/agent/service.py`)
- Agent job orchestration → Agent backends: runs backend (evidence: `biz/agent/service.py`)
- Agent job orchestration → Delivery receipt: records delivery (evidence: `biz/agent/service.py`)
- Agent backends → Review tools: uses review tools
- Agent backends → Platform CLI: delivers review (evidence: `README.md`)
- Isolated workspace → Durable job store: records workspace
