Skip to content
Alok-Yadav25Public

About

Model-assisted code review engine leveraging CodeBERT and PyTorch for contextual suggestions.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

11 Commits

Folders and files

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

Repository files navigation

πŸ” CodeLens β€” AI Code Reviewer

🌐 Live Demo

Try it now: codelens-alok-yadav-25.streamlit.app

Note: the backend runs on a free HuggingFace Space, so the first request may take 20-30 seconds to wake up.

πŸ“Œ Overview

CodeLens is an AI-powered code review tool that combines Microsoft CodeBERT for semantic code understanding with Groq's LLaMA 3 for natural language analysis. Paste any code snippet and get a structured review covering bugs, security vulnerabilities, performance improvements, and suggested fixes β€” all in seconds.

Built as a full-stack project with a FastAPI REST backend and a Streamlit frontend, serving structured reviews across 10 programming languages.


✨ Features

  • πŸ› Bug Detection β€” finds logic errors with exact line numbers
  • πŸ”’ Security Analysis β€” detects hardcoded secrets, SQL injection, unsafe patterns
  • ✨ Code Improvements β€” suggestions for cleaner, more efficient code
  • πŸ”§ Suggested Fixes β€” before/after code diff for every issue found
  • πŸ“Š Performance Chart β€” before vs after scores across 5 metrics (Plotly)
  • 🌐 10 Languages β€” Python, JavaScript, TypeScript, Java, C++, Go, Rust, Swift, Ruby, PHP
  • πŸ” Auto Language Detection β€” regex-based detection, no manual selection needed
  • πŸ“œ Review History β€” compare past reviews in the same session
  • 🎨 Dark UI β€” clean Streamlit interface with gradient title and watermark

πŸ—οΈ Architecture

User Browser
     β”‚
     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Streamlit Frontend  β”‚  share.streamlit.io (free)
β”‚  streamlit_app.py    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚ POST /api/review
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  FastAPI Backend     β”‚  HuggingFace Spaces (free)
β”‚  router.py           β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚      β”‚
       β–Ό      β–Ό
  CodeBERT  Groq API
  (HF API)  (LLaMA 3.1)

πŸ› οΈ Tech Stack

Layer Technology Purpose
Frontend Streamlit 1.35 UI β€” code input, results display, charts
Backend FastAPI 0.111 REST API β€” request validation, routing
LLM Groq API (LLaMA 3.1) Natural language code review generation
Embeddings CodeBERT (HuggingFace API) Semantic code understanding, language detection
Charts Plotly Before/after performance visualization
Validation Pydantic v2 Request/response schema enforcement
Server Uvicorn ASGI server for FastAPI

πŸ“ Project Structure

codelens/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ __init__.py              # Package marker
β”‚   β”œβ”€β”€ app.py                   # FastAPI app + CORS setup
β”‚   β”œβ”€β”€ router.py                # POST /api/review endpoint + Pydantic schemas
β”‚   β”œβ”€β”€ codebert_analyzer.py     # Language detection + HF API embeddings
β”‚   └── groq_reviewer.py         # LLM prompt + JSON parsing
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ streamlit_app.py         # Full Streamlit UI
β”‚   └── requirements.txt         # Frontend-specific dependencies
β”œβ”€β”€ Dockerfile                   # Backend container (port 7860 for HF Spaces)
β”œβ”€β”€ requirements.txt             # Backend dependencies
β”œβ”€β”€ .gitignore                   # Excludes .env and secrets
└── README.md

πŸš€ Quick Start (Local)

Prerequisites

1. Clone the repo

git clone https://github.com/YOUR_USERNAME/codelens.git
cd codelens

2. Create virtual environment

python -m venv .venv
source .venv/bin/activate   # macOS/Linux
# .venv\Scripts\activate    # Windows

3. Install dependencies

pip install -r requirements.txt
pip install streamlit==1.35.0 plotly==5.22.0

4. Set environment variables

Create a .env file in the project root (never commit this):

