# malarcb/ai-reviewer architecture

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

- Interactive diagram: https://gitdiagram.com/malarcb/ai-reviewer
- Repository: https://github.com/malarcb/ai-reviewer

## Overview

AI Code Reviewer is a GitHub Action that reviews pull requests, generates PR titles and descriptions, and responds to relevant review-comment threads. GitHub event dispatch selects the full-review or comment-response workflow; the full review fetches commits and diffs, optionally accounts for existing threads and incremental-review state, generates AI results, and posts a summary and review comments. The graph includes README capabilities, but unsampled implementation details and some integration links are omitted where their call paths are not shown.

Main entry points: [`src/pull_request.ts`](https://github.com/malarcb/ai-reviewer/blob/master/src/pull_request.ts) (PR review workflow), [`src/pull_request_comment.ts`](https://github.com/malarcb/ai-reviewer/blob/master/src/pull_request_comment.ts) (Comment response workflow), [`src/ai.ts`](https://github.com/malarcb/ai-reviewer/blob/master/src/ai.ts) (AI model runner), [`src/octokit.ts`](https://github.com/malarcb/ai-reviewer/blob/master/src/octokit.ts) (GitHub API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Event handling"]
  node_dispatcher["Event dispatcher<br/>[main.ts]"]
end

subgraph group_review["Pull request review"]
  node_pr_workflow["PR review workflow<br/>[pull_request.ts]"]
  node_diff_parser["Diff processing<br/>[diff.ts]"]
  node_review_threads["Review threads<br/>[comments.ts]"]
  node_review_messages["Review messages<br/>[messages.ts]"]
end

subgraph group_interactive["Comment interaction"]
  node_comment_workflow["Comment response workflow"]
end

subgraph group_intelligence["AI generation"]
  node_summary_prompt["PR summary generation<br/>[prompts.ts]"]
  node_code_review_prompt["Code review generation<br/>[prompts.ts]"]
  node_reply_prompt["Comment reply generation<br/>[prompts.ts]"]
  node_ai_runner["AI model runner<br/>[ai.ts]"]
end

subgraph group_integration["GitHub integration"]
  node_configuration["Action configuration<br/>[config.ts]"]
  node_action_context["Event context<br/>[context.ts]"]
  node_octokit_client["GitHub API client<br/>[octokit.ts]"]
end

node_github_event(("GitHub event"))
node_github_api["GitHub API"]
node_llm_provider["LLM providers"]

node_github_event -->|"triggers"| node_dispatcher
node_dispatcher -->|"routes PR events"| node_pr_workflow
node_dispatcher -->|"routes comment events"| node_comment_workflow
node_pr_workflow -->|"loads context"| node_action_context
node_comment_workflow -->|"loads context"| node_action_context
node_pr_workflow -->|"initializes client"| node_octokit_client
node_comment_workflow -->|"initializes client"| node_octokit_client
node_pr_workflow -->|"parses diffs"| node_diff_parser
node_pr_workflow -->|"loads threads"| node_review_threads
node_diff_parser -->|"filters threads"| node_review_threads
node_pr_workflow -->|"requests summary"| node_summary_prompt
node_pr_workflow -->|"requests review"| node_code_review_prompt
node_summary_prompt -->|"runs prompt"| node_ai_runner
node_code_review_prompt -->|"runs prompt"| node_ai_runner
node_comment_workflow -->|"fetches thread"| node_review_threads
node_comment_workflow -->|"parses file diffs"| node_diff_parser
node_comment_workflow -->|"requests reply"| node_reply_prompt
node_reply_prompt -->|"runs prompt"| node_ai_runner
node_pr_workflow -->|"builds review messages"| node_review_messages
node_pr_workflow -->|"fetches and posts"| node_octokit_client
node_comment_workflow -->|"fetches and replies"| node_octokit_client
node_ai_runner -->|"reads model settings"| node_configuration
node_pr_workflow -->|"reads action settings"| node_configuration
node_comment_workflow -->|"reads action settings"| node_configuration
node_octokit_client -->|"calls"| node_github_api
node_ai_runner -->|"generates structured output"| node_llm_provider

click node_dispatcher "https://github.com/malarcb/ai-reviewer/blob/master/src/main.ts"
click node_pr_workflow "https://github.com/malarcb/ai-reviewer/blob/master/src/pull_request.ts"
click node_diff_parser "https://github.com/malarcb/ai-reviewer/blob/master/src/diff.ts"
click node_review_threads "https://github.com/malarcb/ai-reviewer/blob/master/src/comments.ts"
click node_review_messages "https://github.com/malarcb/ai-reviewer/blob/master/src/messages.ts"
click node_comment_workflow "https://github.com/malarcb/ai-reviewer/blob/master/src/pull_request_comment.ts"
click node_summary_prompt "https://github.com/malarcb/ai-reviewer/blob/master/src/prompts.ts"
click node_code_review_prompt "https://github.com/malarcb/ai-reviewer/blob/master/src/prompts.ts"
click node_reply_prompt "https://github.com/malarcb/ai-reviewer/blob/master/src/prompts.ts"
click node_ai_runner "https://github.com/malarcb/ai-reviewer/blob/master/src/ai.ts"
click node_configuration "https://github.com/malarcb/ai-reviewer/blob/master/src/config.ts"
click node_action_context "https://github.com/malarcb/ai-reviewer/blob/master/src/context.ts"
click node_octokit_client "https://github.com/malarcb/ai-reviewer/blob/master/src/octokit.ts"

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_dispatcher toneBlue
class node_pr_workflow,node_diff_parser,node_review_threads,node_review_messages toneAmber
class node_comment_workflow,node_github_api toneMint
class node_summary_prompt,node_code_review_prompt,node_reply_prompt,node_ai_runner toneRose
class node_configuration,node_action_context,node_octokit_client,node_github_event,node_llm_provider toneIndigo
```

## Components

### Event handling

- [Event dispatcher](https://github.com/malarcb/ai-reviewer/blob/master/src/main.ts): `src/main.ts`

### Pull request review

- [PR review workflow](https://github.com/malarcb/ai-reviewer/blob/master/src/pull_request.ts): `src/pull_request.ts`
- [Diff processing](https://github.com/malarcb/ai-reviewer/blob/master/src/diff.ts): `src/diff.ts`
- [Review threads](https://github.com/malarcb/ai-reviewer/blob/master/src/comments.ts): `src/comments.ts`
- [Review messages](https://github.com/malarcb/ai-reviewer/blob/master/src/messages.ts): `src/messages.ts`

### Comment interaction

- [Comment response workflow](https://github.com/malarcb/ai-reviewer/blob/master/src/pull_request_comment.ts): `src/pull_request_comment.ts`

### AI generation

- [PR summary generation](https://github.com/malarcb/ai-reviewer/blob/master/src/prompts.ts): `src/prompts.ts`
- [Code review generation](https://github.com/malarcb/ai-reviewer/blob/master/src/prompts.ts): `src/prompts.ts`
- [Comment reply generation](https://github.com/malarcb/ai-reviewer/blob/master/src/prompts.ts): `src/prompts.ts`
- [AI model runner](https://github.com/malarcb/ai-reviewer/blob/master/src/ai.ts): `src/ai.ts`

### GitHub integration

- [Action configuration](https://github.com/malarcb/ai-reviewer/blob/master/src/config.ts): `src/config.ts`
- [Event context](https://github.com/malarcb/ai-reviewer/blob/master/src/context.ts): `src/context.ts`
- [GitHub API client](https://github.com/malarcb/ai-reviewer/blob/master/src/octokit.ts): `src/octokit.ts`

### Other components

- **GitHub event**
- **GitHub API**
- **LLM providers**

## Connections

- GitHub event → Event dispatcher: triggers (evidence: `src/main.ts`)
- Event dispatcher → PR review workflow: routes PR events (evidence: `src/main.ts`)
- Event dispatcher → Comment response workflow: routes comment events (evidence: `src/main.ts`)
- PR review workflow → Event context: loads context (evidence: `src/pull_request.ts`)
- Comment response workflow → Event context: loads context (evidence: `src/pull_request_comment.ts`)
- PR review workflow → GitHub API client: initializes client (evidence: `src/pull_request.ts`)
- Comment response workflow → GitHub API client: initializes client (evidence: `src/pull_request_comment.ts`)
- PR review workflow → Diff processing: parses diffs (evidence: `src/pull_request.ts`)
- PR review workflow → Review threads: loads threads (evidence: `src/pull_request.ts`)
- Diff processing → Review threads: filters threads (evidence: `src/diff.ts`)
- PR review workflow → PR summary generation: requests summary (evidence: `src/pull_request.ts`)
- PR review workflow → Code review generation: requests review (evidence: `src/pull_request.ts`)
- PR summary generation → AI model runner: runs prompt (evidence: `src/prompts.ts`)
- Code review generation → AI model runner: runs prompt (evidence: `src/prompts.ts`)
- Comment response workflow → Review threads: fetches thread (evidence: `src/pull_request_comment.ts`)
- Comment response workflow → Diff processing: parses file diffs (evidence: `src/pull_request_comment.ts`)
- Comment response workflow → Comment reply generation: requests reply (evidence: `src/pull_request_comment.ts`)
- Comment reply generation → AI model runner: runs prompt (evidence: `src/prompts.ts`)
- PR review workflow → Review messages: builds review messages (evidence: `src/pull_request.ts`)
- PR review workflow → GitHub API client: fetches and posts (evidence: `src/pull_request.ts`)
- Comment response workflow → GitHub API client: fetches and replies (evidence: `src/pull_request_comment.ts`)
- AI model runner → Action configuration: reads model settings (evidence: `src/ai.ts`)
- PR review workflow → Action configuration: reads action settings (evidence: `src/pull_request.ts`)
- Comment response workflow → Action configuration: reads action settings (evidence: `src/pull_request_comment.ts`)
- GitHub API client → GitHub API: calls (evidence: `src/octokit.ts`)
- AI model runner → LLM providers: generates structured output (evidence: `src/ai.ts`)
