MCPcopy Index your code
hub / github.com/Mihir2423/ai-code-review-system

github.com/Mihir2423/ai-code-review-system @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
298 symbols 687 edges 91 files 0 documented · 0% updated 2mo ago★ 381 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

AI Code Review System

A monorepo for automated code review using AI.

Data Flows

1. When a User Installs the Bot to a Repository

sequenceDiagram
    participant User
    participant GitHub
    participant Web as apps/web
    participant WS as services/webhook-service
    participant DB as packages/db
    participant RI as services/repo-indexer

    User->>Web: User initiates GitHub App installation
    Web->>GitHub: Redirect to GitHub OAuth
    GitHub->>Web: OAuth callback with installation token
    Note over Web,GitHub: User selects repositories to install

    GitHub->>WS: Webhook: installation created
    WS->>DB: Create installation record
    DB-->>WS: Installation created

    loop For each repository
        WS->>DB: Upsert repository
        WS->>DB: Upsert RepositoryBranch (default branch)
        WS->>DB: Create RepoIndexingJob (status: pending)
    end

    WS->>RI: Add job to repo-index queue (with branchId, jobId)
    RI->>DB: Update job status to "processing"
    RI->>DB: Update branch indexingStatus to "indexing"
    RI->>GitHub: Fetch repository files
    RI->>RI: Filter excluded files (package.json, images, binaries, etc.)
    RI->>RI: Compute file hash (SHA-256)
    RI->>RI: Chunk large files (500 lines, 50 overlap)
    RI->>DB: Create/update IndexedFile records
    RI->>DB: Create FileChunk records with embeddings
    RI->>RI: Store vectors in Pinecone
    RI->>DB: Update job status to "completed"
    RI->>DB: Update branch indexingStatus to "indexed"

2. Repository Indexing Flow (Detailed)

flowchart TD
    A[Start Indexing Job] --> B{Job already processing?}
    B -->|Yes| C[Skip - avoid duplicates]
    B -->|No| D[Update job status: processing]
    D --> E[Update branch indexingStatus: indexing]
    E --> F[Fetch files from GitHub]
    F --> G[Filter excluded files]
    G --> H{For each file}
    H --> I{File exists in DB?}
    I -->|Yes| J{Hash changed?}
    J -->|No| K[Skip - file unchanged]
    J -->|Yes| L[Delete old chunks, re-index]
    I -->|No| M[Create new IndexedFile]
    M --> N[Chunk file content]
    N --> O[Generate embeddings]
    O --> P[Create FileChunk records]
    P --> Q[Upsert vectors to Pinecone]
    Q --> R{More files?}
    R -->|Yes| H
    R -->|No| S{Any failures?}
    S -->|Yes| T[Update job status: pending, schedule retry]
    S -->|No| U[Update job status: completed]
    U --> V[Update branch indexingStatus: indexed]

3. When a User Raises a Pull Request

sequenceDiagram
    participant User
    participant GitHub
    participant WS as services/webhook-service
    participant DB as packages/db
    participant PP as services/pr-processor
    participant RI as services/repo-indexer
    participant AIR as services/ai-review-worker

    User->>GitHub: Creates/opens PR
    GitHub->>WS: Webhook: pull_request opened

    WS->>DB: Find repository
    DB-->>WS: Repository found
    WS->>PP: Add job to pr-review queue

    PP->>GitHub: Get PR details & diff
    PP->>DB: Create review record (status: pending)
    PP->>RI: Add job to pr-context queue
    PP->>PP: Add job to pr-comment (initial comment)

    PP->>GitHub: Post "processing" comment

    RI->>RI: Fetch similar code from vector store
    RI->>AIR: Add job to pr-ai-review queue

    AIR->>AIR: Generate AI code review
    AIR->>DB: Update review record (status: completed)
    AIR->>PP: Add job to pr-issues queue
    AIR->>PP: Add job to pr-comment (summary)

    PP->>GitHub: Post inline comments for each issue
    PP->>GitHub: Post summary comment

Indexing Features

File Filtering

The repo-indexer automatically excludes:

  • Package files: package.json, package-lock.json, yarn.lock, pnpm-lock.yaml
  • Binary assets: Images (.png, .jpg, .gif, .svg, .webp), Videos, PDFs
  • Build artifacts: node_modules, dist, build, .next, .nuxt
  • Minified files: .min.js, .min.css, .map
  • System files: .DS_Store, Thumbs.db

Chunking Strategy

  • Chunk size: 500 lines
  • Overlap: 50 lines (for context continuity)
  • Each chunk gets its own embedding stored in FileChunk table

Retry Mechanism

  • Retryable errors: Rate limits, quota exceeded
  • Max retries: 3
  • Backoff: Exponential (60s, 120s, 240s)
  • Failed jobs are marked as pending and retried automatically

Diff-Based Indexing (Production Optimization)

The system uses intelligent diff-based indexing to avoid full re-indexing:

Branch Create Event:

  • If base branch is indexed → mark new branch as indexed (no job)
  • If base branch not indexed → trigger full indexing

Push Event:

  • Compare before (old commit SHA) vs after (new commit SHA)
  • If identical → skip indexing
  • If different → create diff-based job with baseCommitSha + headCommitSha

Worker Logic:

  • Uses GitHub Compare API: GET /repos/{owner}/{repo}/compare/{base}...{head}
  • Only fetch changed files (added, modified, removed)
  • Skip unchanged files via hash comparison
  • Delete removed files from index

Edge Cases Handled:

  • Force push → fallback to full indexing
  • First commit (no base) → fallback to full indexing
  • Large diff (500+ files) → fallback to full indexing

What's inside?

Apps and Packages

  • apps/web: a Next.js app
  • apps/server: a Node.js API server
  • packages/ai: AI utilities shared across services
  • packages/config: shared configuration
  • packages/db: Prisma database client
  • packages/kafka: Kafka utilities
  • packages/logger: logging utility shared across services
  • packages/redis: Redis client
  • packages/types: shared TypeScript types
  • services/ai-review-worker: AI review worker service
  • services/pr-processor: PR processor and GitHub comment service
  • services/repo-indexer: Repository indexing service
  • services/webhook-service: Webhook service

Each package/app is 100% TypeScript.

Utilities

Build

To build all apps and packages, run the following command:

pnpm build

Develop

To develop all apps and packages, run the following command:

pnpm dev

You can develop a specific package by using a filter:

pnpm dev --filter=web
pnpm dev --filter=ai-review-worker

Roadmap - Feature Parity with CodeRabbit

Already Implemented ✅

  • PR webhook handling
  • Repository indexing with Pinecone vector store
  • AI code review generation (Gemini)
  • Inline comments + summary with walkthrough, sequence diagrams, poem
  • GitHub Check Run integration
  • Real-time streaming (SSE)
  • Dashboard with review history
  • Repository management page

Todo List - Missing Features

  • [ ] Chat/Conversation - Chat interface for follow-up questions about code
  • [x] Auto-PR description - Automatically generate PR descriptions
  • [ ] Custom review rules - Configurable rules (security, performance, best practices)
  • [ ] Accept/Reject UI - Dashboard to accept AI suggestions directly
  • [ ] Security-specific scanning - Dedicated vulnerability detection
  • [ ] Test generation - Suggest or generate tests
  • [ ] Code explanation - Ask for explanations of specific code sections
  • [ ] Review automation rules - Configure when to auto-review (labels, paths, authors)
  • [ ] Team/Organization management - Multi-tenant support
  • [ ] Billing/Subscription - Monetization features
  • [ ] API for external access - Programmatic integrations
  • [x] Review analytics - Statistics on review patterns
  • [ ] File deep-dive view - Detailed per-file review UI in dashboard
  • [ ] Commit-level analysis - Analyze individual commits (beyond just PRs)
  • [ ] Notification preferences - Granular alert settings

Extension points exported contracts — how you extend this code

RepoStats (Interface)
(no doc)
packages/types/src/github.ts
ReviewEventMessage (Interface)
(no doc)
packages/queue/src/events.ts
ReviewIssue (Interface)
(no doc)
packages/ai/src/index.ts
PaginatedRepositories (Interface)
(no doc)
apps/server/src/modules/github/service.ts
MessageBranchContextType (Interface)
(no doc)
apps/web/components/ai-elements/message.tsx
RepoIndexMessage (Interface)
(no doc)
services/repo-indexer/src/index.ts
AIReviewMessage (Interface)
(no doc)
services/ai-review-worker/src/index.ts
PRReviewMessage (Interface)
(no doc)
services/pr-processor/src/index.ts

Core symbols most depended-on inside this repo

cn
called by 62
apps/web/lib/utils.ts
withContent
called by 22
apps/server/src/utils/response-helpers.ts
withMessage
called by 22
apps/server/src/utils/response-helpers.ts
build
called by 22
apps/server/src/utils/response-helpers.ts
createQueue
called by 11
packages/queue/src/index.ts
addJob
called by 9
packages/queue/src/index.ts
clamp
called by 7
apps/web/components/globals/dither-image.tsx
createWorker
called by 6
packages/queue/src/index.ts

Shape

Function 227
Interface 44
Method 19
Class 8

Languages

TypeScript100%

Modules by API surface

apps/web/components/ui/sidebar.tsx25 symbols
apps/web/app/(root)/review-history/[id]/_components/review-content.tsx17 symbols
apps/server/src/utils/response-helpers.ts17 symbols
services/pr-processor/src/index.ts14 symbols
apps/web/components/ai-elements/message.tsx13 symbols
services/ai-review-worker/src/index.ts12 symbols
packages/kafka/src/index.ts11 symbols
services/repo-indexer/src/lib/github.ts10 symbols
apps/web/components/ui/sheet.tsx10 symbols
apps/web/components/ui/dialog.tsx10 symbols
apps/web/lib/review.ts9 symbols
services/repo-indexer/src/lib/embedding.ts7 symbols

Datastores touched

postgresDatabase · 1 repos

For agents

$ claude mcp add ai-code-review-system \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page