Skip to content

Repository files navigation

SelfHeal-API

Autonomous AI agent that detects API schema drift, patches your client code, and opens a GitHub PR β€” without human intervention.

πŸ”— Live Demo: self-heal-api.vercel.app


Screenshots

Landing Page

Landing Page


Dashboard β€” Stats, Jobs Table, PR Status

Dashboard


Job Result β€” Patched Code & PR Link

Job Result


Discord Notification on PR Open

Discord Notification



The Problem

Third-party APIs (Stripe, Twilio, Shopify) release breaking changes. Your integration breaks at 2am. An engineer spends hours tracking down which field was renamed, finding the right docs, rewriting the mapper, and opening a PR.

SelfHeal-API eliminates that entire loop β€” automatically.


How It Works

User pastes error log  β†’  OR  β†’  Sentry webhook fires automatically
                ↓
Step 1 β€” Detect    β†’ LLM analyzes the log, extracts endpoint + failing field
                ↓
Step 2 β€” Search    β†’ GitHub Code Search locates the broken file and function
                ↓
Step 3 β€” Crawl     β†’ Fetches vendor OpenAPI spec, identifies what changed
                ↓
Step 4 β€” Patch     β†’ Rewrites the broken function with AST-validated code gen
                ↓
Step 5 β€” PR        β†’ Opens a GitHub PR with full explanation + Discord alert

End-to-end in under 60 seconds. Zero human input required.


Live Pipeline Proof

PR opened and merged autonomously on August 10, 2026:


Tech Stack

Layer Technology
Frontend React 18, Vite, TailwindCSS
Backend FastAPI, Python 3.12, uvicorn
Agent / LLM Groq API (Llama 3.3 70B), dual-key rotation
Database Supabase (PostgreSQL)
Job Queue Upstash Redis
Auth GitHub OAuth 2.0
Notifications Discord webhooks
Monitoring Sentry (webhook trigger)
CI/CD GitHub Actions (lint + test on every push)
Hosting Vercel (frontend), Render (backend)

100% free-tier infrastructure.


Architecture

                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   Sentry Webhook     β”‚  ← auto-trigger on error
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
Browser (Vercel)             β”‚
      ↓ HTTPS                ↓
FastAPI Backend (Render) β†β”€β”€β”€β”˜
      ↓
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚              Agent Pipeline                  β”‚
  β”‚  detect β†’ search β†’ crawl β†’ patch β†’ pr        β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
      ↓            ↓           ↓          ↓
  Groq API    GitHub API   Supabase   Discord
  (LLM)       (search +    (jobs +    (notify)
              PR create)    logs)
                  ↑
           Upstash Redis
           (job queue)

Agent Pipeline β€” Detail

Step 1 β€” Detect (detect.py)

Parses the raw error log using an LLM prompt. Returns structured JSON: endpoint, HTTP method, failing field, vendor name.

Step 2 β€” Search (search.py)

Uses GitHub Code Search API to locate the broken file and function in the repo automatically. Falls back to direct repo file listing if the search index is stale. No manual file path needed.

Step 3 β€” Crawl (crawl.py)

Fetches the vendor's public OpenAPI spec (Stripe, Twilio, Shopify). Uses jsondiff to compare old vs new schema. LLM summarizes the breaking change in plain English.

Step 4 β€” Patch (patch.py)

Fetches the broken file from the user's GitHub repo. Prompts the LLM to rewrite only the failing function. Validates output with ast.parse() before proceeding.

Step 5 β€” PR (pr.py)

Creates a new branch selfheal/fix-{timestamp}, pushes the patched file, opens a Pull Request with a structured description explaining what broke and how it was fixed. Fires a Discord notification on success.


Autonomous Trigger β€” Sentry Webhook

Configure SelfHeal-API as a Sentry webhook to trigger healing with zero human input:

URL: https://selfheal-api.onrender.com/api/v1/webhooks/sentry?repo=https://github.com/your-org/your-repo
Events: issue created

When Sentry fires, the agent runs the full 5-step pipeline and opens a PR automatically.


Key Engineering Decisions

See ARCHITECTURE-DECISIONS.md for the full ADR log. Highlights:

  • No LangChain β€” custom 5-step linear pipeline is simpler, more debuggable, and easier for reviewers to understand
  • Groq over OpenAI β€” free tier with 14,400 req/day; dual-key rotation handles rate limits automatically
  • Static analysis only β€” patched code is never executed server-side; ast.parse() validates syntax without running anything
  • GitHub Code Search + fallback β€” search index can lag on new files; direct contents API listing used as fallback
  • /api/v1/ prefix from day one β€” zero cost to add now, expensive to retrofit later
  • Sentry webhook ?repo= query param β€” simpler than maintaining a DB mapping of Sentry project β†’ repo

Security

See SECURITY.md for the full threat model. Key points:

  • GitHub tokens stored server-side only, never returned to the frontend
  • Error logs validated via Pydantic before reaching the agent
  • No arbitrary code execution β€” lint and syntax checks only
  • CORS restricted to the configured frontend origin
  • Sentry webhook signature verified via HMAC-SHA256

Local Development

Prerequisites

  • Python 3.12+
  • Node.js 18+
  • uv package manager
  • Supabase account (free)
  • Groq API keys (free at console.groq.com)
  • GitHub OAuth App
  • GitHub classic token with repo scope

Backend

cd backend
uv sync
cp ../.env.example .env
# Fill in your keys in .env
uv run uvicorn app.main:app --reload

Frontend

cd frontend
npm install
npm run dev

Environment Variables

GROQ_API_KEY_1=
GROQ_API_KEY_2=
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
GITHUB_TOKEN=
SUPABASE_URL=
SUPABASE_SERVICE_KEY=
UPSTASH_REDIS_URL=
UPSTASH_REDIS_TOKEN=
DISCORD_WEBHOOK_URL=
SENTRY_WEBHOOK_SECRET=
FRONTEND_URL=https://self-heal-api.vercel.app

Run Tests

cd backend
uv run pytest tests/ -v

Project Structure

selfheal-api/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ agent/              # detect.py, search.py, crawl.py, patch.py, pr.py
β”‚   β”‚   β”œβ”€β”€ routers/            # jobs.py, github.py, pr_sync.py, webhooks.py
β”‚   β”‚   β”œβ”€β”€ notifications/      # discord.py
β”‚   β”‚   β”œβ”€β”€ db/                 # Supabase client
β”‚   β”‚   └── queue/              # Redis worker
β”‚   └── tests/
β”œβ”€β”€ frontend/
β”‚   └── src/
β”‚       └── pages/              # Landing, Dashboard, NewJob, JobProgress, JobResult
└── screenshots/                # README screenshots

Roadmap

  • Auto file detection β€” agent searches the repo to find the broken file and function automatically
  • Sentry webhook β€” fully autonomous trigger, zero human input required
  • Discord notifications β€” alert on PR open
  • PR status sync β€” track merged/open/closed on dashboard
  • TypeScript support (currently Python only)
  • Support for more vendors (Plaid, SendGrid, Twilio)
  • Slack webhook option
  • Self-serve data deletion / GDPR controls

Built by Suraj

About

Autonomous AI agent that detects API schema drift, patches client code, and opens a GitHub PR automatically

Topics

Resources

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages