Skip to content

Latest commit

 

History

18 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🛡️ AI Code Guardian

A Sequential Multi-Agent Pipeline that scans, refactors, and documents your code — automatically.

Python LangGraph LangChain Gemini Streamlit License


📌 Problem

Developers ship unoptimized or insecure code (SQL injection, bad practices) under time pressure. Manual code review is slow, and small but critical bugs slip through human error.

💡 Solution

Instead of relying on a single general-purpose prompt, AI Code Guardian runs a team of specialized agents sequentially, each with one job, so the output is consistent and auditable at every stage:

   ┌────────────┐      ┌─────────────┐      ┌────────────┐
   │  Scanner   │ ───▶ │  Refactor   │ ───▶ │    Docs    │
   │   Agent    │      │    Agent    │      │   Agent    │
   └────────────┘      └─────────────┘      └────────────┘
   Audit Report          Clean Code           README +
                                               Docstrings

✨ Features

  • Automated Scanning & Refactoring — detects bugs, security issues (SQL injection, unsafe eval/exec, etc.) and bad practices, then rewrites the code to PEP8 standards.
  • Auto-Documentation — generates docstrings and a ready-to-ship README.md for the cleaned code.
  • Real-Time UI Tracking — a Streamlit front-end shows exactly which agent is running, live.
  • Fail-safe pipeline — if any agent errors out, the graph short-circuits instead of burning further API calls on broken input.

🧱 Tech Stack

Layer Tool
Orchestration LangGraph (StateGraph, conditional edges)
LLM Framework LangChain
Model Google Gemini (gemini-3.6-flash)
UI Streamlit (custom glass red/black theme)
Deterministic formatting autopep8
State management TypedDict (PipelineState)

📂 Project Structure

ai-code-guardian/
├── agents/
│   ├── state.py            # shared TypedDict state
│   ├── scanner_agent.py    # Agent 1 — audit
│   ├── refactor_agent.py   # Agent 2 — clean code
│   └── docs_agent.py       # Agent 3 — docstrings + README
├── sample_code/
│   └── example_buggy.py    # demo input with intentional issues
├── graph_pipeline.py        # LangGraph wiring
├── app.py                   # Streamlit UI
├── requirements.txt
└── .env

🚀 Getting Started

git clone https://github.com/HamzaAli2002/ai-code-guardian.git
cd ai-code-guardian
python -m venv venv && source venv/bin/activate   # Windows: venv\Scripts\activate
pip install -r requirements.txt

cp .env.example .env
# add your GOOGLE_API_KEY to .env (get one at aistudio.google.com/app/apikey)

streamlit run app.py

Paste code (or try sample_code/example_buggy.py) into the UI and hit Run Pipeline.

🗺️ How It Works

  1. Scanner Agent reads the raw code and returns a structured Markdown audit (security, bugs, style, performance) — it never modifies code.
  2. Refactor Agent runs autopep8 for deterministic formatting, then asks Gemini to fix everything flagged in the audit report.
  3. Docs Agent adds docstrings/comments to the clean code and writes a project-ready README.md.

State flows between agents through a single PipelineState(TypedDict), so each node only reads/writes the keys it owns.

🔭 Roadmap

  • Multi-file / repo-level scanning
  • Pluggable linters (Bandit, Ruff) as a pre-pass before the LLM
  • Diff view (before/after) in the UI
  • Export audit report as PDF

📄 License

MIT — see LICENSE.


Built as an Agentic AI coursework project — Saylani Mass IT Training SMIT.

About

AI-powered Sequential Multi-Agent Pipeline (LangGraph + Gemini) that scans, refactors, and auto-documents Python code and built with a Streamlit UI.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages