An AI-powered code review automation platform that integrates with GitHub and Bitbucket. It automatically reviews pull requests (PRs), generates contextual suggestions via a finetuned CodeLlama model (hosted on Ollama), and posts inline comments.
Core Capabilities:
- Fetch PR diffs via webhook
- Generate line-level suggestions
- Post inline comments
- Collect user feedback via upvotes/downvotes
- Admin moderation dashboard
- Feedback-driven LoRA model retraining
- Automatically checks for related issues linked in the PR title, body, or commit messages
Framework: Next.js
- Renders the admin dashboard, authentication screens, and connected repository views.
- Displays PR installation info, review suggestions, and feedback logs.
Framework: FastAPI
- Handles GitHub/Bitbucket webhooks, OAuth installs, feedback endpoints, PR diff parsing, and model communication.
- Secures admin APIs using JWT-based auth.
Serving: Ollama
Base Model: CodeLlama (LoRA-finetuned)
- Finetuned on curated datasets of real PR diffs and expert reviews.
- Trained using datasets like
code_alpacaand a custom internal dataset (cyber_native) - Accepts structured prompts (diff + filename + language + chunk context) and returns JSON suggestions.
π Dataset Links :
Engine: SQLite
- Built-in and used via FastAPI's ORM layer (
SQLAlchemy/pydanticmodels). - Used for login credentials, GitHub installations, and Bitbucket workspace tracking.
Feedback Storage:
- Not stored in the DB.
- All user feedback votes (π/π) are logged to
static/feedback.jsonfor moderation and model retraining.
-
PR Created or Updated
- GitHub or Bitbucket sends a webhook to
/github/webhookor/bitbucket/webhook.
- GitHub or Bitbucket sends a webhook to
-
Backend Fetches PR Diff + Metadata
- Extracts file paths, changed lines, filenames, and language hints.
-
Linked Issue Detection
- Scans the PR title, description, and commit messages for issue references (e.g.,
Fixes #42). - If found, issue details are fetched and included in the model prompt.
- Scans the PR title, description, and commit messages for issue references (e.g.,
-
Send to Model via Ollama
- A structured prompt (diff, file info, and issue context) is sent to the finetuned CodeLlama model.
-
Receive Suggestions from Model
- The model returns a JSON object with:
- Suggestion text
- Target file and line number
- Suggestion type (bug, style, improvement, etc.)
- The model returns a JSON object with:
-
Inline Comments Are Posted
- Suggestions are posted as inline comments on the PR.
-
General Comment (Optional)
- A general comment is posted summarizing whether the PR appears to address any linked issue(s).
-
Vote Buttons Included
- Each suggestion includes π / π buttons for user feedback.
-
Sign Up / Login
- Users register and log in through the frontend.
-
Connect with GitHub or Bitbucket
- OAuth flow allows users to link their account.
-
Select Repositories or Workspaces
- Users choose which repositories or workspaces to install the app on.
- When a PR is created or updated:
- The AI model automatically reviews it.
- Inline review comments appear with suggestions.
- Users can vote on each suggestion using π or π buttons.
- Admin logs in via
/auth/login(JWT-protected). - Currently supports a single user via hardcoded credentials.
/feedback-list: View all collected feedback entries./approve-feedback: Mark a suggestion as useful and accurate./reject-feedback: Mark low-quality suggestions for exclusion.
Approved feedback is used later during model finetuning.
This is the internal pipeline used to train and update the CodeLlama model that powers the review system.
-
Datasets Used
code_alpaca: General-purpose instruction datasetcyber_native: Custom PR diff + comment dataset- Augmented over time with real feedback from platform users
-
Finetuning Frameworks
- Used
Unsloth,PEFT, andLoRAfor efficient, low-resource fine-tuning - Training was done on diff chunks β comment pairs
- Used
-
Model Packaging
- After training, the LoRA adapters were merged with the base CodeLlama model using
ollama create - Final model is a self-contained
.ollamamodel ready to be served via Ollama
- After training, the LoRA adapters were merged with the base CodeLlama model using
-
Deployment & Access
- Model is hosted locally via Ollama for fast inference
- Also available on:
- Hugging Face: https://huggingface.co/rohits1711
- Ollama profile: https://ollama.com/rohits
- Node.js (for the Next.js frontend)
- Python 3.10+ (for the FastAPI backend)
- Ollama (for serving the finetuned CodeLlama model)
- Ngrok (for public webhook URL during testing)
cd client
npm install
npm run dev- Frontend runs on:
http://localhost:3000
Update .env.local:
NEXT_PUBLIC_API_URL=http://localhost:8000cd server
pip install -r requirements.txt
uvicorn main:app --port 8000- Backend runs on:
http://localhost:8000
β FastAPI serves:
- GitHub and Bitbucket webhooks
- PR diff processing
- Feedback handling
- Auth routes
- Admin panel APIs
-
Install Ollama: https://ollama.com/download
-
Run the model:
ollama run codellama:7b- Model should be available in your local Ollama registry.
- Ollama listens at
http://localhost:11434by default.
Backend .env example:
GITHUB_APP_ID=1397680
GITHUB_PRIVATE_KEY_PATH=kuriyamcodereview.2025-06-12.private-key.pem
WEBHOOK_SECRET=test-string
NGROK_URL=https://xxxx.ngrok-free.app
BITBUCKET_KEY=code-review-bot
β οΈ OnlyNGROK_URLchanges frequently. Others remain static.
Frontend .env.local:
NEXT_PUBLIC_API_URL=http://localhost:8000- Use Ngrok to expose the backend for webhook testing:
ngrok http 8000-
Set the Ngrok URL in:
.env(backend)- GitHub App Webhook URL
- Bitbucket App descriptor
baseUrl
- Install the GitHub or Bitbucket App to a test repo.
- Create a PR β webhook fires to FastAPI.
- Backend fetches the PR diff and calls the model.
- Model generates suggestions β inline comments are posted to the PR.
- General issue-related comment is posted if applicable.
- Users vote π or π on comments β votes are saved in
static/feedback.json.
- Deploy the frontend to any production-ready host.
- Ensure
.env.localis configured with the backend's production URL:
NEXT_PUBLIC_API_URL=https://your-backend.com- Deploy the FastAPI app using
uvicorn main:app --port 8000. - Environment variables must be securely defined:
GITHUB_APP_ID=...
GITHUB_PRIVATE_KEY_PATH=...
WEBHOOK_SECRET=...
BITBUCKET_KEY=code-review-bot
NGROK_URL=https://your-backend.com- SQLite is used by default (via FastAPI ORM) for login and installation tracking.
- Feedback is not stored in the database, but in
static/feedback.json.
β Update
MODEL_URLin the config file if you change the model source or endpoint.
MODEL_URL=https://your-model-server.com # Change this in core/config.py to match where model is hosted
-
Go to GitHub Developer Settings β GitHub Apps
-
Create a new app with:
-
Webhook URL:
https://your-backend.com/github/webhook -
OAuth Callback URL:
https://your-frontend.com/dashboard -
Permissions:
- Pull Requests: Read & Write
- Issues: Read
- Contents: Read-only
- Metadata: Read
-
Events:
pull_requestpushissue_commentinstallation
-
-
Generate a private key and configure these values in the backend:
GITHUB_APP_ID=...
GITHUB_PRIVATE_KEY_PATH=...
WEBHOOK_SECRET=...-
Register your app at: https://bitbucket.org/account/settings/apps
-
Set the App Descriptor URL:
https://your-backend.com/bitbucket/atlassian-connect.json
- In the descriptor JSON, update:
"baseUrl": "https://your-backend.com"- Required permissions:
- Repositories: Read
- Pull Requests: Write
- Webhooks: Read & Write
- Issues: Read
OAuth handling is automated during installation via Bitbucketβs Connect framework.
-
The platform uses a LoRA-finetuned CodeLlama model trained using:
Unsloth,LoRA, andPEFT- Datasets:
code_alpaca,cyber_native, and curated platform feedback
-
After training, adapters were merged using
ollama create. -
The model is served via Ollama and accessed at the URL configured in
MODEL_URL.
- You may change the model by replacing it in your Ollama environment and updating:
MODEL_URL=https://your-model-server.com- By default, the backend accesses the model on all origins (
localhostor remote).
| Task | Description |
|---|---|
Frontend .env.local |
Set NEXT_PUBLIC_API_URL=https://your-backend.com |
Backend .env |
Set GitHub/Bitbucket secrets and MODEL_URL |
| GitHub Webhook | Set to /github/webhook on deployed backend |
| GitHub OAuth Callback | Set to /dashboard on frontend |
| GitHub Private Key | Generated and stored securely on server |
| Bitbucket Descriptor URL | Hosted at /bitbucket/atlassian-connect.json |
Descriptor baseUrl |
Must point to production backend |
| Feedback Storage | Ensure write access to static/feedback.json |
| Model Configuration | Update MODEL_URL and ensure model is hosted/available |
| Model Source | Optional: change base or finetuned model on Ollama instance |
| Security Settings | Enable HTTPS and restrict CORS to frontend domain |