# tmokmss/bedrock-pr-reviewer architecture

> Architecture diagram of the GitHub repository tmokmss/bedrock-pr-reviewer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tmokmss/bedrock-pr-reviewer
- Repository: https://github.com/tmokmss/bedrock-pr-reviewer

## Overview

##### Main Components

a) External Services Layer:
- GitHub (Pull Request System)
- Amazon Bedrock (Claude AI Models)
- AWS IAM (Authentication)

b) Core Application Components:
- GitHub Action Runner
- PR Review System
- Authentication Handler
- Comment Management System
- Tokenizer Service

##### Trigger Layer
- GitHub Events (pull_request, pull_request_review_comment)
- Concurrency control mechanism

##### Authentication Layer
- AWS OIDC Authentication
- GitHub Token Authentication

##### Core Processing Layer
- Main Review Logic
- File Processing
- Comment Management
- Prompt Management

##### AI Integration Layer
- Bedrock API Communication
- Model Selection Logic ("light" vs "heavy" models)

Use these visual elements:
- Hexagons for external services

##### Component Relationships

Key interactions:
**GitHub Events → GitHub Action Runner → Authentication Handler**
- ↓
- PR Review System ←→ Tokenizer Service
- ↓
- Bedrock API Client
- ↓
- Amazon Bedrock Service

##### Important Details

a) File Processing Flow:
- How the system handles different file types
- Diff processing mechanism
- Incremental review process

b) Comment Management:
- Flow of review comments
- Conversation capability with the bot
- Comment threading mechanism

c) Configuration Elements:
- How environment variables are handled
- Where custom prompts are processed
- Role of action.yml in the system

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph External["External Services"]
        direction TB
        GH[GitHub]
        AB[Amazon Bedrock]
        IAM[AWS IAM]
    end

    subgraph TriggerLayer["Trigger Layer"]
        direction TB
        PRE["Pull Request Events"]:::event
        PRRC["PR Review Comment Events"]:::event
        AC["Action Configuration"]:::config
        click AC "https://github.com/tmokmss/bedrock-pr-reviewer/blob/main/action.yml"
    end

    subgraph AuthLayer["Authentication Layer"]
        direction TB
        OIDC["AWS OIDC Auth"]:::auth
        GTA["GitHub Token Auth"]:::auth
        click OIDC "https://github.com/tmokmss/bedrock-pr-reviewer/blob/main/docs/oidc-cfn.yaml"
    end

    subgraph CoreLayer["Core Processing Layer"]
        direction TB
        AR["Action Runner"]:::core
        click AR "https://github.com/tmokmss/bedrock-pr-reviewer/blob/main/src/main.ts"
        
        subgraph ReviewSystem["Review System"]
            direction TB
            RP["Review Processor"]:::core
            click RP "https://github.com/tmokmss/bedrock-pr-reviewer/blob/main/src/review.ts"
            RC["Review Commenter"]:::core
            click RC "https://github.com/tmokmss/bedrock-pr-reviewer/blob/main/src/review-comment.ts"
            TS["Tokenizer Service"]:::core
            click TS "https://github.com/tmokmss/bedrock-pr-reviewer/blob/main/src/tokenizer.ts"
        end

        subgraph ConfigSystem["Configuration System"]
            direction TB
            IP["Input Processor"]:::config
            click IP "https://github.com/tmokmss/bedrock-pr-reviewer/blob/main/src/inputs.ts"
            CM["Config Manager"]:::config
            click CM "https://github.com/tmokmss/bedrock-pr-reviewer/blob/main/src/options.ts"
            LH["Limits Handler"]:::config
            click LH "https://github.com/tmokmss/bedrock-pr-reviewer/blob/main/src/limits.ts"
        end

        PM["Permission Manager"]:::auth
        click PM "https://github.com/tmokmss/bedrock-pr-reviewer/blob/main/src/permission.ts"
        
        BOT["AI Bot Controller"]:::core
        click BOT "https://github.com/tmokmss/bedrock-pr-reviewer/blob/main/src/bot.ts"
        
        PRM["Prompt Manager"]:::core
        click PRM "https://github.com/tmokmss/bedrock-pr-reviewer/blob/main/src/prompts.ts"
    end

    subgraph IntegrationLayer["Integration Layer"]
        direction TB
        GI["GitHub API Client"]:::integration
        click GI "https://github.com/tmokmss/bedrock-pr-reviewer/blob/main/src/octokit.ts"
        BI["Bedrock Integration"]:::integration
    end

    %% Connections
    PRE --> AR
    PRRC --> AR
    AC --> AR
    
    AR --> PM
    PM --> OIDC
    PM --> GTA
    
    AR --> IP
    IP --> CM
    CM --> LH
    
    AR --> RP
    RP --> TS
    RP --> RC
    RP --> BOT
    BOT --> PRM
    
    RC --> GI
    BOT --> BI
    
    OIDC --> IAM
    GTA --> GH
    GI --> GH
    BI --> AB

    %% Styles
    classDef event fill:#A0D8EF
    classDef auth fill:#E6B8FF
    classDef core fill:#90EE90
    classDef integration fill:#FFB366
    classDef config fill:#D3D3D3

    %% Legend
    subgraph Legend
        direction TB
        E1["Event"]:::event
        A1["Authentication"]:::auth
        C1["Core Processing"]:::core
        I1["Integration"]:::integration
        CF1["Configuration"]:::config
    end
```
