# tusgino/llm-code-reviewer architecture

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

- Interactive diagram: https://gitdiagram.com/tusgino/llm-code-reviewer
- Repository: https://github.com/tusgino/llm-code-reviewer

## Overview

##### Main Components
- GitHub Integration: Include a component labeled “GitHub Actions Workflow” that shows the triggering of the review process on pull request events. This represents the .github/workflows and overall action trigger.
- Core Application: A “Main Application” component (from src/main.py) that orchestrates the review process.
- Core Modules:
- “Core Config & Models” (src/core/config.py and src/core/models.py) – Handles configuration settings and data models.
- “Services” – This component further divides into:
- “AI Service” (src/services/ai_service.py): Central logic for handling code review using LLMs.
- “GitHub Service” (src/services/github_service.py): Handles interactions with GitHub (e.g., posting comments back to PRs).
- “LLM Integrations” (src/services/llms/): Contains specific adapters for each LLM provider (openai.py, gemini.py, anthropic.py) with a base class for common interfaces (base.py).
- Libraries & Utilities:
- “Libraries Module” (src/libs) – e.g., Hunk parsing (Hunk.py) for code differences.
- “Utilities” (src/utils) – Include components for parsing diffs (diff_parser.py), analyzing code (code_analyzer.py), and language validation (language_validator.py).

##### Relationships & Interactions
- Within the “AI Service” component, show that it delegates to specific LLM integrations (OpenAI, Gemini, Anthropic) using the “LLM Integrations” module. This abstraction allows switching between LLMs based on configuration inputs.
- The “Core Config & Models” component should interact with both services, providing configuration details (like model selection and API keys) and handling the abstraction of data used across modules.
- The “Libraries” and “Utilities” components should be linked to the “Main Application” and “AI Service” as they provide necessary support for analyzing code changes (diffs, language info) and preparing inputs for reviews.

##### Architectural Patterns & Design Principles
- Service Abstraction: Emphasize the modular design of the LLM integrations where a base interface allows multiple model implementations.
- Configuration Driven: Highlight that configurations (API keys, model selections, file exclusion patterns, etc.) are supplied centrally via configuration files (e.g., src/core/config.py) and via the action’s inputs.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Integration Layer
    A["GitHub Actions Workflow"]:::integration

    %% Middleware Application Layer
    B["Main Application"]:::business
    C["Core Config & Models"]:::business
    D["AI Service"]:::service
    E["GitHub Service"]:::service

    %% LLM Integrations Subgraph
    subgraph "LLM Integrations"
        F["Base LLM Interface"]:::adapter
        G["OpenAI Adapter"]:::adapter
        H["Gemini Adapter"]:::adapter
        I["Anthropic Adapter"]:::adapter
    end

    %% Supporting Libraries and Utilities Layer
    J["Libraries Module"]:::support
    K["Utilities"]:::support

    %% Relationships & Data Flow
    A -->|"triggers"| B
    B -->|"loadsConfig"| C
    B -->|"orchestrates"| D
    B -->|"handlesComments"| E
    C -->|"providesConfig"| D
    C -->|"providesConfig"| E
    D -->|"delegatesTo"| F
    D -->|"delegatesTo"| G
    D -->|"delegatesTo"| H
    D -->|"delegatesTo"| I
    B -->|"utilizes"| J
    D -->|"utilizes"| K

    %% Supporting connection between libraries and utilities (for code analysis)
    J -->|"assists"| K

    %% Click Events for Component Mapping
    click A "https://github.com/tusgino/llm-code-reviewer/blob/develop/.github/workflows/review.yml"
    click B "https://github.com/tusgino/llm-code-reviewer/blob/develop/src/main.py"
    click C "https://github.com/tusgino/llm-code-reviewer/blob/develop/src/core/config.py"
    click C "https://github.com/tusgino/llm-code-reviewer/blob/develop/src/core/models.py"
    click D "https://github.com/tusgino/llm-code-reviewer/blob/develop/src/services/ai_service.py"
    click E "https://github.com/tusgino/llm-code-reviewer/blob/develop/src/services/github_service.py"
    click F "https://github.com/tusgino/llm-code-reviewer/blob/develop/src/services/llms/base.py"
    click G "https://github.com/tusgino/llm-code-reviewer/blob/develop/src/services/llms/openai.py"
    click H "https://github.com/tusgino/llm-code-reviewer/blob/develop/src/services/llms/gemini.py"
    click I "https://github.com/tusgino/llm-code-reviewer/blob/develop/src/services/llms/anthropic.py"
    click J "https://github.com/tusgino/llm-code-reviewer/tree/develop/src/libs/"
    click J "https://github.com/tusgino/llm-code-reviewer/blob/develop/src/libs/Hunk.py"
    click K "https://github.com/tusgino/llm-code-reviewer/tree/develop/src/utils/"
    click K "https://github.com/tusgino/llm-code-reviewer/blob/develop/src/utils/diff_parser.py"
    click K "https://github.com/tusgino/llm-code-reviewer/blob/develop/src/utils/code_analyzer.py"
    click K "https://github.com/tusgino/llm-code-reviewer/blob/develop/src/utils/language_validator.py"

    %% Styles for clarity and color coding
    classDef integration fill:#ffecb3,stroke:#333,stroke-width:2px;
    classDef business fill:#bbdefb,stroke:#333,stroke-width:2px;
    classDef service fill:#c8e6c9,stroke:#333,stroke-width:2px;
    classDef adapter fill:#f8bbd0,stroke:#333,stroke-width:2px;
    classDef support fill:#b2dfdb,stroke:#333,stroke-width:2px;
```
