Skip to content

Rhitottam/react-perf-guardian

Repository files navigation

React Performance Code Review Agent πŸš€

AI-powered multi-agent system for automated React performance analysis in Pull Requests using Google's Agent Development Kit (ADK) and Gemini models.

Python 3.12+ Node 20+ Docker License: MIT


🎯 Features

  • πŸ€– Multi-Agent Analysis: Four-stage AI pipeline (Parser β†’ Analyzer β†’ Reasoner β†’ Reporter)
  • 🧠 Smart Memory System: Tracks patterns across files, detects recurring issues, learns project conventions
  • πŸ“ Inline PR Comments: Posts detailed review comments on specific lines
  • 🎯 Smart Detection: Identifies critical React performance issues
  • βš™οΈ Configurable: Severity thresholds and auto-approval settings
  • 🐳 Docker Ready: One-command deployment anywhere
  • πŸ”— PR URL Support: Analyze PRs by URL, no manual configuration needed
  • πŸš€ GitHub Action: Automated reviews on every PR

πŸ” What It Detects

🚨 Critical Issues

  • Inline functions/objects breaking React.memo
  • Stale closures in hooks
  • Missing dependency arrays causing infinite loops

⚠️ High Priority

  • Unstable hook dependencies
  • Unnecessary re-renders
  • Derived state anti-patterns

πŸ’‘ Medium Priority

  • Inline JSX expressions
  • Props not used in render
  • State management issues

ℹ️ Low Priority

  • Minor optimizations
  • Best practice suggestions

πŸ—οΈ Architecture

5-Agent Multi-Agent System orchestrated via Google ADK's SequentialAgent:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                           PR Analysis Flow                                   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                              β”‚
β”‚  File N β†’ [Memory Agent] β†’ "Pattern summary: 10 inline functions..."        β”‚
β”‚            ↓                                                                 β”‚
β”‚           [Sequential Agent Pipeline]                                        β”‚
β”‚            β”œβ†’ Parser Agent    (Babel AST parsing)                           β”‚
β”‚            β”œβ†’ Analyzer Agent  (Issue detection - 8 tools)                   β”‚
β”‚            β”œβ†’ Reasoner Agent  (Prioritization + context)                    β”‚
β”‚            β””β†’ Reporter Agent  (GitHub/JSON output)                          β”‚
β”‚            ↓                                                                 β”‚
β”‚           Store Summary β†’ DatabaseSessionService                             β”‚
β”‚                                                                              β”‚
β”‚  PR Done β†’ Clear Database                                                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         5-AGENT MULTI-AGENT SYSTEM                           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                              β”‚
β”‚  🧠 Memory Agent         β†’  Cross-file pattern detection                    β”‚
β”‚                              Provides ~50 word summary to pipeline           β”‚
β”‚                                                                              β”‚
β”‚  πŸ“ Parser Agent         β†’  parse_code() - Babel AST extraction             β”‚
β”‚  πŸ” Analyzer Agent       β†’  8 specialized tools for issue detection         β”‚
β”‚  πŸ’‘ Reasoner Agent       β†’  Prioritizes issues, adds suggestions            β”‚
β”‚  πŸ“Š Reporter Agent       β†’  Formats output for GitHub PR reviews            β”‚
β”‚                                                                              β”‚
β”‚  [SequentialAgent orchestration: Parser β†’ Analyzer β†’ Reasoner β†’ Reporter]   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Configuration: Set USE_MULTI_AGENT=false for single-agent mode (faster, less specialized)

Tech Stack:

  • 🧠 Google Gemini 2.5 Flash Lite
  • πŸ”§ Google ADK (Agent Development Kit) with SequentialAgent
  • πŸ’Ύ DatabaseSessionService (Persistent SQLite)
  • πŸ€– 5 Specialized Agents (Memory, Parser, Analyzer, Reasoner, Reporter)
  • πŸ“ Babel Parser (AST analysis)
  • 🐍 Python 3.12+
  • πŸ“¦ Node.js 20+
  • 🐳 Docker & Docker Compose

πŸš€ Quick Start

Option 1: Docker (Recommended)

# 1. Clone the repository
git clone <repository-url>
cd code-review-agent

# 2. Copy and configure environment
cp .env.example .env
# Edit .env with your API keys

# 3. Build and run
docker-compose build
docker-compose run code-review-agent python3 agents/main.py examples/UserList.tsx

# 4. Analyze a PR
docker-compose run code-review-agent ./review-pr.sh <PR_URL> --analyze-only

Option 2: Local Installation

# 1. Install dependencies
cd parser && npm install && npm run build && cd ..
cd agents && pip install -r requirements.txt && cd ..

# 2. Configure environment
cp .env.example agents/.env
# Edit agents/.env with your API keys

# 3. Run analysis
python3 agents/main.py examples/UserList.tsx

# 4. Review a PR
./review-pr.sh <PR_URL> --analyze-only

πŸ“‹ Prerequisites

Required API Keys

  1. Google AI API Key

  2. GitHub Personal Access Token (for PR reviews)

System Requirements

  • Docker: 20.10+ (recommended), or
  • Python: 3.12+
  • Node.js: 20+
  • Memory: 2GB minimum
  • Storage: 500MB

πŸ’» Usage

Analyze a Single File

# Docker
docker-compose run code-review-agent python3 agents/main.py examples/UserList.tsx

# Local
python3 agents/main.py examples/UserList.tsx [markdown|json|github]

Review a Pull Request

# Dry run (no comments posted)
./review-pr.sh https://github.com/owner/repo/pull/123 --analyze-only

# Post review with default settings
./review-pr.sh https://github.com/owner/repo/pull/123

# High severity only
./review-pr.sh https://github.com/owner/repo/pull/123 --severity high

# Auto-approve if no critical issues
./review-pr.sh https://github.com/owner/repo/pull/123 --auto-approve

GitHub Action

The action runs automatically on PRs that touch React/TypeScript files.

Setup:

  1. Add GOOGLE_API_KEY to repository secrets
  2. Workflow file is already configured at .github/workflows/react-perf-review.yml
  3. Push changes and open a PR

βš™οΈ Configuration

Environment Variables

# Required
GOOGLE_API_KEY=your-google-api-key-here
GITHUB_TOKEN=your-github-token-here

# Optional
GITHUB_REPOSITORY=owner/repo          # Not needed if using PR URLs
DEBUG_ANALYSIS=0                      # Set to 1 for debug output
SEVERITY_THRESHOLD=medium             # low|medium|high|critical
AUTO_APPROVE=false                    # Auto-approve clean PRs

Severity Levels

Level Reports Blocks Merge
critical Only critical issues Yes
high Critical + High On critical only
medium Critical + High + Medium On critical only
low All issues On critical only

πŸ“Š Output Formats

Markdown Report (Default)

# React Performance Analysis Report

## Summary
- 🚨 2 critical issues
- ⚠️ 1 high-priority issues
- πŸ’‘ 3 medium-priority issues

## 🚨 Critical Issues

### `src/Button.tsx:42` - Button
**Inline function breaks memoization**

**Problem:** Arrow function recreates on every render...
**Suggestion:** Use useCallback...

JSON Output

{
  "issues": [
    {
      "file": "src/Button.tsx",
      "line": 42,
      "severity": "critical",
      "title": "Inline function breaks memoization",
      "problem": "...",
      "suggestion": "..."
    }
  ],
  "summary": {
    "critical_count": 2,
    "high_count": 1,
    "files_analyzed": 3
  }
}

GitHub PR Comments

Posted as inline review comments on specific lines with:

  • 🚨 Severity indicator
  • Problem description
  • Suggestion with code examples
  • Runtime Impact explanation

🐳 Docker Details

Build Image

docker-compose build

Run Analysis

# Analyze file
docker-compose run code-review-agent python3 agents/main.py examples/UserList.tsx

# Review PR
docker-compose run code-review-agent ./review-pr.sh <PR_URL> --analyze-only

# Interactive shell
docker-compose run code-review-agent /bin/bash

Deploy on EC2/Server

# 1. Copy files to server
scp -r . user@server:/app/code-review-agent

# 2. SSH into server
ssh user@server

# 3. Run with docker-compose
cd /app/code-review-agent
docker-compose build
docker-compose run code-review-agent <command>

πŸ“ Examples

Example 1: Analyze Local File

docker-compose run code-review-agent \
  python3 agents/main.py examples/UserList.tsx

Output: Identifies inline function creating new reference on each render.

Example 2: Review PR from URL

docker-compose run code-review-agent \
  ./review-pr.sh https://github.com/facebook/react/pull/28977 --analyze-only

Output: Analyzes all React files in the PR and shows results.

Example 3: Post Review Comments

./review-pr.sh https://github.com/owner/repo/pull/123 --severity high

Result: Posts inline comments on high and critical issues.


πŸ”§ Development

Project Structure

code-review-agent/
β”œβ”€β”€ parser/                 # TypeScript AST parser (Babel)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ analyzer.ts     # AST analysis logic
β”‚   β”‚   β”œβ”€β”€ cli.ts          # CLI interface
β”‚   β”‚   └── types.ts        # Type definitions
β”‚   └── package.json
β”‚
β”œβ”€β”€ agents/                 # Python agents
β”‚   β”œβ”€β”€ agents.py           # ADK agent definitions
β”‚   β”œβ”€β”€ main.py             # Orchestrator
β”‚   β”œβ”€β”€ tools.py            # Analysis tools
β”‚   β”œβ”€β”€ github_integration.py  # PR integration
β”‚   └── requirements.txt
β”‚
β”œβ”€β”€ .github/workflows/      # GitHub Actions
β”‚   └── react-perf-review.yml
β”‚
β”œβ”€β”€ examples/               # Sample React files
β”œβ”€β”€ Dockerfile             # Docker image
β”œβ”€β”€ docker-compose.yml     # Docker Compose config
└── README.md

πŸ“š Documentation


πŸ› Troubleshooting

Common Issues

1. "GOOGLE_API_KEY not set"

# Make sure .env file exists and is loaded
cp .env.example .env
# Edit .env with your key

2. Parser errors

# Rebuild parser
cd parser && npm run build

3. Docker build fails

# Clean build
docker-compose build --no-cache

4. Analysis returns empty results

  • File may be too large (>1000 lines)
  • Check DEBUG_ANALYSIS=1 for details
  • Try analyzing smaller files first

πŸ™ Credits

Built with:


⭐ Star History

If you find this useful, please star the repo! It helps others discover the project.


Made with ❀️ for the React community

Catch performance issues before they reach production πŸš€

About

Code reviewer Agent for catching React performance issues before production

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published