# shreyaprasad1209/pr-review-tone-assistant architecture

> Architecture diagram of the GitHub repository shreyaprasad1209/pr-review-tone-assistant, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shreyaprasad1209/pr-review-tone-assistant
- Repository: https://github.com/shreyaprasad1209/pr-review-tone-assistant

## Overview

##### Project Type and Purpose
a. This is a hybrid full-stack application consisting of:
- A Chrome browser extension (frontend) that hooks into GitHub’s PR UI.
- A standalone Express.js server (backend) that proxies requests to the OpenRouter AI service.
b. Purpose: Capture user input in real-time during PR reviews, send it to an AI service for tone rewriting, and display constructive suggestions inline.

##### File Structure
Top-level layout:
- .github – Issue templates
- backend/
– server.js (Express server entry point)
– .env (holds OPENROUTER_API_KEY)
– package.json, node_modules
- frontend/
– manifest.json (Chrome extension metadata)
– content.js (content script injected into GitHub pages)
– styles.css (UI styling)
- README.md – high-level overview, setup, usage

Architectural hints:
- Clear separation of “frontend” (browser extension UI + content script) vs. “backend” (API server).
- No database—stateless proxy.
- External dependency: OpenRouter AI API.

##### Extract Key Insights from the README
- Frontend: content script monitors typing, triggers suggestion fetch after a pause.
- Backend: exposes an endpoint (e.g. POST /rewrite) that calls OpenRouter with the user text and API key.

##### Main Components
1) Browser (Chrome)
- GitHub PR page UI
- Chrome Extension (background/popup not used here—only content script)
2) Content Script (frontend/content.js + styles.css + manifest.json)
- Throttles/debounces input (3-second pause)
- Sends HTTP request to backend
- Receives rewritten text and injects suggestion UI
3) Backend Server (backend/server.js on Node.js + Express)
- Single endpoint to receive text
- Reads OPENROUTER_API_KEY from .env
- Forwards request to OpenRouter API
- Returns AI-rewritten comments
4) External AI Service (OpenRouter API)
- Hosts the language model
- Processes text and returns suggestions

##### Architectural Patterns and Principles
- Single Responsibility: frontend only handles UI/interactions; backend only handles AI requests.
- Event-driven: the extension reacts to typing events and idle pauses.
- Proxy pattern: backend acts as a proxy to hide API key from the client.
- Stateless server: no persistence layer, simplifies scaling.

##### Technologies and Frameworks
- Frontend: JavaScript, Chrome Extension Manifest V3, content scripts, CSS
- Backend: Node.js, Express.js, dotenv
- External: OpenRouter AI REST API

## Diagram (Mermaid)

```mermaid
graph TD
    %% Swimlane: Browser/Extension
    subgraph "Browser/Extension" 
        direction TB
        BrowserUI["GitHub PR Page UI"]:::frontend
        Manifest["manifest.json"]:::frontend
        ContentScript["content.js<br/>(3s debounce)"]:::frontend
        Styles["styles.css"]:::frontend
    end

    %% Swimlane: Backend
    subgraph "Backend Server" 
        direction TB
        Env[".env<br/>(OPENROUTER_API_KEY)"]:::backend
        Package["package.json"]:::backend
        Server["server.js<br/>(Express.js)"]:::backend
    end

    %% External AI Service
    OpenRouter("OpenRouter AI API"):::external

    %% Connections / Data Flows
    ContentScript -->|A: HTTP POST| Server
    Server -->|B: HTTP POST| OpenRouter
    OpenRouter -->|C: JSON response| Server
    Server -->|D: JSON response| ContentScript
    ContentScript -->|E: DOM injection| BrowserUI

    %% Documentation and Templates
    README["README.md"]:::docs
    BugTemplate["bug_report.md"]:::docs
    FeatureTemplate["feature_request.md"]:::docs

    %% Click Events
    click Manifest "https://github.com/shreyaprasad1209/pr-review-tone-assistant/blob/main/frontend/manifest.json"
    click ContentScript "https://github.com/shreyaprasad1209/pr-review-tone-assistant/blob/main/frontend/content.js"
    click Styles "https://github.com/shreyaprasad1209/pr-review-tone-assistant/blob/main/frontend/styles.css"
    click Server "https://github.com/shreyaprasad1209/pr-review-tone-assistant/blob/main/backend/server.js"
    click Package "https://github.com/shreyaprasad1209/pr-review-tone-assistant/blob/main/backend/package.json"
    click Env "https://github.com/shreyaprasad1209/pr-review-tone-assistant/blob/main/backend/.env"
    click README "https://github.com/shreyaprasad1209/pr-review-tone-assistant/blob/main/README.md"
    click BugTemplate "https://github.com/shreyaprasad1209/pr-review-tone-assistant/blob/main/.github/ISSUE_TEMPLATE/bug_report.md"
    click FeatureTemplate "https://github.com/shreyaprasad1209/pr-review-tone-assistant/blob/main/.github/ISSUE_TEMPLATE/feature_request.md"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#4d90fe,color:#000;
    classDef backend fill:#d4edda,stroke:#28a745,color:#000,shape:rect;
    classDef external fill:#f8d7da,stroke:#dc3545,color:#000,shape:cloud;
    classDef docs fill:#fff3cd,stroke:#856404,color:#000;
```
