Skip to content

Repository files navigation

🛡️ CodeSentinel

AI-powered code review platform that analyzes GitHub pull requests using LLMs to detect bugs, security vulnerabilities, and code quality issues — with line-level feedback.

Live Demo · API Docs · Architecture

TypeScript FastAPI Next.js PostgreSQL OpenAI Docker


The Problem

Manual code reviews are slow, inconsistent, and miss subtle bugs. Engineering teams waste hours on reviews that could be automated, and junior developers often lack senior-level feedback on their pull requests.

The Solution

CodeSentinel integrates directly with GitHub repositories via webhooks. When a pull request is opened or updated, CodeSentinel:

  1. Receives the webhook event and extracts the diff
  2. Queues the review job for async processing via Redis
  3. Analyzes the code using LLM-powered pipelines (OpenAI GPT-4)
  4. Posts line-level feedback directly on the PR as review comments

The result: instant, senior-engineer-quality code reviews on every pull request.

Key Features

  • 🔍 Deep Static Analysis — LLM-powered analysis that goes beyond linting to catch logic errors, anti-patterns, and missed edge cases
  • 🛡️ Security Scanning — Detects common vulnerabilities (SQL injection, XSS, hardcoded secrets, insecure dependencies)
  • 📝 Line-Level Feedback — Comments are posted on specific lines in the PR diff, not as a wall of text
  • Async Processing — Webhook → Redis queue → worker pipeline. Reviews don't block your CI.
  • 🔗 GitHub Integration — Native GitHub App with webhook receiver and PR comment API
  • 📊 Dashboard — Next.js frontend to monitor reviews, configure repos, and view analytics
  • 🏗️ Multi-File Analysis — Reviews entire PRs across multiple files, understanding cross-file dependencies

Architecture

┌─────────────────┐      ┌──────────────────┐      ┌──────────────┐
│   GitHub         │─────▶│  FastAPI          │─────▶│  Redis       │
│   Webhook Event  │      │  Webhook Receiver │      │  Job Queue   │
└─────────────────┘      └──────────────────┘      └──────┬───────┘
                                                          │
                                                          ▼
┌─────────────────┐      ┌──────────────────┐      ┌──────────────┐
│  GitHub PR       │◀─────│  Review           │◀─────│  LLM Worker  │
│  Line Comments   │      │  Publisher         │      │  (OpenAI)    │
└─────────────────┘      └──────────────────┘      └──────────────┘
                                │
                                ▼
                         ┌──────────────┐      ┌──────────────┐
                         │  PostgreSQL   │      │  Next.js     │
                         │  (Results DB) │◀────▶│  Dashboard   │
                         └──────────────┘      └──────────────┘

Data flow:

  1. Developer opens a PR on a connected GitHub repository
  2. GitHub sends a webhook event to the FastAPI receiver
  3. The receiver validates the payload and enqueues a review job in Redis
  4. A background worker picks up the job, fetches the PR diff, and sends it to the OpenAI API
  5. The LLM returns structured findings (bugs, security issues, style suggestions) with line references
  6. The publisher posts line-level review comments back to the GitHub PR via the GitHub API
  7. All results are persisted in PostgreSQL and visible on the Next.js dashboard

Tech Stack

Layer Technology Why
Backend API FastAPI (Python) Async-native, auto-generated OpenAPI docs, type safety with Pydantic
Frontend Next.js 14 (TypeScript) App Router, Server Components, fast SSR
Database PostgreSQL Relational integrity for review data, user configs, repo settings
Queue Redis Lightweight async job processing, pub/sub for real-time updates
AI/LLM OpenAI GPT-4 API Best-in-class code understanding for review generation
Auth GitHub OAuth Seamless authentication via GitHub identity
Deployment Vercel (frontend) · Docker (backend) Zero-config frontend deploys, containerized backend

Project Structure

codesentinel-platform/
├── backend/
│   ├── app/
│   │   ├── api/              # Route handlers (webhooks, reviews, repos, auth)
│   │   │   ├── webhooks.py   # GitHub webhook receiver & validation
│   │   │   ├── reviews.py    # Review CRUD endpoints
│   │   │   └── repos.py      # Repository management
│   │   ├── core/             # Config, security, dependency injection
│   │   │   ├── config.py     # Environment variable management
│   │   │   └── security.py   # Webhook signature verification
│   │   ├── models/           # SQLAlchemy ORM models
│   │   ├── schemas/          # Pydantic request/response schemas
│   │   ├── services/         # Business logic layer
│   │   │   ├── review.py     # Review orchestration engine
│   │   │   ├── llm.py        # OpenAI API client & prompt engineering
│   │   │   └── github.py     # GitHub API client (PR comments, diff fetching)
│   │   ├── workers/          # Async queue consumers (Redis workers)
│   │   └── main.py           # FastAPI application entrypoint
│   ├── tests/                # pytest test suite
│   ├── Dockerfile
│   ├── requirements.txt
│   └── .env.example
├── frontend/
│   ├── src/
│   │   ├── app/              # Next.js App Router pages
│   │   ├── components/       # React components (ReviewCard, RepoList, etc.)
│   │   └── lib/              # API client, utilities, types
│   ├── package.json
│   └── next.config.js
├── docker-compose.yml        # Full stack: backend + frontend + postgres + redis
├── .github/
│   └── workflows/
│       └── ci.yml            # GitHub Actions CI pipeline
└── README.md

Getting Started

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • PostgreSQL 15+
  • Redis 7+
  • OpenAI API key
  • GitHub App credentials (for webhook integration)

Installation

# Clone the repository
git clone https://github.com/hosama-adem/codesentinel-platform.git
cd codesentinel-platform

# Backend setup
cd backend
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt

# Frontend setup
cd ../frontend
npm install

Environment Variables

Create .env files in both backend/ and frontend/ directories. See .env.example for reference.

backend/.env

# Database
DATABASE_URL=postgresql://user:password@localhost:5432/codesentinel

# Redis
REDIS_URL=redis://localhost:6379

# OpenAI
OPENAI_API_KEY=sk-...
OPENAI_MODEL=gpt-4

# GitHub App
GITHUB_APP_ID=123456
GITHUB_PRIVATE_KEY_PATH=./private-key.pem
GITHUB_WEBHOOK_SECRET=whsec_...

# Server
HOST=0.0.0.0
PORT=8000
DEBUG=true

frontend/.env.local

NEXT_PUBLIC_API_URL=http://localhost:8000
NEXT_PUBLIC_GITHUB_CLIENT_ID=Iv1.abc123

Running Locally

# Option 1: Docker Compose (recommended)
docker-compose up --build

# Option 2: Manual
# Terminal 1 — Backend
cd backend && uvicorn app.main:app --reload --port 8000

# Terminal 2 — Worker
cd backend && python -m app.workers.review_worker

# Terminal 3 — Frontend
cd frontend && npm run dev

The application will be available at:

API Documentation

Interactive Swagger docs are available at /docs when the backend is running.

Core Endpoints

Method Endpoint Description
POST /api/v1/webhooks/github Receives GitHub webhook events (PR opened/updated)
GET /api/v1/reviews List all code reviews (paginated, filterable)
GET /api/v1/reviews/{id} Get detailed review with all findings
GET /api/v1/reviews/{id}/findings Get individual findings with line references
POST /api/v1/repos Register a repository for automated review
GET /api/v1/repos List connected repositories
DELETE /api/v1/repos/{id} Disconnect a repository
GET /api/v1/analytics Review statistics, trends, and metrics

Example Response

{
  "id": "rev_abc123",
  "repository": "hosama-adem/my-project",
  "pull_request": 42,
  "status": "completed",
  "findings": [
    {
      "type": "bug",
      "severity": "high",
      "file": "src/auth/handler.py",
      "line": 47,
      "message": "SQL query constructed with string concatenation. Use parameterized queries to prevent SQL injection.",
      "suggestion": "cursor.execute('SELECT * FROM users WHERE id = %s', (user_id,))"
    }
  ],
  "summary": {
    "total_findings": 5,
    "bugs": 2,
    "security": 1,
    "style": 2
  },
  "created_at": "2026-07-15T14:30:00Z"
}

Roadmap

  • GitHub webhook integration
  • LLM-powered code analysis with OpenAI GPT-4
  • Line-level PR review comments
  • Next.js dashboard with review history
  • PostgreSQL persistence layer
  • Async job processing with Redis
  • Multi-model support (Claude, Gemini, open-source models)
  • Custom review rule configuration per repository
  • Team analytics dashboard with trends
  • GitLab and Bitbucket integration
  • Self-hosted deployment guide with Helm chart
  • VS Code extension for in-editor feedback

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for guidelines.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Write tests for your changes
  4. Commit using conventional commits (git commit -m 'feat: add amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a Pull Request

License

This project is licensed under the MIT License — see the LICENSE file for details.


Built by Hosama Adem

About

AI-powered code review & security scanner that analyzes pull requests for vulnerabilities, logic bugs, and style issues — built with FastAPI, React/TypeScript, and Docker.

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages