Skip to content

mohammedfirdouss/ai_code_reviewer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

37 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI-Powered Code Reviewer

A modern, real-time AI code review application with intelligent language detection, built on Cloudflare's edge computing platform. Get instant code analysis, security audits, performance insights, and documentation suggestions powered by Llama 3.1.

✨ Features

  • πŸ” Intelligent Language Detection - Automatically detects and validates programming languages
  • ⚑ Real-time Streaming - Watch AI analysis stream in real-time as it's generated
  • 🌐 Multi-language Support - JavaScript, TypeScript, Python, Java, Go, Rust, C++, C#, PHP, Ruby, Swift, Kotlin
  • πŸ“‹ Review Categories:
    • πŸš€ Quick Review - Overall code quality assessment
    • πŸ”’ Security Audit - Vulnerability detection & OWASP analysis
    • ⚑ Performance Analysis - Optimization suggestions
    • πŸ“š Documentation Review - Comment & documentation improvements
  • πŸ’Ύ Review History - Search, filter, and export your past reviews
  • 🎨 Modern UI - Dark mode, syntax highlighting, keyboard shortcuts
  • πŸ“Š Statistics Dashboard - Track your review activity and insights
  • πŸ›‘οΈ Smart Validation - Prevents errors and provides helpful suggestions

πŸš€ Quick Start

Option 1: Use the Live Application

Visit the deployed application: https://ai-code-reviewer-5fq.pages.dev

No setup required - just paste your code and get instant AI-powered reviews!

Option 2: Local Development

# Clone the repository
git clone <your-repo-url>
cd ai_code_reviewer

# Install backend dependencies
npm install

# Install frontend dependencies
cd frontend
npm install
cd ..

# Start the backend Worker (in one terminal)
npm run dev

# Start the frontend (in another terminal)
npm run dev:frontend

The frontend will be available at http://localhost:5173 and connects to the local Worker at http://localhost:8787.

Option 3: HTTP API

Use the REST API directly without the frontend:

# Submit code for review
curl -X POST https://ai-code-reviewer-backend.mohammedfirdousaraoye.workers.dev/api/review \
  -H "Content-Type: application/json" \
  -d '{
    "code": "console.log(\"Hello World\");",
    "category": "quick",
    "language": "javascript"
  }'

# Get all reviews
curl https://ai-code-reviewer-backend.mohammedfirdousaraoye.workers.dev/api/reviews

# Check service status
curl https://ai-code-reviewer-backend.mohammedfirdousaraoye.workers.dev/api/status

πŸ“– API Reference

Endpoints

POST /api/review

Submit code for AI analysis.

Request:

{
  "code": "console.log('Hello World');",
  "category": "quick|security|performance|documentation",
  "language": "javascript|typescript|python|java|go|rust|cpp|csharp|php|ruby|swift|kotlin|other"
}

Response:

{
  "success": true,
  "review": {
    "id": "unique-review-id",
    "code": "console.log('Hello World');",
    "category": "quick",
    "language": "javascript",
    "result": "AI analysis result...",
    "timestamp": 1760798282676
  }
}

GET /api/reviews

Retrieve all submitted code reviews.

GET /api/status

Check service health and statistics.

GET /health

Basic health check endpoint.

GET /api

Interactive API documentation.

WebSocket API

The application also supports WebSocket connections for real-time streaming. Connect to /agent endpoint and send:

{
  "type": "submit_code",
  "code": "your code here",
  "category": "quick",
  "language": "javascript"
}

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend (React + Vite)          β”‚
β”‚   - Modern UI with dark mode       β”‚
β”‚   - Real-time streaming display    β”‚
β”‚   - Review history & search        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚ WebSocket / HTTP
               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Cloudflare Worker                 β”‚
β”‚   - Durable Objects for state       β”‚
β”‚   - Language detection              β”‚
β”‚   - Request validation              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚ AI Binding
               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Cloudflare Workers AI             β”‚
β”‚   - Llama 3.1 8B Model              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Project Structure

