karthik.dev
Back to projects
AI

AI Code Reviewer

GitHub-integrated AI code review bot that comments on PRs with actionable feedback

TypeScriptNode.jsGitHub APIGemini AIWebhooksExpress.js

Overview

A GitHub App that listens for pull request events via webhooks, fetches the diff, sends each changed file to Gemini AI for review, and posts structured inline comments directly on the PR — covering code quality, security, performance, and test coverage gaps.

Problem

Code review is one of the highest-leverage activities in software engineering, but reviewers are limited in time and attention. An AI reviewer can do a first pass for mechanical issues — leaving human reviewers to focus on design and intent.

Solution

A GitHub App registered with `pull_request` webhook events. On each PR, the app fetches the diff, chunks it by file, sends each chunk to Gemini with a structured review prompt, parses the structured feedback, and posts inline PR comments via the GitHub REST API.

Architecture

  1. 1GitHub App webhook receiver validates HMAC signatures and processes `pull_request.opened/synchronize` events
  2. 2Diff fetcher retrieves the full PR diff via GitHub API
  3. 3File-level chunking with context assembly for each changed file
  4. 4Gemini AI review with structured output: issues, severity, line references, suggestions
  5. 5GitHub Review API posts inline comments at the specific diff lines referenced in AI feedback
  6. 6Summary comment posted as a PR review with aggregate findings

Technical Challenges

  • GitHub's diff format requires careful parsing to map AI-referenced line numbers back to the correct diff position for inline comments.
  • Keeping review feedback actionable rather than verbose — prompt engineering to force concise, specific suggestions with code examples.
  • Handling large PRs that exceed context window limits by prioritizing the most changed/complex files.

Results

  • Functional GitHub App deployable to any repository as a reviewer bot.
  • Reduces trivial review comments (formatting, obvious bugs, missing error handling) by automating the first-pass review.