# maokli/reviewpal architecture

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

- Interactive diagram: https://gitdiagram.com/maokli/reviewpal
- Repository: https://github.com/maokli/reviewpal

## Overview

##### Project Type Analysis
This is a Python-based application that follows a clean architecture pattern, evident from the directory structure (core, application, infrastructure, presentation layers). It's an AI-powered tool that integrates with GitHub and OpenAI/Azure OpenAI for code review purposes.

##### Main Components

A. External Services Layer:
- GitHub API (for pull request interaction)
- OpenAI/Azure OpenAI API (for AI review generation)

B. Application Layers (following clean architecture):
1. Presentation Layer:
- CLI Interface

2. Application Layer:
- Use Cases (PR comments, PR retrieval)
- Parsers (GitHub PR parser, LLM text parser)
- Text Splitters
- Tools (commenting functionality)

3. Core Layer:
- Domain Models (PR, Comments, Content)
- Prompt Templates

4. Infrastructure Layer:
- Review Agent
- GitHub Repository Implementation
- LLM Integration

- [External Services]
- ↕
- [Presentation Layer]
- ↕
- [Application Layer]
- ↕
- [Core Layer]
- ↕
- [Infrastructure Layer]

##### Specific Elements

a. Data Flow:
1. User input (PR URL) → CLI
2. CLI → Use Cases → GitHub Repository
3. GitHub Data → Parsers → Domain Models
4. Domain Models → Review Agent → LLM
5. Review Results → Comment Tool → GitHub

b. Key Components:
- Review_agent.py as a central orchestrator
- Parsing pipeline
- Demonstrate the text splitting process
- Comment generation and posting flow

##### Technical Details to Highlight

- LangChain integration points
- GitHub API interaction patterns
- Text processing pipeline
- Comment generation and posting mechanism

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph External["External Services"]
        direction TB
        GitHub["GitHub API"]:::external
        OpenAI["OpenAI/Azure OpenAI"]:::external
    end

    subgraph Present["Presentation Layer"]
        direction TB
        CLI["CLI Interface"]:::presentation
    end
    click CLI "https://github.com/Maokli/ReviewPal/blob/master/src/presentation/cli.py"

    subgraph App["Application Layer"]
        direction TB
        UseCases["Use Cases"]:::application
        subgraph Parsers["Parsers"]
            direction TB
            GHParser["GitHub PR Parser"]:::application
            LLMParser["LLM Text Parser"]:::application
        end
        subgraph Tools["Tools"]
            direction TB
            CommentTool["Comment Tool"]:::application
        end
        TextSplitter["PR File Splitter"]:::application
    end
    click UseCases "https://github.com/Maokli/ReviewPal/tree/master/src/application/use_cases"
    click GHParser "https://github.com/Maokli/ReviewPal/blob/master/src/application/parsers/github_pull_request_parser.py"
    click LLMParser "https://github.com/Maokli/ReviewPal/blob/master/src/application/parsers/llm_text_pull_request_parser.py"
    click CommentTool "https://github.com/Maokli/ReviewPal/blob/master/src/application/tools/add_comment_tool.py"
    click TextSplitter "https://github.com/Maokli/ReviewPal/blob/master/src/application/text_splitters/pull_request_file_text_splitter.py"

    subgraph Core["Core Layer"]
        direction TB
        subgraph Models["Domain Models"]
            direction TB
            PRModel["PR Model"]:::core
            CommentModel["Comment Model"]:::core
            LLMCommentModel["LLM Comment Model"]:::core
            PRFileModel["PR File Model"]:::core
            ContentModel["Content Model"]:::core
        end
        PromptTemplate["Review Prompt Template"]:::core
    end
    click PRModel "https://github.com/Maokli/ReviewPal/blob/master/src/core/models/pull_request.py"
    click CommentModel "https://github.com/Maokli/ReviewPal/blob/master/src/core/models/comment.py"
    click LLMCommentModel "https://github.com/Maokli/ReviewPal/blob/master/src/core/models/llm_comment.py"
    click PRFileModel "https://github.com/Maokli/ReviewPal/blob/master/src/core/models/pull_request_file.py"
    click ContentModel "https://github.com/Maokli/ReviewPal/blob/master/src/core/models/content_with_line.py"
    click PromptTemplate "https://github.com/Maokli/ReviewPal/blob/master/src/core/prompt_templates/review_prompt_template.py"

    subgraph Infra["Infrastructure Layer"]
        direction TB
        ReviewAgent["Review Agent"]:::infrastructure
        GHRepo["GitHub Repository Implementation"]:::infrastructure
    end
    click ReviewAgent "https://github.com/Maokli/ReviewPal/blob/master/src/infrastructure/agents/review_agent.py"
    click GHRepo "https://github.com/Maokli/ReviewPal/blob/master/src/infrastructure/repositories/github_repository.py"

    %% Relationships
    GitHub <--> GHRepo
    OpenAI <--> ReviewAgent
    CLI --> UseCases
    UseCases --> GHRepo
    GHRepo --> Parsers
    Parsers --> Models
    Models --> ReviewAgent
    ReviewAgent --> CommentTool
    CommentTool --> GitHub
    TextSplitter --> ReviewAgent
    PromptTemplate --> ReviewAgent

    %% Styles
    classDef external fill:#gray,stroke:#333,stroke-width:2px
    classDef presentation fill:#3498db,stroke:#2980b9,stroke-width:2px
    classDef application fill:#2ecc71,stroke:#27ae60,stroke-width:2px
    classDef core fill:#f1c40f,stroke:#f39c12,stroke-width:2px
    classDef infrastructure fill:#e67e22,stroke:#d35400,stroke-width:2px

    %% Legend
    subgraph Legend
        direction TB
        E[External Services]:::external
        P[Presentation Layer]:::presentation
        A[Application Layer]:::application
        C[Core Layer]:::core
        I[Infrastructure Layer]:::infrastructure
    end
```