ai_code_reviewer/
β”œβ”€β”€ worker/                       # Cloudflare Worker backend
β”‚   β”œβ”€β”€ index.ts                 # Worker entry point
β”‚   β”œβ”€β”€ agent.ts                 # Durable Object Agent
β”‚   β”œβ”€β”€ types.ts                 # TypeScript definitions
β”‚   └── lib/
β”‚       β”œβ”€β”€ code-review-service.ts
β”‚       └── websocket-handler.ts
β”œβ”€β”€ frontend/                     # React frontend application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.tsx              # Main component
β”‚   β”‚   β”œβ”€β”€ App.css              # Styles
β”‚   β”‚   └── main.tsx             # Entry point
β”‚   β”œβ”€β”€ package.json
β”‚   └── vite.config.ts
β”œβ”€β”€ scripts/                      # Deployment & utility scripts
β”‚   β”œβ”€β”€ setup-env.sh             # Environment setup
β”‚   β”œβ”€β”€ pre-deploy-check.sh      # Pre-deployment validation
β”‚   └── verify-deployment.sh     # Post-deployment verification
β”œβ”€β”€ tests/                        # Test files
β”‚   └── test-websocket.html      # WebSocket test utility
β”œβ”€β”€ docs/                         # Documentation
β”‚   └── PROMPT.md                # Project prompt/requirements
β”œβ”€β”€ config/                       # Configuration files
β”‚   β”œβ”€β”€ wrangler.workers.toml    # Worker configuration
β”‚   └── wrangler.pages.toml      # Pages configuration
β”œβ”€β”€ wrangler.toml                 # Main Worker config
β”œβ”€β”€ package.json                  # Backend dependencies
└── tsconfig.json                 # TypeScript configuration

πŸ› οΈ Development

Prerequisites

  • Node.js 18+ and npm
  • Cloudflare account (for deployment)
  • Wrangler CLI (installed via npm)

Setup

  1. Install dependencies:

    # Backend
    npm install
    
    # Frontend
    cd frontend && npm install && cd ..
  2. Configure environment:

    npm run setup
    # Edit .env with your Cloudflare credentials
  3. Run locally:

    # Terminal 1: Backend
    npm run dev
    
    # Terminal 2: Frontend
    npm run dev:frontend

Testing

  1. Open http://localhost:5173 in your browser
  2. Paste code into the editor
  3. Select a review category
  4. Click "Review Code" to see streaming AI analysis

🚒 Deployment

Backend (Cloudflare Worker)

# Configure environment first
npm run setup

# Deploy
npm run deploy

Frontend (Cloudflare Pages)

cd frontend
npm run deploy

The deployment script uses API tokens from .env - no OAuth required!

Verify Deployment

# Check health
curl https://ai-code-reviewer-backend.mohammedfirdousaraoye.workers.dev/health

# View logs
npm run logs

# Verify deployment
npm run verify

🧠 Language Detection

The application intelligently detects programming languages using pattern recognition:

  • Automatic Detection - Analyzes code syntax to identify the language
  • Validation - Prevents mismatched language selections
  • Smart Suggestions - Recommends correct language when mismatch detected
  • Non-code Detection - Identifies and rejects plain text submissions

Supported Languages

JavaScript, TypeScript, Python, Java, Go, Rust, C++, C#, PHP, Ruby, Swift, Kotlin, and more.

⌨️ Keyboard Shortcuts

  • Ctrl/Cmd + K - Focus code input
  • Ctrl/Cmd + Enter - Submit review

πŸ”§ Configuration

Worker Configuration (wrangler.toml)

  • AI Binding: Connects to Workers AI for Llama 3.1
  • Durable Object: CodeReviewerAgent for stateful sessions
  • Compatibility: Node.js compatibility enabled

Environment Variables

Create a .env file with:

CLOUDFLARE_ACCOUNT_ID=your-account-id
CLOUDFLARE_API_TOKEN=your-api-token

πŸ“š Resources

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

This project is open source and available under the MIT License.

About

AI-powered code reviewer and explainer using Cloudflare Workers and Pages

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •