CodeShield AI is a state-of-the-art, enterprise-quality codebase security analyzer.
2.8K
CodeShield AI is an enterprise-quality codebase security analyzer and college project integrating a modern frontend, FastAPI backend, and Render PostgreSQL database. It automates remote repository cloning, dependency mapping, intelligent code chunking, and leverages Groq's Large Language Models (LLMs) alongside static scanners to detect, score, and automatically remediate vulnerabilities.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend Dashboard / User Profile (/profile) β
ββββββββββββββββ¬ββββββββββββββββββββββββββββββββ¬βββββββββββββββ
β (Public / Guest Scans) β (Auth & Profile)
βΌ βΌ
βββββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββ
β FastAPI Scanner Endpoints β β FastAPI Auth & DB Router β
ββββββββββββββββ¬βββββββββββββββββ βββββββββββββββ¬ββββββββββββββ
β β (SQLAlchemy ORM)
βΌ βΌ
βββββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββ
β ScanStateManager (Disk Cache) β β Render PostgreSQL DB β
ββββββββββββββββ¬βββββββββββββββββ β (users table) β
β βββββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββ
β PipelineManager Worker β
βββ¬βββββββββββββ¬ββββββββββββββ¬βββ
β β β
βΌ βΌ βΌ
ββββββββββββββββββ ββββββββββββββββ ββββββββββββββββββ
β GitHub/GitLab β β Code Chunker β β Static Regex & β
β Cloner Service β β & LLM Merger β β Groq Scanner β
ββββββββββββββββββ ββββββββββββββββ ββββββββββββββββββ
.diff patches and pre-formatted AI prompt logs (fix_prompt.json, .md, .txt) to fix codebase security flaws.http://localhost:8000/ and start scanning immediately./#signup).users table./#login)./profile)/profile or by clicking the user badge in the header.Active)/profile, a friendly notice explains guest mode and offers quick links to sign in or return to scanning.CodeShield AI integrates with Render PostgreSQL using SQLAlchemy 2.0 and psycopg2.
users table)| Column | Type | Constraints | Description |
|---|---|---|---|
id | Integer | Primary Key, Autoincrement | Unique user identifier |
full_name | String(100) | Not Null | User display name |
email | String(255) | Unique, Indexed, Not Null | Normalized login email |
password_hash | String(255) | Not Null | Argon2id cryptographic password hash |
is_active | Boolean | Default True, Not Null | Account status flag |
created_at | DateTime (UTC) | Not Null | Registration timestamp |
updated_at | DateTime (UTC) | Not Null | Last profile update timestamp |
init_db() verifies table existence and creates the users table automatically.DATABASE_URL is omitted, placeholder, or temporarily unreachable, the application logs an informational notice and continues running in guest-only mode without crashing. Existing scanner functionality is 100% independent of the database.app/core/database.py with scoped session cleanup (get_db dependency)..env)Create a local .env file in the root directory (never commit .env to Git):
# PostgreSQL β Connection string from Render
DATABASE_URL=postgresql://csai_user:[email protected]/csai
# Existing Groq configuration β retain real values locally
GROQ_API_KEY=your_groq_api_key_here
GROQ_MODEL=llama-3.3-70b-versatile
# Authentication
SESSION_SECRET=a_very_long_and_cryptographically_random_secret_string
# Application
HOST=0.0.0.0
PORT=8000
DEBUG=false
LOG_LEVEL=INFO
COOKIE_SECURE=false
| Variable | Required | Default | Description |
|---|---|---|---|
DATABASE_URL | Optional | "" | Render PostgreSQL connection URI. Automatically normalizes postgres:// to postgresql+psycopg2://. |
SESSION_SECRET | Required | Built-in fallback | Secret key used to sign HMAC session tokens. |
GROQ_API_KEY | Required | "" | Groq Cloud API key for AI security reasoning. |
GROQ_MODEL | Optional | llama-3.3-70b-versatile | Groq LLM model name. |
HOST | Optional | 0.0.0.0 | Server host binding. |
PORT | Optional | 8000 | Application HTTP port. |
COOKIE_SECURE | Optional | false | Set to true when running on HTTPS in production. |
Important
Never commit real secrets or `.env` files. Both `.env` and local database files are excluded in `.gitignore`. If an API key has ever been committed, rotate it immediately in the Groq Cloud Console.
Clone the Repository:
git clone https://github.com/mohd-musheer/CodeShield-AI.git
cd CodeShield-AI
Create and Activate a Virtual Environment:
# Windows PowerShell
python -m venv .venv
.\.venv\Scripts\Activate.ps1
# Linux / macOS
python3 -m venv .venv
source .venv/bin/activate
Install Dependencies:
pip install -r requirements.txt
Configure .env:
cp .env.example .env
# Edit .env with your Render PostgreSQL URL and Groq API Key
Start the Application:
python -m uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
Open http://localhost:8000 in your web browser.
Docker Compose automatically reads environment variables from .env and mounts persistent volumes:
docker compose up --build -d
View logs and container status:
docker compose logs -f codeshield
docker compose ps
Stop services:
docker compose down
# Build Docker image
docker build -t codeshield-ai:latest .
# Run container with environment file
docker run -d -p 8000:8000 --env-file .env codeshield-ai:latest
Deploying PostgreSQL on Render:
Deploying Web Service on Render:
DATABASE_URL: Your Render Internal Database URL.GROQ_API_KEY: Your Groq Cloud API Key.GROQ_MODEL: llama-3.3-70b-versatile.SESSION_SECRET: A long random string (e.g. openssl rand -hex 32).COOKIE_SECURE: true (Render provides automatic TLS/HTTPS).PORT: 8000.CodeShield AI exposes standard REST endpoints for integration:
| Method | Endpoint | Access | Description |
|---|---|---|---|
POST | /auth/signup | Public | Registers a new account, hashes password, sets session cookie. |
POST | /auth/login | Public | Authenticates credentials, checks rate limits, sets session cookie. |
POST | /auth/logout | Session | Clears session and CSRF cookies. |
GET | /auth/me | Authenticated | Retrieves current authenticated user profile. |
PATCH | /auth/me | Authenticated | Updates current user's profile details (full name). |
GET | /profile | Public | Serves the user profile management HTML page. |
| Method | Endpoint | Access | Description |
|---|---|---|---|
GET | / | Public | Serves the main CodeShield AI security dashboard. |
GET | /health | Public | Server status and API liveness metrics. |
GET | /scan/status/{scan_id} | Public | Retrieves active progress metrics and current scan stage. |
POST | /repository/analyze | Public | Triggers background codebase security scans. |
POST | /repository/upload | Public | Uploads a ZIP codebase archive for parsing. |
POST | /repository/cancel/{scan_id} | Public | Aborts a running scan and cleans up disk cache. |
GET | /repository/report | Public | Downloads scan report in json, html, markdown, sarif, csv, pdf, patch_diff, or fix_prompt. |
| Project Size | Total Chunks | Merged Groq Calls | Total Scan Duration |
|---|---|---|---|
| Small (1-50 Files) | 3-10 | 1 | 2-4 seconds |
| Medium (50-200 Files) | 30-80 | 3-5 | 6-9 seconds |
| Large (200+ Files) | 200+ | 12-15 | 15-20 seconds |
Distributed under the Apache 2.0 License. See LICENSEβ for details.
docker pull mohdmusheer/codeshield-ai:latest