GROQ_API_KEY=gsk_your_key_here
HF_TOKEN=hf_your_token_here
BACKEND_URL=http://localhost:8000/api
ALLOWED_ORIGINS=http://localhost:8501

5. Run the backend

export $(grep -v '^#' .env | xargs)
uvicorn backend.app:app --reload --port 8000

6. Run the frontend (new terminal)

source .venv/bin/activate
export $(grep -v '^#' .env | xargs)
streamlit run frontend/streamlit_app.py

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


🌐 Deployment (Free)

This project is deployed using two free services:

Service What it hosts URL
HuggingFace Spaces FastAPI backend https://YOUR_USERNAME-codelens-backend.hf.space
Streamlit Community Cloud Streamlit frontend codelens-alok-yadav-25.streamlit.app

Deploy Backend β†’ HuggingFace Spaces

  1. Create a new Space at huggingface.co/spaces β†’ SDK: Docker
  2. Push this repo to the Space:
git remote add hf https://huggingface.co/spaces/YOUR_USERNAME/codelens-backend
git push hf main
  1. Add secrets in Space Settings β†’ Variables and secrets:
GROQ_API_KEY  = gsk_your_key
HF_TOKEN      = hf_your_token
ALLOWED_ORIGINS = https://codelens-alok-yadav-25.streamlit.app

Deploy Frontend β†’ Streamlit Cloud

  1. Go to share.streamlit.io β†’ New app
  2. Select this repo β†’ frontend/streamlit_app.py
  3. Add secret in Advanced settings:
BACKEND_URL = "https://YOUR_USERNAME-codelens-backend.hf.space/api"

πŸ“‘ API Reference

Base URL: http://localhost:8000 (local) or your HuggingFace Space URL

POST /api/review

Request:

{
  "code": "def divide(a, b):\n    return a / b",
  "language": "auto"
}

Response:

{
  "language": "python",
  "bugs": [
    {"line": 2, "description": "No check for division by zero when b=0"}
  ],
  "security_issues": [],
  "improvements": ["Add input validation for parameters a and b"],
  "fixes": [
    {
      "original": "return a / b",
      "suggested": "return a / b if b != 0 else None"
    }
  ],
  "performance_scores": {
    "before": {"readability": 65, "security": 70, "performance": 60, "maintainability": 55, "best_practices": 60},
    "after":  {"readability": 85, "security": 90, "performance": 80, "maintainability": 80, "best_practices": 85}
  },
  "severity": "medium",
  "summary": "The function has a critical division by zero bug..."
}

GET /api/languages

Returns the list of supported languages:

{"languages": ["python", "javascript", "typescript", "java", "go", "ruby", "php", "cpp", "rust", "swift"]}

GET /health

Liveness check for Docker/deployment health monitoring:

{"status": "ok"}

πŸ§ͺ Testing Accuracy

Run the language detection test (no backend needed):

python test_language_detection.py

Run the review quality test (backend must be running):

python test_review_quality.py

Expected results:

Test Target
Language detection > 90%
Bug detection > 75%
Security detection > 70%

πŸ”‘ Environment Variables

Variable Where Description
GROQ_API_KEY Backend Groq API key from console.groq.com
HF_TOKEN Backend HuggingFace token for CodeBERT API
ALLOWED_ORIGINS Backend CORS allowed origins (your Streamlit URL)
BACKEND_URL Frontend Full URL to FastAPI backend /api

🀝 Contributing

  1. Fork the repo
  2. Create a feature branch: git checkout -b feature/your-feature
  3. Commit changes: git commit -m "add your feature"
  4. Push to branch: git push origin feature/your-feature
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.


πŸ‘¨β€πŸ’» Author

Alok Kumar Yadav

Made with ❀️ by Alok Kumar Yadav Screenshot 2026-06-07 at 4 49 12 PM Screenshot 2026-06-07 at 4 49 38 PM Screenshot 2026-06-07 at 4 49 54 PM

About

Model-assisted code review engine leveraging CodeBERT and PyTorch for contextual suggestions.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages