Skip to content

ShreyaVijaykumar/DiffInsight

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

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

Repository files navigation

DiffInsight


DiffInsight is a developer tool that transforms Git diffs into clear, structured, and risk-assessed code review reports. Designed for developers, team leads, and code reviewers, it highlights what changed, why it matters, and what risks it carries β€” powered by a local LLM and presented in a clean, dark-themed web interface.

Upload a .diff, .patch, or .txt file (or paste your diff directly), and DiffInsight generates actionable insights, a 5-axis risk radar, and a team-aware change breakdown β€” all running fully locally, no cloud required.


πŸ’‘ Key Features

  • LLM-powered code review reports via Ollama (deepseek-coder:6.7b) β€” runs entirely on your machine.
  • Two review modes: Senior Reviewer (concise, critical) and Junior Mentor (explanatory, educational).
  • 5-axis Risk Radar β€” pattern-based scoring across Security, Performance, Complexity, Stability, and Testing.
  • Change Intelligence panel β€” team-aware diff breakdown that works on any language:
    • Which architectural layers were touched (Backend, LLM/AI, Security, Frontend, Tests, Config, Database…)
    • Per-file change classification: NEW, MODIFIED, REFACTORED, EXPANDED, DELETED
    • Merge conflict candidate detection with High/Medium/Low risk per file
    • Churn bar visualisation showing relative size of each change
    • File type (extension) breakdown
  • Tech Assistant β€” ask any technical question, topic auto-detected, answered by the local LLM.
  • GitHub Explorer β€” search repositories by topic, filter by language, sort by stars/forks/issues/watchers/updated.
  • Secrets via HashiCorp Vault β€” GitHub token stored and retrieved securely; falls back to GITHUB_TOKEN env var.
  • Rate limiting β€” 10 requests per 60 seconds per IP.
  • File upload + paste β€” upload .diff/.patch/.txt (max 5MB) or paste a diff directly into the UI.
  • Health indicators β€” live Ollama and Vault status dots in the sidebar.
  • Supports standard git diff, diff -ruN, and most unified diff variants.

🌟 Why DiffInsight Matters

  • Accelerates code reviews β€” identify critical issues without manually scanning every line.
  • Reduces merge risk β€” conflict candidates are flagged before you merge.
  • Team-aware β€” when multiple people share a repo, Change Intelligence shows exactly which layers and files each diff touches, making coordination easier.
  • Educates junior developers β€” Junior Mentor mode explains changes with context and best-practice guidance.
  • Fully local β€” your code never leaves your machine. LLM inference runs via Ollama, secrets via Vault.

🎯 Target Audience

  • Software engineers wanting faster, more consistent code reviews.
  • Team leads seeking risk-aware insights before approving merges.
  • Junior developers learning best practices through guided diff explanations.
  • Teams sharing a dev machine or repo who need to coordinate changes without stepping on each other.
  • Open-source contributors reviewing PRs or comparing branches.

πŸ—‚οΈ Project Structure

diffinsight/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ main.py                        # FastAPI app, endpoints, radar scoring
β”‚   β”œβ”€β”€ llm/
β”‚   β”‚   β”œβ”€β”€ analyzer.py                # LLM diff analysis (reviewer/junior modes)
β”‚   β”‚   └── tech_assistant.py          # Tech Q&A with topic detection
β”‚   β”œβ”€β”€ security/
β”‚   β”‚   └── secret_manager.py          # HashiCorp Vault + env var fallback
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   └── github_service.py          # GitHub search (sort, filter, paginate)
β”‚   └── utils/
β”‚       β”œβ”€β”€ change_intelligence.py     # Team-aware diff breakdown (NEW)
β”‚       └── risk.py                    # Risk level computation
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ templates/
β”‚   β”‚   └── index.html                 # Main UI
β”‚   └── static/
β”‚       β”œβ”€β”€ script.js                  # All frontend logic + Change Intelligence renderer
β”‚       └── style.css                  # Dark theme styles
β”œβ”€β”€ dev.ps1                            # PowerShell dev runner
└── requirements.txt

πŸ› οΈ Installation & Setup

Prerequisites

  • Python 3.10+
  • Ollama installed and running
  • HashiCorp Vault (optional β€” for GitHub Explorer)
  • A GitHub personal access token (for GitHub Explorer)

1. Clone the repository

git clone https://github.com/ShreyaVijaykumar/Diff-Insight.git
cd diffinsight

2. Install dependencies

pip install -r requirements.txt

3. Pull the LLM model

ollama pull deepseek-coder:6.7b

4. Start Ollama

ollama serve

5. Set up HashiCorp Vault (for GitHub Explorer)

Open a PowerShell terminal and start Vault in dev mode:

vault server -dev

Copy the Root Token printed in the terminal (starts with hvs.). Then open a second terminal and run:

# Set Vault address
$env:VAULT_ADDR="http://127.0.0.1:8200"

# Set your root token
$env:VAULT_TOKEN="hvs.<YOUR_ROOT_TOKEN>"

# Store your GitHub personal access token
vault kv put secret/github token=<YOUR_GITHUB_TOKEN>

To verify everything is set correctly:

echo $env:VAULT_ADDR
echo $env:VAULT_TOKEN
vault kv get secret/github

No Vault? You can skip this and set GITHUB_TOKEN=<your_token> as a regular environment variable instead. GitHub Explorer will fall back to it automatically.

6. Start DiffInsight

From the project root (diffinsight/):

uvicorn backend.main:app --reload

Or use the PowerShell dev runner:

powershell -ExecutionPolicy Bypass -File dev.ps1

7. Open in browser

http://127.0.0.1:8000/

πŸ“„ How to Generate a Git Diff File

Common commands

# Unstaged changes
git diff

# Staged changes
git diff --staged

# All changes since last commit
git diff HEAD

# Compare two commits
git diff <commit-id-1> <commit-id-2> > my_diff.txt

# Compare two branches
git diff main feature-branch > branch_diff.txt

# Compare a specific file
git diff <file-path> > file_diff.txt

# Compare tags
git diff v1.0 v1.1 > tag_diff.txt

Save the output with > to create a .txt or .diff file, then upload it to DiffInsight β€” or paste the output directly using the Paste Diff toggle.

Understanding diff output

Symbol Meaning
--- a/file.txt Original file
+++ b/file.txt Updated file
@@ -m,n +o,p @@ Hunk header (line numbers)
- Line removed
+ Line added
(no symbol) Unchanged context

For a graphical comparison:

git difftool

πŸ§‘β€πŸ’» How It Works

  1. Upload or paste a .diff, .patch, or .txt file.
  2. DiffInsight normalises the diff (handles git diff, diff -ruN, and similar formats).
  3. Risk Radar scores the diff across 5 axes using regex-based pattern detection β€” no LLM needed for this step, so it's instant.
  4. Change Intelligence parses every file in the diff and classifies it by layer, change type, and merge conflict risk β€” also instant, works on any language.
  5. LLM report is generated by Ollama using the selected mode (Senior Reviewer or Junior Mentor).
  6. Everything is displayed in the single-page dashboard β€” no page reload needed.

πŸ–₯️ Features In Detail

Diff Analyzer

  • Toggle between file upload and paste input.
  • Select Senior Reviewer (concise, critical) or Junior Mentor (educational, step-by-step).
  • Stats bar shows files changed, lines added/removed, functions modified, and overall risk level.

Risk Radar

Pattern-based scores (0–10) across five dimensions:

Axis What it detects
Security Hardcoded secrets, auth/crypto keywords, sensitive patterns
Performance N+1 query patterns, loops with DB calls, missing cache/async
Complexity Branch depth, nesting, lambda/comprehension density, net line growth
Stability Config/migration file changes, API surface churn, deletion ratio
Testing Assert/mock/test function presence, untested addition penalty

Change Intelligence

Replaces the dependency graph with a team-friendly breakdown that works on any language:

  • Summary bar β€” one-line description: how many files, which layers, additive/refactor/mixed/destructive.
  • Layers Touched β€” which parts of the codebase were affected (LLM/AI, Security, Backend, Frontend JS/CSS, Frontend HTML, Tests, Config/Infra, Database, Docs…).
  • Merge Conflict Candidates β€” files flagged High or Medium risk based on deletion ratio and churn volume.
  • File Breakdown β€” every changed file with change type badge, +/- counts, conflict risk, and a proportional churn bar.
  • File Types β€” extension summary for a quick "was this a backend-only or full-stack change?" read.

Tech Assistant

Ask any technical question in plain English. The assistant auto-detects the topic (40+ keywords including Python, FastAPI, Docker, PostgreSQL, Redis, Terraform, AWS, PyTorch, RAG, and more) and answers with a structured explanation, real-world example, industry use, and common misconception.

GitHub Explorer

Search GitHub repositories by topic, filter by language, and sort by:

  • ⭐ Most Stars
  • 🍴 Most Forks
  • πŸ•’ Recently Updated
  • πŸ› Most Issues
  • πŸ‘οΈ Most Watchers

Results show name, description, all 5 metrics, last updated date, and a direct link.


πŸ‘€ Preview

DIFFINSIGHT REPORT
------------------
Risk Level : HIGH

TITLE: Refactor login flow
CHANGE_SUMMARY: Simplified authentication logic and fixed edge cases
MODIFIED_FILES: auth.py, login.py
WHAT_CHANGED: Updated login flow, added error handling
WHY_CHANGED: Improve security and readability
RISK_LEVEL: HIGH
IMPACT: High risk on authentication
REVIEWER_NOTES: Ensure unit tests are added for all new auth paths

Change Intelligence panel example output:

πŸ”€ Mixed  |  4 files changed across 3 layers (Backend, LLM / AI, Tests) β€” +87 / -32 lines

Layers Touched:  βš™οΈ Backend (2)   πŸ€– LLM / AI (1)   πŸ§ͺ Tests (1)

⚠️ Merge Conflict Candidates
  backend/utils/risk.py       High risk     +2 / -9
  backend/main.py             Medium risk   +15 / -6

File Breakdown:
  REFACTORED  backend/utils/risk.py        βš™οΈ Backend     +2  -9   High conflict risk   
  EXPANDED    backend/main.py              βš™οΈ Backend    +15  -6  Medium conflict risk  
  NEW         backend/llm/analyzer.py      πŸ€– LLM / AI   +58  -0    Low conflict risk   
  MODIFIED    tests/test_risk.py           πŸ§ͺ Tests      +12  -17    Low conflict risk  

πŸ“ˆ Impact

  • Reduces time spent manually reviewing diffs.
  • Flags merge conflict candidates before they cause problems.
  • Gives team members visibility into which layers a change touches.
  • Educates junior developers through structured, mode-aware explanations.
  • Keeps all analysis local β€” no data leaves your machine.

πŸ”’ Security Notes

  • GitHub tokens are stored in HashiCorp Vault (KV v2), never in code or .env files.
  • Vault token is stripped of whitespace on read to prevent header injection bugs.
  • If Vault is unavailable, the app falls back to the GITHUB_TOKEN environment variable.
  • The LLM runs locally via Ollama β€” no diff content is sent to external APIs.
  • Rate limiting (10 req/60s per IP) is applied to all endpoints.

About

DiffInsight is a lightweight, interactive tool that transforms Git diffs into clear, structured, and risk-assessed code review reports. Designed for developers, team leads, and code reviewers, it highlights what changed, why it changed, and its impact along few more features.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors