Skip to content

zaidkhan-sudo/protocol_zero

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

54 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Protocol Zero Logo

Protocol Zero

AI-Powered Code Police β€” Automated Code Review, Self-Healing Bugs & Blockchain Attestation

Live Demo Β· Features Β· Tech Stack Β· Getting Started Β· Architecture

Next.js React TypeScript Gemini AI Solidity Firebase


Table of Contents


Introduction

Protocol Zero is a full-stack AI-powered DevOps platform that acts as an autonomous code quality guardian for your GitHub repositories. It combines real-time AI code review, autonomous bug detection & fixing, and immutable blockchain audit trails β€” all in a single, unified dashboard.

Connect any GitHub repository, and Protocol Zero will:

  1. Review every push & pull request with multi-dimensional AI analysis (security, performance, bugs, readability, test coverage).
  2. Autonomously heal broken code β€” clone, scan, fix, test, and submit Pull Requests, all without human intervention.
  3. Record every AI fix on-chain via a Solidity smart contract on Ethereum Sepolia, creating a tamper-proof compliance log.

"Enough Building, time for redemption."


Features

πŸš” Code Police

Webhook-driven AI code review that watches every commit in real-time.

  • Automated Analysis β€” Triggered on every push and pull_request event via GitHub webhooks
  • Multi-Dimensional Review β€” Each file is analyzed for security vulnerabilities, performance issues, bugs, readability, and test coverage
  • Auto-Fix Pull Requests β€” Critical and high-severity issues trigger automatic fix PRs with AI-generated patches
  • Email Reports β€” Rich HTML email digests summarizing findings and linking directly to auto-fix PRs
  • Custom Rules β€” Define your own rules (e.g., "No console.log in production", "Enforce async/await over .then()")
  • Full Repository Scan β€” On-demand full-repo analysis with parallel processing (5 files concurrently) and multi-layer caching (in-memory + Redis)
  • Repository Health Analytics β€” Health scores, language breakdown, commit activity, contributor stats, PR metrics, documentation presence, and AI-powered executive summaries

🩺 Self-Healing Code

A multi-agent autonomous pipeline that clones your repo, finds bugs, writes fixes, runs tests, and opens a PR.

  • Multi-Agent Architecture β€” 5 specialized agents working in concert:

    Agent Role
    Orchestrator Coordinates the entire healing loop with up to 3 retry attempts
    Bug Scanner (The Scout) AI-powered scanning for SYNTAX, LINTING, RUNTIME, LOGIC, IMPORT, TYPE, and DEPENDENCY bugs
    Fix Engineer Generates complete fixed file contents using Gemini AI
    Test Runner Auto-detects framework (Jest, Vitest, Mocha, pytest, Go, Cargo, etc.) and runs tests
    Repo Manager Git operations β€” fork, clone, branch, commit, push, create PR
  • Live Streaming via SSE β€” Watch the healing process in real-time with a live timeline, bug table, file tree, and score breakdown

  • Automatic PR Creation β€” Creates a PR with branch name TEAM_LEADER_AI_Fix and [AI-AGENT] commit prefix

  • Score Breakdown β€” Weighted 0–100 score with per-category analytics and animated visualizations

  • 5-Minute Timeout β€” Safety guard to prevent runaway sessions

⛓️ Blockchain Notary

Immutable, tamper-evident audit trail for every AI code fix.

  • On-Chain Attestations β€” Every fix is recorded as a Solidity Attestation struct containing: session ID, bug category, file path, line number, error message, fix description, test results (before & after), commit SHA, and timestamp
  • ComplianceLog Smart Contract β€” Deployed on Ethereum Sepolia testnet (Solidity 0.8.24)
  • Etherscan Verification β€” Every attestation links directly to its transaction on Etherscan for independent verification
  • Read-Only Public Auditing β€” Anyone can query the contract to audit the AI agent's fix history
  • Graceful Degradation β€” Blockchain features are optional; the platform works fully without blockchain configuration

πŸ“Š Dashboard & Admin

A comprehensive, feature-rich dashboard with a premium dark UI.

  • Home Dashboard β€” Greeting, stats cards, code review counts, recent activity feed
  • Code Police Panel β€” Connect repos, view analysis results, manage project settings, explore issues, trigger full scans
  • Self-Healing Panel β€” Submit healing requests, view session history, live session streaming with timeline & attestation log
  • Notifications Center β€” In-app notifications for code analysis completions, critical issues, auto-fix PRs, and repo connections
  • Settings β€” Analytics overview, project management, activity history, integrated Clerk profile
  • Admin Panel β€” Email-gated admin dashboard with total user/project/analysis stats, user management, and activity logs
  • SaaS Usage Tracking β€” Free and Pro tier limits with monthly resets

Tech Stack

Layer Technology
Framework Next.js 16 (App Router) Β· React 19 Β· TypeScript 5.9
AI Google Gemini (2.5 Flash Lite, 2.0 Flash) via LangChain
Authentication Clerk (OAuth Β· GitHub Social Connection)
Database Firebase / Firestore (primary) Β· Redis (L2 cache)
Blockchain Solidity 0.8.24 Β· Hardhat Β· ethers.js v6 Β· Sepolia Testnet
GitHub Integration Octokit Β· Webhooks Β· Bot Token (PAT)
Email Nodemailer (SMTP) Β· Resend
UI Components Radix UI Β· Framer Motion Β· Tailwind CSS v4 Β· Recharts
3D / Animations Spline 3D Β· cobe (globe) Β· tsparticles Β· canvas-confetti
Forms & Validation React Hook Form Β· Zod v4
State Management Zustand Β· TanStack React Query Β· SWR
Deployment Vercel Β· Netlify Β· Render

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        PROTOCOL ZERO                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   Landing    β”‚  Dashboard   β”‚  Admin       β”‚  API Layer         β”‚
β”‚   Page       β”‚  (Protected) β”‚  (Gated)     β”‚  31 Endpoints      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                         MIDDLEWARE                               β”‚
β”‚              Clerk Auth Β· Route Protection                       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                       AI AGENTS                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚    CODE POLICE       β”‚   β”‚     SELF-HEALING ENGINE      β”‚    β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚   β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚    β”‚
β”‚  β”‚  β”‚ Analyzer      β”‚  β”‚   β”‚  β”‚ Orchestrator           β”‚  β”‚    β”‚
β”‚  β”‚  β”‚ Fix Generator β”‚  β”‚   β”‚  β”‚ Bug Scanner (Scout)    β”‚  β”‚    β”‚
β”‚  β”‚  β”‚ PR Creator    β”‚  β”‚   β”‚  β”‚ Fix Engineer           β”‚  β”‚    β”‚
β”‚  β”‚  β”‚ Email Service β”‚  β”‚   β”‚  β”‚ Test Runner            β”‚  β”‚    β”‚
β”‚  β”‚  β”‚ Analytics     β”‚  β”‚   β”‚  β”‚ Repo Manager           β”‚  β”‚    β”‚
β”‚  β”‚  β”‚ Cache Layer   β”‚  β”‚   β”‚  β”‚ Progress Emitter (SSE) β”‚  β”‚    β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚   β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                     DATA & SERVICES                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚ Firestore  β”‚ β”‚ Redis  β”‚ β”‚ GitHub API β”‚ β”‚ Sepolia (EVM)   β”‚  β”‚
β”‚  β”‚ (Primary)  β”‚ β”‚ (Cache)β”‚ β”‚ (Webhooks) β”‚ β”‚ ComplianceLog   β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Getting Started

Prerequisites

  • Node.js β‰₯ 18.x
  • npm or yarn or pnpm
  • Git
  • A Google Cloud account with Gemini API access
  • A Clerk account (clerk.com)
  • A Firebase project with Firestore enabled
  • (Optional) A GitHub Personal Access Token with repo scope for the self-healing bot
  • (Optional) An Alchemy or Infura account for Sepolia RPC access

Installation

# Clone the repository
git clone https://github.com/zaidkhan-sudo/protocol_zero.git
cd protocol_zero

# Install dependencies
npm install

Environment Variables

Create a .env.local file in the root directory:

# ═══════════════════════════════════════════════════
# REQUIRED
# ═══════════════════════════════════════════════════

# Google Gemini AI
GEMINI_API_KEY=your_gemini_api_key

# Clerk Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...
CLERK_SECRET_KEY=sk_test_...

# ═══════════════════════════════════════════════════
# FIREBASE (Required for full functionality)
# ═══════════════════════════════════════════════════

# Server-side (Firebase Admin) β€” choose ONE method:
# Method 1: Individual keys
FIREBASE_PROJECT_ID=your-project-id
FIREBASE_CLIENT_EMAIL=your-service-account@your-project.iam.gserviceaccount.com
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"

# Method 2: Service account JSON file path
# FIREBASE_SERVICE_ACCOUNT_PATH=./path/to/service-account.json

# Method 3: Base64-encoded service account JSON
# FIREBASE_ADMIN_SERVICE_ACCOUNT=base64_encoded_json

# Client-side (Firebase SDK)
NEXT_PUBLIC_FIREBASE_API_KEY=your_api_key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your-project-id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your-project.firebasestorage.app
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=123456789
NEXT_PUBLIC_FIREBASE_APP_ID=1:123456789:web:abc123

# ═══════════════════════════════════════════════════
# GITHUB
# ═══════════════════════════════════════════════════

GITHUB_BOT_TOKEN=ghp_...              # PAT with repo scope (self-healing bot)
GITHUB_CLIENT_ID=your_github_oauth_id  # GitHub OAuth app

# ═══════════════════════════════════════════════════
# BLOCKCHAIN (Optional β€” Sepolia Testnet)
# ═══════════════════════════════════════════════════

SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/...
DEPLOYER_PRIVATE_KEY=0x...
COMPLIANCE_CONTRACT_ADDRESS=0x...
NEXT_PUBLIC_SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/...

# ═══════════════════════════════════════════════════
# EMAIL (Optional β€” SMTP via Nodemailer)
# ═══════════════════════════════════════════════════

EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USER=your_email@gmail.com
EMAIL_PASS=your_app_password

# ═══════════════════════════════════════════════════
# OTHER
# ═══════════════════════════════════════════════════

CLERK_WEBHOOK_SECRET=whsec_...        # Svix webhook verification
NEXT_PUBLIC_APP_URL=http://localhost:3000
ADMIN_EMAILS=admin@example.com        # Comma-separated admin emails
REDIS_URL=redis://localhost:6379      # Optional L2 cache

Running Locally

# Start the development server
npm run dev

Open http://localhost:3000 to see the app.

Other scripts:

npm run build          # Production build (with env validation)
npm run start          # Start production server
npm run lint           # Run ESLint
npm run lint:fix       # Auto-fix lint errors
npm run type-check     # TypeScript type checking

Smart Contract Deployment

To deploy the ComplianceLog contract to Sepolia:

# Ensure SEPOLIA_RPC_URL and DEPLOYER_PRIVATE_KEY are set in .env
npx hardhat compile
npx hardhat run scripts/deploy.ts --network sepolia

After deployment, update COMPLIANCE_CONTRACT_ADDRESS in your environment with the deployed contract address.


Project Structure

protocol_zero/
β”œβ”€β”€ contracts/                  # Solidity smart contracts
β”‚   └── ComplianceLog.sol       # On-chain audit trail contract
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ deploy.ts               # Hardhat deployment script
β”‚   └── validate-env.js         # Pre-build env validation
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ page.tsx            # Landing page
β”‚   β”‚   β”œβ”€β”€ layout.tsx          # Root layout (Clerk + fonts)
β”‚   β”‚   β”œβ”€β”€ providers.tsx       # Client providers (React Query)
β”‚   β”‚   β”œβ”€β”€ api/                # 31 API route handlers
β”‚   β”‚   β”‚   β”œβ”€β”€ auth/           # GitHub OAuth status
β”‚   β”‚   β”‚   β”œβ”€β”€ code-police/    # Analysis, issues, analytics, auto-fix
β”‚   β”‚   β”‚   β”œβ”€β”€ self-healing/   # Start session, SSE stream, attestations
β”‚   β”‚   β”‚   β”œβ”€β”€ webhooks/       # GitHub & Clerk webhooks
β”‚   β”‚   β”‚   β”œβ”€β”€ dashboard/      # Dashboard stats
β”‚   β”‚   β”‚   β”œβ”€β”€ admin/          # Admin endpoints (gated)
β”‚   β”‚   β”‚   β”œβ”€β”€ github/         # Repo listing & connection
β”‚   β”‚   β”‚   β”œβ”€β”€ notifications/  # Mark read, delete
β”‚   β”‚   β”‚   β”œβ”€β”€ projects/       # Unified CRUD
β”‚   β”‚   β”‚   β”œβ”€β”€ user/           # Init & usage tracking
β”‚   β”‚   β”‚   └── health/         # Health check
β”‚   β”‚   β”œβ”€β”€ dashboard/          # Protected dashboard pages
β”‚   β”‚   β”‚   β”œβ”€β”€ code-police/    # Code Police UI
β”‚   β”‚   β”‚   β”œβ”€β”€ self-healing/   # Self-Healing UI
β”‚   β”‚   β”‚   β”œβ”€β”€ notifications/  # Notification center
β”‚   β”‚   β”‚   β”œβ”€β”€ settings/       # User settings
β”‚   β”‚   β”‚   └── admin/          # Admin panel
β”‚   β”‚   β”œβ”€β”€ sign-in/            # Clerk sign-in
β”‚   β”‚   └── sign-up/            # Clerk sign-up
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ code-police/        # Code Police components
β”‚   β”‚   β”œβ”€β”€ self-healing/       # Self-Healing components (7)
β”‚   β”‚   β”œβ”€β”€ dashboard/          # Dashboard shell
β”‚   β”‚   β”œβ”€β”€ layout/             # Header, Footer, Hero sections
β”‚   β”‚   └── ui/                 # 44 reusable UI components
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ agents/
β”‚   β”‚   β”‚   β”œβ”€β”€ code-police/    # Analyzer, Fix Generator, PR Creator, etc.
β”‚   β”‚   β”‚   └── self-healing/   # Orchestrator, Bug Scanner, Fix Engineer, etc.
β”‚   β”‚   β”œβ”€β”€ blockchain/         # Ethers.js attestation service
β”‚   β”‚   β”œβ”€β”€ firebase/           # Admin SDK + Client SDK init
β”‚   β”‚   └── utils/              # Shared utilities
β”‚   └── types/                  # TypeScript type definitions
β”œβ”€β”€ artifacts/                  # Compiled contract ABIs
β”œβ”€β”€ typechain-types/            # Auto-generated contract typings
β”œβ”€β”€ hardhat.config.ts           # Hardhat / Sepolia config
β”œβ”€β”€ middleware.ts               # Clerk route protection
β”œβ”€β”€ firebase.json               # Firebase project config
└── package.json

API Reference

Endpoint Method Description
/api/health GET Health check β€” reports service status
Auth & User
/api/auth/github/status GET DELETE Check/disconnect GitHub OAuth
/api/user/init POST Initialize user document in Firestore
/api/user/usage GET POST Usage stats & plan management
Code Police
/api/code-police/projects GET POST List/create projects
/api/code-police/projects/[id] GET PATCH DELETE Manage individual project
/api/code-police/analyze POST Trigger commit analysis
/api/code-police/analyze-repo POST Full repository analysis
/api/code-police/issues GET POST Fetch issues / generate auto-fix PR
/api/code-police/analytics GET Repository health analytics
/api/code-police/disconnect POST Disconnect repository
Self-Healing
/api/self-healing/start POST Start autonomous healing session
/api/self-healing/stream/[sessionId] GET SSE live progress stream
/api/self-healing/sessions GET List all sessions
/api/self-healing/sessions/[id] GET Session details
/api/self-healing/sessions/[id]/fail POST Mark session as failed
/api/self-healing/attestations/[sessionId] GET On-chain attestation records
Webhooks
/api/webhooks/github POST GitHub push/PR webhook handler
/api/webhooks/clerk POST Clerk user lifecycle sync
GitHub
/api/github/repos GET List user's GitHub repos
/api/github/connect POST Connect repo + create webhook
Dashboard & Admin
/api/dashboard/stats GET Aggregated dashboard statistics
/api/admin/stats GET Admin-only platform stats
/api/admin/users GET Admin-only user list
/api/admin/users/[userId] GET PATCH Admin user management
/api/admin/projects GET Admin project list
/api/admin/activities GET Admin activity log
/api/notifications PATCH DELETE Manage notifications
/api/projects GET POST PATCH DELETE Unified project CRUD

Deployment

Vercel

# Install Vercel CLI
npm i -g vercel

# Deploy
vercel --prod

Set all environment variables in the Vercel dashboard under Settings β†’ Environment Variables.

Netlify

The project includes a netlify.toml with pre-configured build settings and the @netlify/plugin-nextjs plugin.

# Install Netlify CLI
npm i -g netlify-cli

# Deploy
netlify deploy --prod

Render

The live instance runs on Render. Configure a new Web Service pointing to the repository with:

  • Build Command: npm install && npm run build
  • Start Command: npm start

Contributors

Zaid Khan
Zaid Khan
Mohnish Pamnani
Mohnish Pamnani
Anurag Mishra
Anurag Mishra
Shivang Jaiswal
Shivang Jaiswal

LinkedIn Β· Live Demo Β· GitHub

Built with πŸ›‘οΈ by the Protocol Zero Team

Releases

Packages

Contributors

Languages