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.
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.
- π 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
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)
| 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 |
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
- Python 3.11+
- Groq API key (free)
- HuggingFace token (free)
git clone https://github.com/YOUR_USERNAME/codelens.git
cd codelenspython -m venv .venv
source .venv/bin/activate # macOS/Linux
# .venv\Scripts\activate # Windowspip install -r requirements.txt
pip install streamlit==1.35.0 plotly==5.22.0Create 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:8501export $(grep -v '^#' .env | xargs)
uvicorn backend.app:app --reload --port 8000source .venv/bin/activate
export $(grep -v '^#' .env | xargs)
streamlit run frontend/streamlit_app.pyOpen http://localhost:8501 in your browser.
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 |
- Create a new Space at huggingface.co/spaces β SDK: Docker
- Push this repo to the Space:
git remote add hf https://huggingface.co/spaces/YOUR_USERNAME/codelens-backend
git push hf main- 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
- Go to share.streamlit.io β New app
- Select this repo β
frontend/streamlit_app.py - Add secret in Advanced settings:
BACKEND_URL = "https://YOUR_USERNAME-codelens-backend.hf.space/api"Base URL: http://localhost:8000 (local) or your HuggingFace Space URL
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..."
}Returns the list of supported languages:
{"languages": ["python", "javascript", "typescript", "java", "go", "ruby", "php", "cpp", "rust", "swift"]}Liveness check for Docker/deployment health monitoring:
{"status": "ok"}Run the language detection test (no backend needed):
python test_language_detection.pyRun the review quality test (backend must be running):
python test_review_quality.pyExpected results:
| Test | Target |
|---|---|
| Language detection | > 90% |
| Bug detection | > 75% |
| Security detection | > 70% |
| 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 |
- Fork the repo
- Create a feature branch:
git checkout -b feature/your-feature - Commit changes:
git commit -m "add your feature" - Push to branch:
git push origin feature/your-feature - Open a Pull Request
This project is licensed under the MIT License β see the LICENSE file for details.
Alok Kumar Yadav


