Skip to content

AI-powered code review platform built with Next.js, Google Gemini, and TypeScript. Analyzes code for security, performance, and best practices.

Notifications You must be signed in to change notification settings

Nobelgalido/code-review-ai

Repository files navigation

Code Review AI

An AI-powered code review platform that provides instant feedback on security vulnerabilities, performance issues, and best practices. Built with Next.js 15, TypeScript, and Google Gemini AI.

Features

  • AI-Powered Analysis: Get instant code reviews using Google Gemini 1.5 Flash (FREE)
  • Multi-Language Support: JavaScript, TypeScript, Python, Java, Go, Rust, C++, C#, PHP, and Ruby
  • Security Scanning: Detect SQL injection, XSS, authentication issues, and more
  • Performance Optimization: Identify inefficient algorithms and bottlenecks
  • Code Editor: Monaco editor with syntax highlighting
  • Review History: Track all your past reviews
  • Rate Limiting: Free tier (5 reviews/day) with production-ready limits
  • Authentication: Secure auth with Clerk
  • Database: PostgreSQL with Supabase

Tech Stack

  • Framework: Next.js 15 (App Router)
  • Language: TypeScript
  • Styling: Tailwind CSS
  • AI: Google Gemini API (FREE)
  • Authentication: Clerk
  • Database: Supabase (PostgreSQL)
  • Code Editor: Monaco Editor
  • Validation: Zod
  • Package Manager: pnpm

Prerequisites

  • Node.js 18+ installed
  • pnpm installed (npm install -g pnpm)
  • Accounts created for:

Getting Started

1. Clone and Install

cd code-review-ai
pnpm install

2. Set Up Environment Variables

Copy .env.example to .env.local and fill in your credentials:

cp .env.example .env.local

Required environment variables:

# Clerk Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...
CLERK_SECRET_KEY=sk_test_...

# Supabase
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbG...
SUPABASE_SERVICE_ROLE_KEY=eyJhbG...

# Google Gemini AI (FREE)
GEMINI_API_KEY=AIza...

3. Set Up Database

  1. Go to your Supabase project
  2. Navigate to SQL Editor
  3. Run the schema from supabase/schema.sql

4. Configure Clerk

  1. Go to Clerk Dashboard
  2. Create a new application
  3. Copy the API keys to .env.local
  4. In Clerk settings, set redirect URLs:
    • Sign-in URL: /sign-in
    • Sign-up URL: /sign-up
    • After sign-in: /review
    • After sign-up: /review

5. Get Google Gemini API Key (FREE)

  1. Go to Google AI Studio
  2. Sign in with your Google account
  3. Click "Create API key in new project"
  4. Copy your API key
  5. Add to .env.local

See GEMINI_SETUP.md for detailed instructions.

6. Run Development Server

pnpm dev

Open http://localhost:3000 in your browser.

Project Structure

code-review-ai/
├── src/
│   ├── app/                    # Next.js app router
│   │   ├── api/                # API routes
│   │   │   ├── review/         # Code review endpoint
│   │   │   └── reviews/        # Review history endpoint
│   │   ├── dashboard/          # Review history page
│   │   ├── review/             # Main review page
│   │   ├── sign-in/            # Auth pages
│   │   ├── sign-up/
│   │   ├── layout.tsx          # Root layout
│   │   └── page.tsx            # Landing page
│   ├── components/
│   │   ├── features/           # Feature components
│   │   │   ├── code-editor.tsx
│   │   │   ├── issue-card.tsx
│   │   │   └── language-selector.tsx
│   │   └── ui/                 # Reusable UI components
│   ├── lib/                    # Utilities and services
│   │   ├── ai-service.ts       # Google Gemini AI integration
│   │   ├── rate-limit.ts       # Rate limiting logic
│   │   └── supabase.ts         # Supabase client
│   ├── types/                  # TypeScript types
│   │   └── index.ts
│   └── middleware.ts           # Clerk middleware
├── supabase/
│   └── schema.sql              # Database schema
├── .env.local                  # Environment variables
├── .env.example                # Environment template
├── .prettierrc                 # Prettier config
└── package.json

Available Scripts

  • pnpm dev - Start development server
  • pnpm build - Build for production
  • pnpm start - Start production server
  • pnpm lint - Run ESLint
  • pnpm format - Format code with Prettier
  • pnpm type-check - Check TypeScript types

Features Breakdown

Code Review Engine

The AI service (src/lib/ai-service.ts) uses Google Gemini to analyze code and returns:

  • Security vulnerabilities
  • Performance issues
  • Style problems
  • Potential bugs
  • Best practice suggestions

Each issue includes:

  • Type and severity
  • Description and location
  • Actionable suggestions
  • Before/after code examples

Rate Limiting

Production-grade rate limiting in src/lib/rate-limit.ts:

  • Free tier: 5 reviews per day
  • Pro tier: 100 reviews per day (ready for implementation)
  • Automatic daily reset
  • Per-user tracking

Database Schema

PostgreSQL with Row Level Security:

  • users table - User profiles and tier information
  • code_reviews table - Review history with JSONB issues
  • Indexes for performance
  • RLS policies for security
  • Automatic timestamp updates

Deployment

Deploy to Vercel

  1. Push code to GitHub
  2. Go to Vercel
  3. Import your repository
  4. Add environment variables
  5. Deploy

Environment Variables on Vercel

Add all variables from .env.local to Vercel:

  • Clerk keys
  • Supabase keys
  • Google Gemini API key
  • Rate limit settings

Production Considerations

Security

  • ✅ Row Level Security in Supabase
  • ✅ API route authentication
  • ✅ Input validation with Zod
  • ✅ Rate limiting per user
  • ✅ Secure environment variables

Performance

  • ✅ Database indexes
  • ✅ Efficient queries
  • ✅ Monaco editor lazy loading
  • ✅ API response caching ready

Scalability

  • ✅ Serverless API routes
  • ✅ PostgreSQL database
  • ✅ Rate limiting infrastructure
  • ✅ Horizontal scaling ready

Future Enhancements

  • GitHub integration for PR reviews
  • CI/CD pipeline integration
  • Team accounts
  • Custom review rules
  • VSCode extension
  • Batch file reviews
  • Analytics dashboard
  • Payment integration (Stripe)

Contributing

This is a portfolio project. Feel free to fork and customize for your own use.

License

MIT

Author

Built as a portfolio project to demonstrate full-stack development skills with modern technologies.


Tech Stack Highlights: Next.js 15, TypeScript, Tailwind CSS, Clerk Auth, Supabase, Google Gemini AI (FREE), Monaco Editor, Zod Validation

About

AI-powered code review platform built with Next.js, Google Gemini, and TypeScript. Analyzes code for security, performance, and best practices.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published