Skip to content

PETROL-BOY/ai-code-review-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 AI Code Review Bot

A real-time, AI-powered code review assistant that analyzes your code for security, performance, and quality issues. It provides instant feedback, a calculated request rating, and historical tracking using a comprehensive tech stack.

License Node.js PostgreSQL

✨ Features

  • Real-Time Analysis: Streamed feedback via WebSockets as you type or submit code.
  • Multi-Model Support: Works with:
    • Google Gemini (Default)
    • Ollama (Local/Custom LLMs)
    • OpenAI (GPT-3.5/4)
  • Deterministic Scoring: Transparent rating system starting at 10/10 with strict deductions for issues found.
  • Persistent History: All reviews and analysis results are stored in a PostgreSQL database.
  • User Feedback: (Optional) UI allowing users to mark reviews as accurate or inaccurate.
  • Categorized Insights:
    • 🔒 Security Issues
    • ⚡ Performance Bottlenecks
    • 🎯 Code Quality & Best Practices
    • 🧪 Type Safety

🛠️ Tech Stack

  • Frontend: Vanilla JavaScript, HTML5, CSS3 (Served via http-server)
  • Backend: Node.js, Express, WebSocket (ws)
  • AI Integration: LangChain (@langchain/google-genai, @langchain/ollama, @langchain/openai)
  • Database: PostgreSQL 15 (Dockerized), Sequelize ORM
  • Infrastructure: Docker Compose

🚀 Getting Started

Prerequisites

  • Node.js (v18+)
  • Docker & Docker Compose (For PostgreSQL)
  • API Keys (Google Gemini, OpenAI) OR Ollama installed locally.

1. Database Setup

Start the PostgreSQL container:

docker-compose up -d

This starts Postgres on port 5433 (mapped from internal 5432) to avoid local conflicts.

2. Backend Setup

Navigate to the backend directory:

cd backend
npm install

Configure your environment: Create a .env file in backend/ with the following:

PORT=3001
# Database Config
DB_HOST=localhost
DB_PORT=5433
DB_NAME=review_bot
DB_USER=admin
DB_PASSWORD=password123

# --- Choose ONE LLM Provider ---

# Option A: Google Gemini (Default)
# LLM_PROVIDER=google
# GOOGLE_API_KEY=your_gemini_key

# Option B: Ollama (Local or Custom)
LLM_PROVIDER=custom # or 'ollama'
LLM_MODEL=gpt-oss:120b-cloud # or 'llama3', 'mistral'
LLM_BASE_URL=https://ollama.com/api # or http://localhost:11434
OPENAI_API_KEY=your_custom_key_if_needed

# Option C: OpenAI
# LLM_PROVIDER=openai
# OPENAI_API_KEY=sk-...

Start the backend server:

npm start
# OR for development
npm run dev

3. Frontend Setup

Navigate to the frontend directory:

cd ../frontend
npx http-server -p 8081 -c-1

Access the application at http://localhost:8081.

📊 Scoring System

To ensure trust, the bot uses a strict logic-based grading rubric:

  • Base Score: 10 Points
  • Deductions:
    • -3.0: CRITICAL (Security flaws, crashing bugs)
    • -2.0: HIGH (Performance blockers, logic errors)
    • -1.0: MEDIUM (Code smells, maintainability)
    • -0.5: LOW (Nitpicks, styling, comments)

Minimum score is 0/10.

📂 Project Structure

ai-code-review-bot/
├── backend/
│   ├── models/         # Sequelize Schemas (Review.js)
│   ├── .env            # Config keys
│   ├── db.js           # Database connection
│   ├── server.js       # Main API & WebSocket logic
│   └── package.json
├── frontend/
│   ├── index.html      # Main UI
│   └── (styles/scripts embedded for simplicity)
├── docker-compose.yml  # PostgreSQL Configuration
└── README.md

🐛 Troubleshooting

  • WebSocket Error / Disconnect: Ensure backend is running on port 3001.
  • Database Connection Refused: Check if Docker container review_bot_db is running (docker ps) and port 5433 is available.
  • LLM 404/Error: Verify LLM_MODEL name matches exactly what your provider expects (e.g., gemini-1.5-flash vs gemini-pro).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors