An AI-powered code security scanner that uses Google Gemini API to detect vulnerabilities, security flaws, and code quality issues in your codebase.
- AI-Powered Analysis: Leverages Google Gemini 1.5 Flash for intelligent security scanning
- Comprehensive Security Checks: Detects OWASP Top 10, SQL injection, XSS, hardcoded secrets, and more
- Interactive Dashboard: Clean UI with severity-based color coding (Critical, High, Medium, Low, Info)
- Monaco Code Editor: View your code with line-by-line highlighting of vulnerabilities
- AI Chat Assistant: Ask questions about detected vulnerabilities and get expert advice
- Fix Suggestions: Every issue comes with detailed fix recommendations
- Multiple Input Methods: Upload files or paste code directly
- React 18 with TypeScript
- Vite for fast development
- Tailwind CSS for styling
- Monaco Editor for code viewing
- Axios for API calls
- Node.js with Express
- Google Gemini API for AI analysis
- SQLite for data persistence
- Better-SQLite3 for database operations
- Node.js 18+ installed
- Google Gemini API key (Get one here)
cd dh-25-pt2cd backend
npm install
# Create .env file
cp .env.example .envEdit backend/.env and add your Gemini API key:
GEMINI_API_KEY=your_actual_gemini_api_key_here
PORT=3001cd ../frontend
npm installcd backend
npm run devBackend will run on http://localhost:3001
cd frontend
npm run devFrontend will run on http://localhost:3000
- Open your browser to
http://localhost:3000 - Click "Start Security Scan"
- Either:
- Upload a code file (.js, .ts, .py, .java, .php, etc.)
- Or paste code directly into the text area
- Click "Analyze Code"
- View results in the dashboard with:
- Summary statistics by severity
- Detailed vulnerability cards
- Code viewer with line highlighting
- AI chat for questions
Three vulnerable code samples are provided in /sample-code:
- vulnerable-sql.js - SQL injection and hardcoded credentials
- vulnerable-xss.html - XSS vulnerabilities and unsafe DOM manipulation
- vulnerable-auth.py - Authentication flaws, weak crypto, command injection
Try uploading these to see CodeGuardian in action!
POST /api/analyze- Analyze code for vulnerabilitiesGET /api/scans- Get all scan historyGET /api/scans/:id- Get specific scan detailsPOST /api/chat- Chat with AI about vulnerabilitiesGET /health- Health check endpoint
dh-25-pt2/
├── frontend/
│ ├── src/
│ │ ├── components/
│ │ │ ├── LandingPage.tsx
│ │ │ ├── CodeUpload.tsx
│ │ │ ├── Dashboard.tsx
│ │ │ ├── CodeViewer.tsx
│ │ │ └── ChatBot.tsx
│ │ ├── services/
│ │ │ └── api.ts
│ │ ├── types/
│ │ │ └── index.ts
│ │ ├── utils/
│ │ │ └── severityConfig.ts
│ │ ├── App.tsx
│ │ ├── main.tsx
│ │ └── index.css
│ ├── package.json
│ └── vite.config.ts
├── backend/
│ ├── src/
│ │ ├── controllers/
│ │ │ └── scanController.js
│ │ ├── services/
│ │ │ └── geminiService.js
│ │ ├── models/
│ │ │ └── database.js
│ │ ├── routes/
│ │ │ └── scanRoutes.js
│ │ └── index.js
│ ├── package.json
│ └── .env.example
├── sample-code/
│ ├── vulnerable-sql.js
│ ├── vulnerable-xss.html
│ └── vulnerable-auth.py
└── README.md
CodeGuardian can detect:
- Injection Flaws: SQL injection, Command injection, Code injection
- Authentication Issues: Weak passwords, hardcoded credentials, session management
- Sensitive Data Exposure: API keys, passwords, tokens in code
- XSS: Reflected, Stored, and DOM-based XSS
- Broken Access Control: Missing authentication, authorization bypasses
- Security Misconfiguration: Debug mode, default credentials
- Cryptographic Issues: Weak hashing algorithms, insecure random generation
- Code Quality: Performance issues, bad practices
- Critical (Red): Immediate security risk requiring urgent attention
- High (Orange): Serious security flaw that should be fixed soon
- Medium (Yellow): Moderate risk or code quality issue
- Low (Blue): Minor issue or suggestion
- Info (Gray): Informational notice or best practice
Click "Ask AI" in the dashboard to:
- Get detailed explanations of vulnerabilities
- Learn how to implement fixes
- Understand security best practices
- Ask questions about specific issues
Example questions:
- "How do I fix the SQL injection on line 15?"
- "What's the best way to hash passwords?"
- "Explain the XSS vulnerability you found"
- Code must be under 10MB
- Analysis time depends on code size (usually 5-15 seconds)
- Requires active internet connection for Gemini API
- Some complex vulnerabilities may require manual review
- Verify your Gemini API key is set correctly in
.env - Check that port 3001 is not in use
- Run
npm installagain if dependencies are missing
- Ensure backend is running on port 3001
- Check browser console for CORS errors
- Verify API URL in
frontend/src/services/api.ts
- Try the sample files to verify setup
- Check that code is valid and parseable
- Some clean code may genuinely have no issues
# Frontend
cd frontend
npm run build
# Backend (uses npm start)
cd backend
npm startMIT
Contributions welcome! Please open an issue or PR.
For issues or questions, please open a GitHub issue.
Built with Google Gemini AI