# ahsan-raza-sheikh/ai-based-code-reviewer architecture

> Architecture diagram of the GitHub repository ahsan-raza-sheikh/ai-based-code-reviewer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ahsan-raza-sheikh/ai-based-code-reviewer
- Repository: https://github.com/ahsan-raza-sheikh/ai-based-code-reviewer

## Overview

##### Project type and purpose
- This is a hybrid full-stack project composed of a VS Code extension (written in TypeScript/JavaScript) that provides AI-powered code-review capabilities, plus a standalone Python backend (FastAPI) that interfaces with Google Gemini.
- The extension invokes commands (review, refactor, documentation, real-time analysis) via the VS Code API and sends requests to the backend, which runs machine-learning logic and returns diagnostics, fixes, or documentation.

##### File structure
- Top level:
- package.json / tsconfig.json → VS Code extension manifest & TS config
- requirements.txt / backend/ → Python VirtualEnv + FastAPI service
- src/ → extension source (commands/, core/, providers/, services/, utils/)
- backend/api/server.py → FastAPI application entrypoint
- backend/services/analyzer.py → AI analysis logic
- test/ → integration & fixture tests
- Patterns:
- “commands → core → services → providers” reflects a command pattern layered atop a service layer, with language providers hooking into VS Code’s Diagnostic and CodeAction APIs.
- Backend is structured with clear separation: API endpoints vs. business logic vs. utility helpers.

##### README insights
- It describes two major sub-systems: the “Frontend VS Code Extension” and the “Python AI Backend.”
- Lists features (real-time analysis, auto-fix, refactor, docs generation, security, performance) driven by Google Gemini.
- Mentions configuration (API key, server URL) and dev workflows (npm scripts, uvicorn).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External User
    User["VS Code Host (User)"]:::external

    %% VS Code Extension Layer
    subgraph "VS Code Extension"
        subgraph "Core Extension"
            CoreExt["Core Extension"]:::frontend
        end
        subgraph "Commands"
            CmdMgr["Command Manager"]:::frontend
            RevCmd["Review Command"]:::frontend
            RefCmd["Refactor Command"]:::frontend
            DocCmd["Documentation Command"]:::frontend
            RTcmd["Real-Time Analysis Command"]:::frontend
        end
        subgraph "Providers"
            DiagProv["Diagnostic Provider"]:::frontend
            CodeActProv["Code Action Provider"]:::frontend
        end
        subgraph "Services & Utils"
            CodeSvc["Extension Service"]:::frontend
            Logger["Logger Utility"]:::frontend
        end
    end

    %% Python AI Backend Layer
    subgraph "Python AI Backend"
        subgraph "API Layer"
            API["FastAPI Server"]:::backend
            Main["Uvicorn Launcher"]:::backend
        end
        subgraph "AI Services"
            Analyzer["AI Analysis Service"]:::backend
        end
        subgraph "Backend Utils"
            BUt["Helpers"]:::backend
        end
    end

    %% External AI API
    Gemini["Google Gemini API"]:::external

    %% Test Suite
    subgraph "Test Suite"
        TestHarness["Test Harness"]:::test
        TestFixtures["Test Fixtures"]:::test
    end

    %% Flow of commands
    User -->|"trigger command"| CoreExt
    CoreExt -->|"activate & context"| CmdMgr
    CmdMgr --> RevCmd
    CmdMgr --> RefCmd
    CmdMgr --> DocCmd
    CmdMgr --> RTcmd
    RevCmd -->|"calls service"| CodeSvc
    RefCmd -->|"calls service"| CodeSvc
    DocCmd -->|"calls service"| CodeSvc
    RTcmd -->|"calls service"| CodeSvc
    CodeSvc -->|"HTTP POST /analyze"| API
    API -->|"delegate to"| Analyzer
    Analyzer -->|"call Google Gemini API"| Gemini
    Analyzer -->|"use helpers"| BUt
    Analyzer -->|"return JSON response"| API
    API -->|"JSON response"| CodeSvc
    CodeSvc -->|"provide diagnostics"| DiagProv
    CodeSvc -->|"provide code actions"| CodeActProv

    %% Test interactions
    TestHarness --> CodeSvc
    TestHarness --> API
    TestHarness --> TestFixtures

    %% Click Events
    click CoreExt "https://github.com/ahsan-raza-sheikh/ai-based-code-reviewer/blob/main/src/core/extension.js"
    click CmdMgr "https://github.com/ahsan-raza-sheikh/ai-based-code-reviewer/blob/main/src/commands/commandManager.js"
    click RevCmd "https://github.com/ahsan-raza-sheikh/ai-based-code-reviewer/blob/main/src/commands/reviewCommand.js"
    click RefCmd "https://github.com/ahsan-raza-sheikh/ai-based-code-reviewer/blob/main/src/commands/refactorCommand.js"
    click DocCmd "https://github.com/ahsan-raza-sheikh/ai-based-code-reviewer/blob/main/src/commands/documentationCommand.js"
    click RTcmd "https://github.com/ahsan-raza-sheikh/ai-based-code-reviewer/blob/main/src/commands/realtimeCommand.js"
    click DiagProv "https://github.com/ahsan-raza-sheikh/ai-based-code-reviewer/blob/main/src/providers/diagnosticProvider.js"
    click CodeActProv "https://github.com/ahsan-raza-sheikh/ai-based-code-reviewer/blob/main/src/providers/codeActionProvider.js"
    click CodeSvc "https://github.com/ahsan-raza-sheikh/ai-based-code-reviewer/blob/main/src/services/codeAnalysisService.js"
    click Logger "https://github.com/ahsan-raza-sheikh/ai-based-code-reviewer/blob/main/src/utils/logger.js"
    click API "https://github.com/ahsan-raza-sheikh/ai-based-code-reviewer/blob/main/backend/api/server.py"
    click Main "https://github.com/ahsan-raza-sheikh/ai-based-code-reviewer/blob/main/backend/main.py"
    click Analyzer "https://github.com/ahsan-raza-sheikh/ai-based-code-reviewer/blob/main/backend/services/analyzer.py"
    click BUt "https://github.com/ahsan-raza-sheikh/ai-based-code-reviewer/blob/main/backend/utils/helpers.py"
    click TestHarness "https://github.com/ahsan-raza-sheikh/ai-based-code-reviewer/blob/main/test/test_comprehensive.js"
    click TestFixtures "https://github.com/ahsan-raza-sheikh/ai-based-code-reviewer/tree/main/test/fixtures/"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,stroke-width:1px
    classDef backend fill:#DFFFE0,stroke:#28a745,stroke-width:1px
    classDef external fill:#FFE0B2,stroke:#ff8c00,stroke-width:1px
    classDef test fill:#F0F0F0,stroke:#888888,stroke-width:1px
```
