Autonomous, enterprise-grade AI code review engine for GitHub Pull Requests and local project repositories.
Detects logic bugs, security vulnerabilities, leaked secrets, and syntax errors with 100% real Abstract Syntax Tree (AST) validation, verified diff bounds, and an interactive VS Code-style Review Studio.
- Overview
- Key Features
- System Architecture
- Tech Stack & Verified Versions
- Prerequisites
- Environment Variables
- Installation & Local Setup
- Running Automated Tests & Quality Checks
- Repository Configuration (.prreview.yml)
- API Endpoints Reference
- Directory Structure
- Troubleshooting & FAQs
- License
Code reviews consume substantial engineering hours, yet critical syntax bugs, edge-case regressions, and leaked API keys frequently slip into production.
PR Review AI provides an end-to-end, multi-stage automated review pipeline:
- Event Ingestion: Ingests GitHub webhook events (
pull_request.opened,synchronize,reopened) with constant-time HMAC-SHA256 signature verification and delivery idempotency. - Multi-Stage Static Analysis: Scans patches for high-entropy secrets, known security vulnerabilities (SQLi, command injection, path traversal, ReDoS), and code quality smells without invoking LLMs.
- Real AST Syntax Validation: Validates Python Abstract Syntax Trees (
ast.parse) and syntax constructs to catch syntax errors (trailing dots, incomplete expressions, unbalanced syntax) with AST validation. - Context-Aware AI Review: Dispatches filtered code diffs to Google Gemini Flash (
gemini-2.5-flash,gemini-2.0-flash) using strict JSON schemas and diff boundary checks. - Inline Publishing & Web Studio: Posts structured review summaries and line-by-line comments directly to GitHub PRs and streams interactive diffs to a Next.js 16 Review Studio dashboard.
- π‘οΈ 100% Real AST Syntax Verification: Real Python
ast.parsechecks syntax integrity before and after suggested patches, eliminating invalid syntax and verifying diff bounds. - π¨ Interactive Review Studio: Next.js 16 dashboard with red-highlighted error lines, green corrected lines, side-by-side file inspection, and one-click code copying.
- π VS Code-Style File Explorer:
- Full tree view with automatic file detection across 30+ languages (Python, TypeScript, JavaScript, SQL, Rust, Go, Java, Dockerfile, YAML, etc.).
- Dynamic language badges and colored icons.
- Inline file renaming directly from the dashboard sidebar (
Enterto commit,Escto cancel).
- π Automated Secrets & Vulnerability Scanner:
- Pre-merge regex pattern scanner for AWS, GitHub, Stripe, OpenAI, Gemini, and generic bearer tokens.
- Automatic masking of detected secret values in logs and dashboard reports.
- Prevents secret-bearing files from being sent to external LLM APIs.
- β‘ Distributed Task Queue: Decoupled FastAPI API layer with Celery workers backed by Redis for asynchronous review execution, time limits, and retries.
- π’ Multi-Tenant Isolation: Constant-time token comparisons, encrypted credentials via AES-256-GCM, and strictly isolated account resources returning
404 Not Foundfor unauthorized tenant access. - βοΈ Custom Team Rules: Configure repository-level review behavior via
.prreview.yml(path ignore rules, severity thresholds, custom team conventions).
flowchart TD
%% Styling Definitions
classDef client fill:#FAFAFA,stroke:#26D67C,stroke-width:2px,color:#1A1A1A,rx:10,ry:10;
classDef gateway fill:#FFFFFF,stroke:#26D67C,stroke-width:2px,color:#1A1A1A,rx:10,ry:10;
classDef queue fill:#F5F5F5,stroke:#6B6B6B,stroke-width:2px,color:#1A1A1A,stroke-dasharray: 4 4,rx:8,ry:8;
classDef worker fill:#FFFFFF,stroke:#26D67C,stroke-width:3px,color:#1A1A1A,rx:12,ry:12;
classDef engine fill:#FAFAFA,stroke:#26D67C,stroke-width:1.5px,color:#1A1A1A,rx:6,ry:6;
classDef storage fill:#FAFAFA,stroke:#6B6B6B,stroke-width:2px,color:#1A1A1A,rx:8,ry:8;
classDef output fill:#26D67C,stroke:#1A1A1A,stroke-width:1.5px,color:#FFFFFF,rx:10,ry:10;
%% Nodes
GH["π GitHub PR / Webhook Event"]:::client
API["β‘ FastAPI Webhook Gateway<br/><code>HMAC-SHA256 β’ Idempotency β’ 5MB Cap</code>"]:::gateway
REDIS[("π¬ Redis Message Broker<br/><code>Celery Queue</code>")]:::queue
subgraph WORKER_CLUSTER ["π οΈ Distributed Celery Worker Cluster"]
W["π Review Pipeline Orchestrator"]:::worker
S1["π File Filter & Cap Enforcer<br/><i>Ignore lockfiles, binaries, & limits</i>"]:::engine
S2["π‘οΈ Secret & Security Scanner<br/><i>Pre-merge regex & token mask</i>"]:::engine
S3["π² 100% Real Python AST Parser<br/><i>Syntax validation & auto-fix</i>"]:::engine
S4["π€ Google Gemini Flash LLM<br/><i>Strict JSON schema & diff bounds</i>"]:::engine
S5["π Severity Ranking & Deduplicator<br/><i>Fingerprint hashing & risk scoring</i>"]:::engine
W --> S1 --> S2 --> S3 --> S4 --> S5
end
PG[("πΎ PostgreSQL 16 DB<br/><code>Reviews β’ Metrics β’ Findings</code>")]:::storage
OUT_GH["π¬ GitHub Check Runs & Inline Diff Comments"]:::output
STUDIO["π» Next.js 16 Review Studio Dashboard"]:::output
%% Connections
GH -->|"1. Webhook POST"| API
API -->|"2. Enqueue Job"| REDIS
REDIS -->|"3. Consume Task"| W
S5 -->|"4. Post Review & Checks"| OUT_GH
S5 -->|"5. Store Results"| PG
PG -->|"6. Query Analytics & History"| STUDIO
linkStyle default stroke:#26D67C,stroke-width:2px;
sequenceDiagram
autonumber
actor Dev as π¨βπ» Developer
participant GH as π GitHub
participant API as β‘ FastAPI Gateway
participant Redis as π¬ Redis
participant Celery as βοΈ Celery Worker
participant AST as π² AST & Static Analyzers
participant Gemini as π€ Google Gemini Flash
participant DB as πΎ PostgreSQL
participant Studio as π» Next.js Studio
Dev->>GH: Open / Synchronize Pull Request
GH->>API: POST /api/v1/webhooks/github (HMAC Signature)
Note over API: Verify constant-time HMAC-SHA256 & Delivery ID
API->>Redis: Enqueue review task
API-->>GH: HTTP 202 Accepted (Instant response)
Redis->>Celery: Dispatch background review task
Celery->>AST: 1. Filter files, scan secrets & parse Python AST
alt Syntax error or secret found
AST-->>Celery: Real syntax error with candidate patch
end
Celery->>Gemini: 2. Request structured AI review (JSON Schema)
Gemini-->>Celery: Structured findings & risk breakdown
Note over Celery: 3. Verify finding lines fall strictly inside diff
Celery->>GH: 4. Post unified inline review comments & check runs
Celery->>DB: 5. Persist review metadata & findings
Studio->>DB: 6. Real-time fetch for interactive side-by-side inspection
| Component | Technology | Verified Version | Purpose |
|---|---|---|---|
| Backend API | FastAPI | 0.136.0+ |
High-performance asynchronous REST API, OpenAPI docs |
| ASGI Server | Uvicorn | 0.34.0+ |
Fast ASGI server with standard worker support |
| Data Validation | Pydantic v2 | 2.10.0+ |
Request schemas, environment settings, and data validation |
| Worker Queue | Celery | 5.4.0+ |
Distributed task execution with retry exponential backoff |
| Message Broker | Redis | 7.x |
Message queue for Celery and high-speed delivery deduplication |
| Database | PostgreSQL | 16.x |
Relational persistence with SQLAlchemy 2.0 and Alembic |
| AI / LLM | Google GenAI SDK | 1.0.0+ |
Gemini Flash models (gemini-2.5-flash, gemini-2.0-flash) |
| Syntax Analyzer | Python Standard Library | ast |
Native Abstract Syntax Tree validation |
| Frontend Framework | Next.js | 16.3.8 (App Router) |
React Server Components, Turbopack, and API routing |
| UI Library | React | 19.2.8 |
Component rendering and client state management |
| Styling | Tailwind CSS | 4.3.3 |
Utility-first responsive design and dark theme styling |
| Frontend Types | TypeScript | 5.x |
Strict type safety across UI components and client hooks |
| Testing | Pytest & Vitest | pytest 8.3+ / vitest 5.0+ |
Unit tests, integration tests, and type checking |
Ensure the following tools are installed in your environment:
- Python:
3.12or3.13(python --version) - Node.js:
22 LTS(Node>=20.19.0 || >=22.12.0required by Vite/Vitest;node --version) - npm:
10.xor11.x(npm --version) - Docker & Docker Compose: (Optional, for containerized execution;
docker compose version) - Google Gemini API Key: Obtain a free or paid API key from Google AI Studio.
Create backend/.env using the template below or by copying backend/.env.example:
# Application Environment (local, staging, production)
APP_ENV=local
API_BASE_URL=http://localhost:8000
WEB_BASE_URL=http://localhost:3000
LOG_LEVEL=INFO
# Security Keys (Generate random 32+ character strings for production)
SESSION_SIGNING_KEY=dev_session_signing_key_32_characters_minimum_example
FIELD_ENCRYPTION_KEY=dev_field_encryption_key_32_chars_min_example!
# Database & Cache Connections
DATABASE_URL=postgresql+psycopg://postgres:postgres@localhost:5432/prreview
REDIS_URL=redis://localhost:6379/0
# Google Gemini API
GEMINI_API_KEY=your_gemini_api_key_here
GEMINI_KEY_TIER=free
LLM_REVIEW_MODEL=gemini-2.5-flash
LLM_LIGHT_MODEL=gemini-2.0-flash
# Review Limits
MAX_FILES_PER_REVIEW=40
MAX_LINES_PER_REVIEW=2000
MAX_TOKENS_PER_REVIEW=30000
# GitHub App Configuration (Optional for local studio testing; required for live PR webhooks)
GITHUB_APP_ID=
GITHUB_APP_SLUG=pr-review-ai-dev
GITHUB_APP_PRIVATE_KEY=
GITHUB_WEBHOOK_SECRET=your_github_webhook_secretNEXT_PUBLIC_API_BASE_URL=http://localhost:8000The repository provides a modular, containerized multi-service architecture running PostgreSQL 16, Redis 7, FastAPI API, Celery Worker, and Next.js 16 Web.
Important
Production Network Isolation: By default, PostgreSQL (5432) and Redis (6379) do not publish ports to the public host network in base or production compose files. All database and cache communication is strictly restricted to Docker's internal container network.
For local testing, the base compose file provides safe local development defaults:
# 1. Clone repository
git clone https://github.com/VarunNa3530J/PR-Review-AI.git
cd PR-Review-AI
# 2. (Optional) Copy environment template for local overrides
cp infra/.env.example infra/.env
# 3. Build and launch all services in detached mode
docker compose -f infra/docker-compose.yml up --build -d
# 4. Check service health and running containers
docker compose -f infra/docker-compose.yml ps
docker compose -f infra/docker-compose.yml logs -f api- Frontend Dashboard:
http://localhost:3000/app - FastAPI Documentation:
http://localhost:8000/docs - API Health Check:
http://localhost:8000/healthz
If you need direct workstation access to PostgreSQL (5432) or Redis (6379) using tools like psql, pgAdmin, DBeaver, or redis-cli, launch with the development override file (which binds only to 127.0.0.1 loopback):
docker compose -f infra/docker-compose.yml -f infra/docker-compose.dev.yml up -ddocker compose -f infra/docker-compose.yml downIn production environments, never rely on default credentials or unencrypted channels. The production compose configuration (infra/docker-compose.prod.yml) enforces that all production secrets are explicitly defined and valid.
cp infra/.env.example infra/.envGenerate high-entropy random keys (minimum 32 characters) for session signing and database field encryption:
# Generate 32-byte hex keys:
python -c "import secrets; print(secrets.token_hex(32))"
# Or using OpenSSL:
openssl rand -hex 32In infra/.env, configure:
- Strong unique
POSTGRES_PASSWORDand match it inDATABASE_URL. - Generated
SESSION_SIGNING_KEYandFIELD_ENCRYPTION_KEY. - Real
GEMINI_API_KEYand setGEMINI_KEY_TIER=paid(or your allocated tier). - Real
GITHUB_APP_ID,GITHUB_APP_PRIVATE_KEY(PEM RSA key), andGITHUB_WEBHOOK_SECRET. - Ensure
APP_ENV=production.
# Strict secret validation: fails immediately if any required secret is missing or empty
docker compose --env-file infra/.env -f infra/docker-compose.yml -f infra/docker-compose.prod.yml up --build -d(If any mandatory production secret is missing, Docker Compose will abort execution with ${VARIABLE:?Set VARIABLE in environment})
# Check status and health
docker compose -f infra/docker-compose.yml -f infra/docker-compose.prod.yml ps
# Inspect logs
docker compose -f infra/docker-compose.yml -f infra/docker-compose.prod.yml logs -f api worker- Persistence: Database data is stored in the Docker volume
pgdata. - Database Backup:
docker compose -f infra/docker-compose.yml exec -T postgres pg_dump -U postgres prreview > backup_$(date +%Y%m%d_%H%M%S).sql
- Database Restore:
cat backup.sql | docker compose -f infra/docker-compose.yml exec -T postgres psql -U postgres -d prreview
Caution
Infrastructure Hardening: In production, always terminate TLS via a reverse proxy (e.g. Nginx, Caddy, Cloudflare, or AWS ALB), enforce strict firewall rules (security groups) preventing external access to internal services, and store secrets using a secure secret manager (AWS Secrets Manager, GCP Secret Manager, or HashiCorp Vault).
If you have Docker installed, you can spin up just PostgreSQL and Redis:
docker run -d --name prreview-postgres -p 5432:5432 -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=prreview postgres:16-alpine
docker run -d --name prreview-redis -p 6379:6379 redis:7-alpinecd backend
# Create and activate Python virtual environment
python -m venv .venv
# On Windows:
.venv\Scripts\activate
# On Linux / macOS:
# source .venv/bin/activate
# Upgrade pip and install package with dev dependencies
python -m pip install --upgrade pip
pip install -e ".[dev]"
# Configure environment file
cp .env.example .env
# Edit backend/.env and provide your GEMINI_API_KEY
# Start FastAPI development server
uvicorn app.main:app --reload --host 127.0.0.1 --port 8000Interactive Swagger docs: http://127.0.0.1:8000/docs
cd backend
# Activate virtual environment
# Windows: .venv\Scripts\activate | Linux/macOS: source .venv/bin/activate
# Start Celery worker instance
celery -A app.workers.celery_app.celery_app worker --loglevel=info -P solo
# Note: On Windows use '-P solo' or '-P threads'; on Linux/macOS default prefork works.cd frontend
# Perform clean dependency installation
npm ci
# Start Next.js development server
npm run devOpen http://localhost:3000/app in your browser to access the Review Studio.
All linters, typecheckers, security scanners, and test suites run in GitHub Actions CI. You can run every check locally:
From the backend/ directory with virtual environment activated:
# 1. Linting with Ruff
ruff check .
# 2. Code formatting check with Ruff
ruff format --check .
# 3. Static type checking with Mypy
mypy app
# 4. Security vulnerability scan with Bandit
bandit -c pyproject.toml -r app
# 5. Unit and integration tests with Pytest
pytest -vFrom the frontend/ directory:
# 1. ESLint check
npm run lint
# 2. TypeScript typecheck
npm run typecheck
# 3. Unit tests with Vitest
npm test
# 4. Production build check
npm run buildConfigure custom review rules by adding a .prreview.yml file to the root of your monitored repositories:
# Folders and files the bot skips entirely (glob patterns)
ignore_paths:
- "dist/**"
- "build/**"
- "**/*.min.js"
- "docs/**"
# Minimum severity threshold to report: critical, high, medium, low, info (default: low)
min_severity: medium
# Block PR merge / fail check run on Critical findings (default: false)
block_on_critical: false
# Review draft pull requests (default: false)
review_drafts: false
# Plain-English rules for your engineering team (max 20)
custom_rules:
- "Every new public function must have a docstring."
- "Database queries must use parameterized statements or ORM methods."
- "Flag any new third-party dependency with explanation."The FastAPI backend exposes the following primary endpoints under /api/v1:
GET /healthzβ Service liveness probe (returns{"status": "ok"}).GET /readyzβ Readiness probe checking environment state and pause switches.
POST /api/v1/webhooks/githubβ Ingests GitHub webhook deliveries. RequiresX-Hub-Signature-256,X-GitHub-Delivery, andX-GitHub-Eventheaders.
GET /api/v1/dashboard/overviewβ Aggregated account metrics (reviews this month, critical findings, average review duration).GET /api/v1/reposβ Lists monitored repositories and their quality scores.GET /api/v1/reviewsβ Lists recent pull request reviews and local audit runs.GET /api/v1/reviews/{review_id}β Returns findings, risk assessment, and file diffs for a review.POST /api/v1/reviews/review-filesβ Triggers an audit across uploaded files or directories with AST and AI analysis.POST /api/v1/reviews/triggerβ Triggers an on-demand review for an individual file patch.
PR-Review-AI/
βββ .github/
β βββ workflows/
β βββ ci.yml # GitHub Actions CI workflow (lint, test, build, gitleaks)
βββ backend/
β βββ app/
β β βββ api/
β β β βββ deps.py # Authentication & tenant isolation dependencies
β β β βββ v1/ # API routers: webhooks, dashboard, repos, reviews
β β βββ core/ # Config, security (AES-GCM/HMAC), logging, error handlers
β β βββ db/ # SQLAlchemy models, sessions, Alembic migrations
β β βββ services/
β β β βββ analyzers/ # Syntax (AST), secrets scanner, complexity
β β β βββ github/ # GitHub App token exchange & review publisher
β β β βββ llm/ # Google Gemini API integration and fallbacks
β β β βββ review/ # Pipeline orchestrator, diff validation, ranking
β β βββ workers/ # Celery application and background review task
β β βββ main.py # FastAPI application entry point
β βββ tests/
β β βββ fixtures/ # Test diff fixtures and mock repositories
β β βββ integration/ # Tenant isolation and webhook security tests
β β βββ unit/ # Core pipeline, AST parsing, and secret scanner tests
β βββ pyproject.toml # Python packaging, Ruff, Mypy, and Pytest configuration
β βββ .env.example # Backend environment template
βββ frontend/
β βββ src/
β β βββ app/ # Next.js App Router (Studio, Quality, Repos, Settings)
β β βββ components/ # UI components, diff highlighters, file trees
β β βββ lib/ # Types, API utilities, mock datasets
β βββ package.json # Frontend dependencies, scripts, and engines
β βββ package-lock.json # Synchronized npm lockfile (satisfies peer dependencies)
β βββ Dockerfile # Multi-stage production container build (Node 22)
βββ infra/
β βββ docker-compose.yml # Complete service orchestration (Postgres, Redis, API, Worker, Web)
β βββ .env.example # Infrastructure environment variable template
βββ .prreview.yml # Default repository review configuration
βββ LICENSE # MIT License
βββ README.md # Comprehensive project documentation
Ensure you are using Node.js 22 LTS. The dependencies (Vite 8 and Vitest 5) specify engine constraints for Node >=22.12.0. Run npm ci rather than npm install to maintain strict dependency tree integrity.
Ensure Redis is running on port 6379 (redis-cli ping returns PONG). If running locally without Docker on Windows, you can start Redis using WSL2 or Docker (docker run -p 6379:6379 redis:7-alpine).
If GEMINI_API_KEY is not provided in backend/.env, static analysis (AST syntax parsing, secret scanning, and security rule analysis) continues to function, while AI review passes will gracefully fallback or report configuration errors. Check Google AI Studio for your API quota.
Celery's default prefork pool is not supported natively on Windows. Pass -P solo or -P threads when starting the worker:
celery -A app.workers.celery_app.celery_app worker --loglevel=info -P soloThis project is licensed under the MIT License - see the LICENSE file for details.