Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 SmartCode

AI-powered code review that understands intent, not just syntax.

Demo β€’ Architecture β€’ Quick Start β€’ Example Review β€’ Tech Stack β€’ Roadmap

Python FastAPI React LLM License


🚨 The Problem

Code reviews are the biggest bottleneck in software delivery.

  • The average PR waits 24+ hours for human review

  • Reviews are inconsistent β€” quality depends entirely on who reviews

  • Existing tools catch syntax issues but miss the real question:

    "Does this PR actually implement what was requested, and is it safe to merge?"

Tool What It Does What It Misses
GitHub Copilot Autocompletes code Doesn't review PRs or validate requirements
CodeQL / Semgrep Rule-based SAST scanning Can't reason about feature completeness
SonarQube Tracks tech debt metrics No PR-level intelligence, no requirement tracing
SmartCode AI review: requirement drift + security + performance + confidence scoring β€”

πŸ’‘ The Solution

SmartCode is an AI-powered GitHub App that reviews pull requests like a Senior Staff Engineer β€” checking not just code quality, but whether the code actually does what the issue asked for.

✨ Key Capability: PR Approval Confidence Score

A 0-100% composite score that tells you how safe it is to merge this PR, combining:

Dimension Weight What It Measures
Requirement Alignment 30% Do changes match linked issues?
Security Safety 25% Are there vulnerabilities?
Code Quality 20% Complexity, patterns, tech debt
Test Coverage Signal 15% Are tests added/modified?
Static Analysis 10% Linting + pattern results

Verdicts:

  • 🟒 80-100: APPROVE β€” safe to merge
  • 🟑 60-79: REVIEW_NEEDED β€” human should check flagged items
  • πŸ”΄ 0-59: CHANGES_REQUESTED β€” significant issues found

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        SmartCode Platform                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚  GitHub App  │───▢│  Webhook Handler │───▢│   Celery Worker  β”‚    β”‚
β”‚  β”‚  (Webhooks)  β”‚    β”‚  (FastAPI)       β”‚    β”‚   (Redis Queue)  β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚                              β”‚                        β”‚              β”‚
β”‚                              β–Ό                        β–Ό              β”‚
β”‚                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚                    β”‚   REST API       β”‚    β”‚  Analysis Pipeline   β”‚  β”‚
β”‚                    β”‚  /api/review     β”‚    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚
β”‚                    β”‚  /api/metrics    β”‚    β”‚  β”‚ Context Extract β”‚  β”‚  β”‚
β”‚                    β”‚  /api/analyze    β”‚    β”‚  β”‚ Static Analysis β”‚  β”‚  β”‚
β”‚                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚  β”‚ LLM Reasoning  β”‚  β”‚  β”‚
β”‚                             β”‚              β”‚  β”‚ Confidence Scoreβ”‚  β”‚  β”‚
β”‚                             β–Ό              β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚
β”‚                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                    β”‚   PostgreSQL     β”‚               β”‚              β”‚
β”‚                    β”‚   (Reviews +     β”‚β—€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β”‚
β”‚                    β”‚    Findings)     β”‚                              β”‚
β”‚                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                              β”‚
β”‚                             β”‚                                        β”‚
β”‚                             β–Ό                                        β”‚
β”‚                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚                    β”‚  React Dashboard β”‚    β”‚  GitHub PR Comment   β”‚  β”‚
β”‚                    β”‚  (Metrics + UI)  β”‚    β”‚  (Auto-posted)       β”‚  β”‚
β”‚                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🎬 Demo Workflow

Developer opens PR ──▢ GitHub fires webhook
                           β”‚
                           β–Ό
                   POST /webhook/github
                   (signature verified)
                           β”‚
                           β–Ό
                   Review record created
                   (status: "pending")
                           β”‚
                           β–Ό
                   Celery task queued
                   analyze_pull_request()
                           β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β–Ό                         β–Ό
        Context Extraction        Static Analysis
        β”œβ”€β”€ PR diff               β”œβ”€β”€ AST complexity
        β”œβ”€β”€ Linked issues         β”œβ”€β”€ Diff structure
        └── Project docs          └── Dependency changes
              β”‚                         β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β–Ό
                    LLM AI Reasoning
                    β”œβ”€β”€ Requirement alignment
                    β”œβ”€β”€ Security scan
                    β”œβ”€β”€ Performance check
                    └── Code quality review
                           β”‚
                           β–Ό
                   Confidence Scoring
                   β”œβ”€β”€ 5-dimension breakdown
                   β”œβ”€β”€ Risk flags
                   └── Verdict (APPROVE / REVIEW_NEEDED / CHANGES_REQUESTED)
                           β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β–Ό                         β–Ό
        Findings β†’ DB              GitHub PR Comment
        (PostgreSQL)               (auto-posted)

πŸ“‹ Example AI Review

When SmartCode reviews a PR, it automatically posts a comment like this:

## πŸ€– SmartCode AI Review

**PR Confidence Score: 72/100** β€” ⚠️ REVIEW NEEDED

### πŸ“Š Score Breakdown
| Dimension | Score |
|-----------|-------|
| Requirement Alignment | 85/100 |
| Security Safety | 58/100 |
| Code Quality | 70/100 |
| Test Coverage | 45/100 |
| Static Analysis | 82/100 |

### πŸ” Findings (4 issues)

#### πŸ”΄ CRITICAL β€” SQL Injection in payment query handler
**File:** `src/payments/queries.py:42`

query = f"SELECT * FROM payments WHERE user_id = '{user_id}'"

**Suggested Fix:** Use parameterized queries:
cursor.execute("SELECT * FROM payments WHERE user_id = %s", (user_id,))

**Confidence:** 95% Β· **Ref:** CWE-89, OWASP A03:2021

---

#### πŸ”΄ HIGH β€” Missing pagination for transaction listing
**File:** `src/payments/routes.py:67`
Issue #189 requires paginated transaction listing.
Current implementation returns all records with no limit.

**Suggested Fix:** Add limit/offset parameters to the query.
**Confidence:** 88% Β· **Ref:** Issue #189

---

#### 🟑 MEDIUM β€” N+1 query in payment detail enrichment
**File:** `src/payments/service.py:91`
1001 queries instead of 2 for 1000 payments.

**Suggested Fix:** Prefetch merchants with a single IN query.
**Confidence:** 82%

---

#### 🟒 LOW β€” Missing error handling for external API call
**File:** `src/payments/gateway.py:128`

**Suggested Fix:** Add timeout and try/except for request failures.
**Confidence:** 76%

---

> πŸ’‘ Powered by SmartCode β€” AI Code Review that understands intent

πŸ“Š Metrics & Scoring

SmartCode calculates four measurable indicators for every review:

Metric Range What It Measures
Bug Risk Score 0-100 Inverse severity-weighted finding count
Review Confidence 0-100% Composite PR safety score
Security Severity Index 0.0-10.0 Vulnerability density per file
Technical Debt Indicator 0.0-10.0 Complexity + nesting + function sprawl

πŸ› οΈ Tech Stack

Layer Technology
Backend Python 3.11+, FastAPI, Celery
Database PostgreSQL 15+ (SQLite for dev)
Queue Redis 7+
LLM OpenRouter β†’ DeepSeek R1
Static Analysis AST (Python), Tree-sitter, Semgrep
GitHub GitHub App, Webhooks, PyGithub
Frontend React 18+, TypeScript, Recharts, shadcn/ui
Deployment Docker, Docker Compose

πŸš€ Quick Start

Local Development (minimal)

# 1. Clone and setup
git clone https://github.com/riyaa1611/SmartCode.git
cd SmartCode

# 2. Create virtual environment
python -m venv .venv
.venv\Scripts\Activate.ps1        # PowerShell
# source .venv/bin/activate       # macOS/Linux

# 3. Install dependencies
pip install -r requirements.txt

# 4. Configure environment
cp .env.example .env
# Edit .env with your OPENROUTER_API_KEY

# 5. Initialize database
python init_db.py

# 6. Run the server
uvicorn main:app --host 127.0.0.1 --port 8084 --reload

Docker Compose (full stack)

docker compose up --build -d
docker compose exec smartcode-app python init_db.py

Frontend Development

cd frontend
npm install
npm run dev

Test the Demo Endpoint

curl http://localhost:8084/api/demo/review/1 | python -m json.tool

πŸ—ΊοΈ Roadmap

  • GitHub App webhook integration
  • AI-powered PR review (security, performance, requirements)
  • PR Approval Confidence Score (0-100)
  • Structured findings with suggested fixes
  • Metrics dashboard (Bug Risk, Security Index, Tech Debt)
  • Multi-repo evaluation framework
  • Custom architectural rule definitions
  • Learning from developer feedback (accept/dismiss signals)
  • VS Code extension for inline review
  • Dependency vulnerability scanning integration

πŸ“ Project Structure

SmartCode/
β”œβ”€β”€ main.py                          # FastAPI application entry point
β”œβ”€β”€ config.py                        # Environment-based settings
β”œβ”€β”€ models.py                        # SQLAlchemy models (Review, Finding)
β”œβ”€β”€ worker.py                        # Celery worker β€” full analysis pipeline
β”œβ”€β”€ database.py                      # Database engine + session
β”œβ”€β”€ analysis_engine/
β”‚   β”œβ”€β”€ llm_reviewer.py              # LLM-powered review (4 dimensions)
β”‚   β”œβ”€β”€ prompt_templates.py          # Production-grade prompt templates
β”‚   β”œβ”€β”€ confidence_scorer.py         # PR Approval Confidence Score
β”‚   β”œβ”€β”€ metrics_calculator.py        # Bug Risk, Security Index, Tech Debt
β”‚   β”œβ”€β”€ code_analyzer.py             # AST complexity + diff analysis
β”‚   β”œβ”€β”€ requirement_extractor.py     # Issue β†’ requirements parser
β”‚   └── aggregator.py                # Findings aggregation + DB mapping
β”œβ”€β”€ github_integration/
β”‚   └── client.py                    # GitHub App auth + PR commenting
β”œβ”€β”€ data_pipeline/
β”‚   └── collector.py                 # PR, issue, and project data collector
β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ api.py                       # REST API endpoints
β”‚   β”œβ”€β”€ webhook.py                   # GitHub webhook handler
β”‚   └── health.py                    # Health check
β”œβ”€β”€ frontend/                        # React 18 + TypeScript dashboard
β”œβ”€β”€ docker-compose.yml               # Postgres + Redis + app
β”œβ”€β”€ Dockerfile                       # Container build
└── CAREER.md                        # Resume + portfolio positioning

🀝 Contributing

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

πŸ“„ License

MIT License β€” see LICENSE for details.


Built with ❀️ as a production-grade AI developer tool

Problem β€’ Solution β€’ Architecture β€’ Quick Start

About

Smart GitHub code review bot Demo application

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages