The problem
Code review is where most software defects are caught, yet in student and small-team projects it is often skipped or done superficially — reviewers skim for style while real bugs slip through. Commercial AI reviewers exist but are black boxes, and their training data and rules are hidden. This project builds the review pipeline in the open: Python code is parsed into an abstract syntax tree for exact structural checks (mutable default arguments, bare except clauses, SQL string concatenation, unused imports, deep nesting), while a CodeBERT model fine-tuned on CodeSearchNet suggests missing docstrings and summaries for undocumented functions. Because both layers are visible, the student can explain exactly how each finding is produced — a strong position for a viva. The web demo makes the pipeline tangible: paste any Python function and get an instant, categorized review with fix suggestions.
How it works
- Pasted Python source is parsed with the standard
astmodule into a syntax tree; syntax errors are reported immediately with line numbers. - A set of AST visitor rules walks the tree and records matches — for example, a
FunctionDefwhose defaults contain aListorDictnode triggers the mutable-default-argument rule. - Security patterns are matched against call sites: string-formatted SQL in
execute()calls,os.systemwith f-strings, and hardcoded credential assignments. - Undocumented public functions are passed to the fine-tuned CodeBERT model, which generates a draft docstring shown alongside the "missing documentation" finding.
- Findings are scored by severity, deduplicated, and sorted; the demo renders them with category filters (Bugs, Security, Style, Documentation).
- The summary panel aggregates counts by severity and category, and every finding links to a suggested fix snippet the student can copy.
Tech stack:
- Python 3.11,
astmodule (static analysis core) - Hugging Face Transformers, CodeBERT (microsoft/codebert-base)
- CodeSearchNet Python subset (training data)
- PyTorch (fine-tuning)
- Flask (demo backend) + HTML/CSS/JS (demo frontend)
- pytest (rule test suite)
Dataset & model details
- Dataset: CodeSearchNet (Husain et al., 2019) — 2M+ (function, documentation) pairs mined from open-source GitHub repositories across 6 languages; the Python subset (~457k pairs) is used for fine-tuning. Source: github.com/github/CodeSearchNet.
- Task: Code-to-text generation (draft a docstring/comment for a given Python function) plus AST-based defect detection as the deterministic layer.
- Model: CodeBERT (microsoft/codebert-base, 125M parameters) fine-tuned on CodeSearchNet Python pairs for comment generation; static rules implemented as
ast.NodeVisitorsubclasses. - Metrics: BLEU score on a held-out CodeSearchNet Python split for comment generation (design target, not a claimed result); per-rule precision/recall measured on the shipped labeled test suite and reported honestly in the report.
| Parameter | Value |
|---|---|
| Input | Python 3 source, single file or pasted snippet |
| Static rules | 18 AST/security checks (documented list) |
| Model | CodeBERT-base fine-tune, ~125M parameters (design target) |
| Comment BLEU | Design target on held-out split (reported after training) |
| Demo latency | Under 2 s for a 500-line file on CPU (expected) |
| Demo | Single-file web app, runs offline after download |
| Fine-tuning | Approximately 2–4 h on a single GPU (expected) |
Project features
- [AST-based static checks] Deterministic analysis over the Python abstract syntax tree catches structural bugs — mutable default arguments, bare
except:,eval()usage, unused imports and variables, and functions with excessive complexity. - [CodeBERT comment generation] A CodeBERT model fine-tuned on CodeSearchNet Python pairs drafts docstrings for undocumented functions, demonstrating transformer-based code understanding.
- [Security-focused rules] Flags SQL string concatenation, hardcoded credentials,
pickle.loadson untrusted data and shell injection patterns, each with a plain-language risk explanation. - [Severity-ranked findings] Every issue is scored and grouped as Critical, Warning or Suggestion, so the most dangerous problems surface first.
- [Fix suggestions] Each finding ships with a concrete corrected code snippet, not just a complaint — the demo shows before/after for every rule.
- [Live web demo] Paste Python code and get an instant review in the browser: findings list, severity filters, per-rule explanations and an issue summary panel.
- [Rule test suite] Each checker ships with positive and negative test cases, so the report documents exactly what the tool catches and what it misses.
What is included
- AST-based static checker source code (18 documented rules)
- Fine-tuned CodeBERT adapter weights for docstring generation
- Training notebook (CodeSearchNet loading, fine-tuning, BLEU evaluation)
- Live web demo wired to the checker and model
- Per-rule test suite with positive/negative cases
- Project report PDF (background, transformer code models, rule design, methodology, results)
- PPT presentation for final review
- Viva Q&A preparation document (ASTs, CodeBERT, BLEU, static vs dynamic analysis)
Limitations & prerequisites
- Static rules are pattern-based and can miss novel bug shapes; they complement, not replace, human review.
- Comment generation quality is bounded by CodeSearchNet docstring quality, which varies across repositories.
- BLEU is reported as a design target — the report documents the actual achieved score after the training run.
- The checker targets Python 3 only; other languages are out of scope.
- Security rules flag suspicious patterns but do not perform taint tracking, so some findings need human confirmation.
Frequently Asked Questions
How is this different from a linter like pylint?
Linters check style and simple errors. This project adds a transformer model that understands code semantics (drafting docstrings, explaining issues) and a documented rule engine built from scratch, which gives you genuine viva material about how both layers work.
Which dataset trains the model?
CodeSearchNet's Python subset — roughly 457,000 real function–documentation pairs from open-source GitHub projects. It is the standard public dataset for code intelligence tasks.
Can it find real bugs?
The AST rules catch real structural defects (mutable defaults, bare excepts, SQL injection patterns) with exact precision on their patterns; the report's test suite shows measured precision/recall per rule. The model layer drafts documentation rather than claiming to find novel bugs.
Does it work on my own code?
Yes — paste any Python 3 snippet into the demo. Very long files are truncated at a documented limit for demo responsiveness.
What do I need to run it?
Python 3.11, PyTorch and the Hugging Face Transformers library; fine-tuning needs a GPU, inference runs on CPU.
Is this project suitable for a final-year project?
Yes — for Computer Science, IT and AI/ML programs. It combines program analysis with transformer-based code models and ships a genuinely usable tool. Suitable for B.E./B.Tech final-year projects in Computer Science, IT and AI & Machine Learning.
Components & software requirements
- Python 3.11,
astmodule (static analysis core) - Hugging Face Transformers, CodeBERT (microsoft/codebert-base)
- CodeSearchNet Python subset (training data)
- PyTorch (fine-tuning)
- Flask (demo backend) + HTML/CSS/JS (demo frontend)
- pytest (rule test suite)
Dataset & model details
- Dataset: CodeSearchNet (Husain et al., 2019) — 2M+ (function, documentation) pairs mined from open-source GitHub repositories across 6 languages; the Python subset (~457k pairs) is used for fine-tuning. Source: github.com/github/CodeSearchNet.
- Task: Code-to-text generation (draft a docstring/comment for a given Python function) plus AST-based defect detection as the deterministic layer.
- Model: CodeBERT (microsoft/codebert-base, 125M parameters) fine-tuned on CodeSearchNet Python pairs for comment generation; static rules implemented as
ast.NodeVisitorsubclasses. - Metrics: BLEU score on a held-out CodeSearchNet Python split for comment generation (design target, not a claimed result); per-rule precision/recall measured on the shipped labeled test suite and reported honestly in the report.
Delivery information
Built-to-order project. Delivery timeline is shared after order confirmation based on current queue.
Support terms
Complete documentation, setup guide, and viva preparation included. Support for setup and explanation provided.