# murtuzaalisurti/better architecture

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

- Interactive diagram: https://gitdiagram.com/murtuzaalisurti/better
- Repository: https://github.com/murtuzaalisurti/better

## Overview

##### Project type and purpose
- This is an open-source GitHub Action (a reusable automation component) written in Node.js.
- Its purpose is to run on pull_request events, call an external AI service to review code, and post feedback back to the PR.

##### File structure
- Top level:
- action.yml – Action metadata (inputs, outputs, runs-on, main entrypoint)
- index.js – Entrypoint in source (used in dev), which is bundled into dist/
- dist/ – Transpiled, production-ready JS that the Action actually runs
- utils/ – Shared code (constants, types) used by index.js
- assets/ – Images for documentation
- .github/ – Contains any workflow templates (not this repo’s workflows)
- Packaging: package.json defines dependencies; build step compiles source into dist/.

##### Extract architectural insights from README
- Trigger: on pull_request events (opened, synchronized, etc.)
- Inputs: repo-token, ai-model-api-key, platform, rules, filesToIgnore, etc.
- Flow: GitHub CI → Action code (Node) → AI platform API → GitHub REST API to post a review

##### Main components
a. Developer Repository
- .github/workflows/your-workflow.yml (defines “uses: murtuzaalisurti/better@v3”)
- Secrets: GITHUB_TOKEN, MODEL_API_KEY
b. GitHub Actions Service
- Receives the pull_request event and spins up a runner
c. GitHub Actions Runner (VM/Container)
- Checks out code
- Installs action code (dist/ + node_modules)
- Executes Action (dist/index.js)
d. Action Code (Node.js)
- utils/constants.js, utils/types.js
- business logic: read changed files, filter by glob, assemble prompt, call AI
e. External AI Platform(s)
- OpenAI, Anthropic, Google Gemini, Mistral, OpenRouter
- Receives prompt, returns suggestions
f. GitHub REST API
- Used by Action to delete old reviews and post new comments

##### Architectural patterns & design principles
- Event-driven architecture: reacts to GitHub events
- Modular code: utils folder for constants/types, single entrypoint in index.js
- External service integration: pluggable AI platform via the `platform` input
- Idempotency: deletes previous bot review before posting new comments

##### Essential elements to capture
- Inputs (repo-token, secrets) flowing into Runner
- Decision logic for ignoring files (glob filter)
- Retry logic on AI failures (max-retries)
- Deletion of previous bot reviews (delete-existing-review-by-bot)

##### Final advice
- Be detailed but keep it high-level: group related modules under “Action Code”
- Event flows and data flows
- Component with key technologies: Node.js, micromatch, GitHub Actions, OpenAI API

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer repository
    subgraph "Developer Repository"
        WF[".github/workflows/your-workflow.yml"]:::developer
        AM["action.yml"]:::developer
        PKG["package.json"]:::developer
        ASSETS["assets/"]:::developer
    end

    %% GitHub Actions service
    GAS["GitHub Actions Service"]:::github

    %% Runner
    S["Runner (VM/Container)"]:::github

    %% Action Code
    subgraph "Action Code"
        DEV["index.js"]:::developer
        UT1["utils/constants.js"]:::developer
        UT2["utils/types.js"]:::developer
        PRODB["dist/index.js"]:::developer
    end

    %% Transpiled Bundle artifacts
    subgraph "Transpiled Bundle"
        DPJSON["dist/package.json"]:::developer
        DL["dist/licenses.txt"]:::developer
    end

    %% External AI Platforms
    EP["External AI Platforms\n(OpenAI, Anthropic,\nGoogle Gemini, Mistral, OpenRouter)"]:::ai

    %% GitHub REST API
    GAPI["GitHub REST API"]:::github

    %% Flows
    WF -->|triggers pull_request| GAS
    GAS -->|spin up runner| S
    S -->|checkout & setup| DEV
    DEV -->|bundles into| PRODB
    S -->|executes| PRODB
    PRODB -->|loads| UT1
    PRODB -->|loads| UT2
    PRODB -->|POST /v1/chat/completions| EP
    EP -->|AI response| PRODB
    PRODB -->|DELETE /repos/:owner/:repo/pulls/:pr/reviews| GAPI
    PRODB -->|POST /repos/:owner/:repo/pulls/:pr/reviews| GAPI

    %% Click events
    click AM "https://github.com/murtuzaalisurti/better/blob/main/action.yml"
    click DEV "https://github.com/murtuzaalisurti/better/blob/main/index.js"
    click PRODB "https://github.com/murtuzaalisurti/better/blob/main/dist/index.js"
    click DPJSON "https://github.com/murtuzaalisurti/better/blob/main/dist/package.json"
    click DL "https://github.com/murtuzaalisurti/better/blob/main/dist/licenses.txt"
    click UT1 "https://github.com/murtuzaalisurti/better/blob/main/utils/constants.js"
    click UT2 "https://github.com/murtuzaalisurti/better/blob/main/utils/types.js"
    click ASSETS "https://github.com/murtuzaalisurti/better/tree/main/assets/"
    click PKG "https://github.com/murtuzaalisurti/better/blob/main/package.json"

    %% Styles
    classDef developer fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef github fill:#D4F8E8,stroke:#28A745,color:#28A745;
    classDef ai fill:#FFE8A1,stroke:#F29D38,color:#F29D38;
```
