Skip to content

Latest commit

Β 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– AI Code Reviewer (CodePulse AI)

An intelligent, full-stack automated code review workspace powered by Large Language Models via OpenRouter. The application performs in-depth security, performance, and bug analysis on source code across multiple programming languages and delivers structured feedback, ratings, industry best practices, and refactored code through an interactive split-view dashboard.


🚦 Workflow & System Status

All project workflows have been verified and tested end-to-end:

Workflow Scope Status Notes
Frontend Linting frontend PASSED ESLint 10 verification clean across all JSX components
Frontend Build frontend PASSED Vite 8 production build bundles clean assets to dist/
Backend API Server backend PASSED Express 5 REST API running on port 8000 (supports /api and /ai routes)
3-Stage LLM Pipeline backend/services PASSED Multi-stage analysis, refactoring, and JSON report synthesis verified with live OpenRouter model (google/gemini-2.5-flash)

🌟 Key Features

  • Multi-Stage AI Analysis Pipeline:
    • Phase 1: Deep Code Analysis β€” Scans specifically for security vulnerabilities, logic defects, edge cases, and performance bottlenecks.
    • Phase 2: Intelligent Refactoring β€” Generates clean, idiomatic, type-safe, and bug-free code based on Phase 1 findings.
    • Phase 3: Structured Report Synthesis β€” Formats insights into a reliable JSON schema for seamless UI rendering.
  • Interactive Tabbed Review Dashboard:
    • Overview: Executive summary, rating score (1–10 stars), and key code strengths.
    • Issues: Itemized security flaws, runtime risks, and algorithmic issues.
    • Improvements: Actionable recommendations for code maintainability, type safety, and scalability.
    • Best Practices: Industry-standard engineering tips tailored to the submitted code.
    • Refactored Code: Ready-to-use refactored code snippet with one-click clipboard copying.
  • Multi-Language Support: Editor selector with preset support for JavaScript, TypeScript, Python, and Java.
  • Provider Agnostic (OpenRouter): Easily switch between LLM models (e.g., Google Gemini 2.5 Flash, OpenAI GPT-4o, Anthropic Claude 3.5 Sonnet) via environment variable configuration.
  • Modern Split-Screen Interface: Code editor panel on the left with live character counters, real-time loading feedback with skeleton cards, and formatted AI review panel on the right.

πŸ—οΈ Architecture & Data Flow

  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚   React 19 Frontend    β”‚  (Vite 8 Dev Server @ http://localhost:5173)
  β”‚  (Source Code Editor)  β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚  POST /api/review { "code": "..." }
              β–Ό
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚   Express 5 Backend    β”‚  (Node.js REST Server @ http://localhost:8000)
  β”‚  (Controller & Router) β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚
              β”œβ”€β”€β”€β–Ί Step 1: Deep Code Analysis (Security & Bugs)
              β”œβ”€β”€β”€β–Ί Step 2: Code Refactoring based on Analysis Findings
              └───► Step 3: Report Synthesis into Structured JSON Schema
                      β”‚
                      β–Ό
            [ OpenRouter API ]
      (e.g., google/gemini-2.5-flash)

πŸ“ Project Structure

ai-code-reviewer/
β”œβ”€β”€ backend/                     # Express.js REST API Backend
β”‚   β”œβ”€β”€ controllers/             # Endpoint controllers
β”‚   β”‚   └── ai.controller.js     # Express request handler for code reviews
β”‚   β”œβ”€β”€ middleware/              # Express middlewares
β”‚   β”‚   └── errorHandler.js      # Global error and OpenRouter response handler
β”‚   β”œβ”€β”€ prompts/                 # Prompt engineering templates
β”‚   β”‚   └── reviewPrompt.js      # 3-stage prompts & JSON output schema definition
β”‚   β”œβ”€β”€ routes/                  # API routing definitions
β”‚   β”‚   └── ai.routes.js         # Express router for /review and /get-review
β”‚   β”œβ”€β”€ services/                # Business logic & LLM service integration
β”‚   β”‚   └── openai.service.js    # OpenRouter API client & 3-stage execution pipeline
β”‚   β”œβ”€β”€ .env.example             # Backend environment template
β”‚   β”œβ”€β”€ .env                     # Local environment file (API keys & port config)
β”‚   β”œβ”€β”€ package.json             # Backend dependencies & npm scripts
β”‚   β”œβ”€β”€ server.js                # Express app entry point
β”‚   └── test.http                # REST Client test request collection
β”‚
β”œβ”€β”€ frontend/                    # React 19 Frontend Application (Vite 8)
β”‚   β”œβ”€β”€ public/                  # Favicons and SVG assets
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ CodeInput.jsx    # Split-screen code editor input component
β”‚   β”‚   β”‚   β”œβ”€β”€ Loader.jsx       # Animated loading state with skeleton UI
β”‚   β”‚   β”‚   β”œβ”€β”€ Navbar.jsx       # Header bar & branding component
β”‚   β”‚   β”‚   └── ReviewOutput.jsx # Tabbed review dashboard & refactored code view
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   └── api.js           # Axios API client pointing to backend
β”‚   β”‚   β”œβ”€β”€ App.jsx              # Workspace layout manager
β”‚   β”‚   β”œβ”€β”€ App.css              # Dashboard and component styling
β”‚   β”‚   β”œβ”€β”€ index.css            # Base design system tokens and typography
β”‚   β”‚   └── main.jsx             # React DOM root render
β”‚   β”œβ”€β”€ eslint.config.js         # ESLint 10 flat configuration
β”‚   β”œβ”€β”€ package.json             # Frontend dependencies & npm scripts
β”‚   └── vite.config.js           # Vite 8 project configuration
β”‚
└── README.md                    # System documentation & project overview

πŸ› οΈ Tech Stack

Frontend

  • Framework: React 19
  • Build Tool: Vite 8
  • HTTP Client: Axios
  • Linting: ESLint 10
  • Styling: Modern CSS variables & responsive split-grid layout system

Backend


πŸš€ Getting Started

Prerequisites

  • Node.js (>= v18.0.0)
  • npm (>= v9.0.0)
  • OpenRouter API Key (Obtain from openrouter.ai)

1. Backend Setup

  1. Open your terminal and navigate to the backend directory:

    cd backend
  2. Install dependencies:

    npm install
  3. Configure environment variables: Create a .env file in backend/ (or copy .env.example):

    PORT=8000
    OPENROUTER_API_KEY=your_actual_openrouter_api_key
    MODEL=google/gemini-2.5-flash
    MAX_TOKENS=800
  4. Run the backend server:

    • Development mode (with auto-restart via nodemon):
      npm run dev
    • Production mode:
      npm start

    The backend API will start on http://localhost:8000.


2. Frontend Setup

  1. Open a second terminal window and navigate to the frontend directory:

    cd frontend
  2. Install dependencies:

    npm install
  3. Run linting and build checks:

    npm run lint
    npm run build
  4. Start the Vite development server:

    npm run dev
  5. Open your browser and navigate to http://localhost:5173.


βš™οΈ Environment Variables Reference

The backend requires the following keys in backend/.env:

Variable Description Default / Recommended
PORT Port number for Express API server 8000
OPENROUTER_API_KEY Authentication bearer token from OpenRouter sk-or-v1-...
MODEL OpenRouter model identifier google/gemini-2.5-flash
MAX_TOKENS Maximum completion token limit per pipeline step 800

πŸ“‘ API Reference

1. Server Health Check

GET /

Response (200 OK):

{
  "success": true,
  "message": "AI Code Reviewer API is running πŸš€"
}

2. Submit Code for Review

POST /api/review

(Also aliased at POST /ai/review and POST /api/get-review)

Request Headers:

Content-Type: application/json

Request Body:

{
  "code": "function add(a, b) { return a + b; }"
}

Response (200 OK):

{
  "success": true,
  "data": {
    "review": {
      "summary": "The function performs basic addition but lacks type checking for JavaScript's dynamic typing.",
      "rating": 7,
      "strengths": [
        "Concise implementation",
        "Clean functional logic"
      ],
      "issues": [
        "Lack of input validation allows unexpected string concatenation"
      ],
      "improvements": [
        "Add explicit typeof validation or switch to TypeScript",
        "Include JSDoc documentation"
      ],
      "bestPractices": [
        "Validate input arguments before performing arithmetic operations",
        "Document function contracts with JSDoc parameters"
      ],
      "refactoredCode": "/**\n * Adds two numbers.\n * @param {number} a\n * @param {number} b\n * @returns {number}\n */\nfunction add(a, b) {\n  if (typeof a !== 'number' || typeof b !== 'number') {\n    throw new TypeError('Both arguments must be numbers.');\n  }\n  return a + b;\n}"
    }
  },
  "review": { ... }
}

πŸ§ͺ Testing

Frontend Workflow Tests

  • Run ESLint check:
    cd frontend && npm run lint
  • Run Vite production bundle build:
    cd frontend && npm run build

Backend API Tests

  • Use the included REST Client file backend/test.http in VS Code / Cursor.
  • Or send a test request via curl:
    curl -X POST http://localhost:8000/api/review \
      -H "Content-Type: application/json" \
      -d '{"code": "function calculate(x, y) { return x / y; }"}'

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add AmazingFeature')
  4. Push to your branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

Distributed under the ISC License.

About

An automated AI-powered code reviewer that analyzes code for bugs and security flaws, suggests best practices, and generates refactored code in a clean split-screen UI.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages