How badrisnarayanan/antigravity-claude-proxy works
Project Type and Purpose
• This is a full-stack, monolithic Node.js application that acts as an Anthropic-compatible proxy server. It exposes an Anthropic-style API (used by Claude Code CLI, OpenClaw, ClawdBot) and translates requests/responses to/from Google Generative AI via Antigravity Cloud Code. It also provides a browser-based Web UI and a CLI for account management.
Key Architectural Layers & Components
a. Clients
• Web UI (public/…): Static HTML/CSS/JS single-page app serving the dashboard, account manager, logs viewer, settings, etc.
• CLI (bin/cli.js + src/cli/…): Command-line interface for headless account linking and status queries.
b. Backend Server (src/server.js + src/index.js)
• HTTP/API Layer: Express (or similar) routes under /api/* that handle incoming Anthropic-format requests, account management endpoints, health checks, quota queries.
• Authentication (src/auth/…): OAuth token management, token extraction, optional manual‐paste flow.
• Account Manager (src/account-manager/…):
• Storage of linked Google accounts (local DB via storage.js).
• Strategy pattern implementations (round-robin, sticky, hybrid) with health/quota trackers for load balancing across multiple accounts.
• Cloud Code Bridge (src/cloudcode/…):
• Wraps Google Generative AI requests inside Antigravity Cloud Code API calls.
• Handles SSE streaming parsing and re-emits streaming Anthropic-style events.
• Formatter (src/format/…): Converts message payloads between Anthropic API schema and Google Generative AI schema; signature caching, schema sanitization, thinking utilities.
• Modules (src/modules/usage-stats.js, etc.): Stats collection, preset loading, helper utilities.
• Configuration & Constants (src/config.js, src/constants.js, fallback-config.js): Merges config.json, environment variables, default fallbacks.
• Logging & Error Handling (src/utils/logger.js, error-handler utils).
External Dependencies / Services
• Antigravity Cloud Code API (daily-cloudcode-pa.sandbox.googleapis.com) – endpoint for actual Generative AI calls.
• Google OAuth Servers – for user account authorization.
• Local Storage – file-based or in-memory store for account credentials.
Data Flows & Interactions
1. Client Request:
• Web UI or CLI → HTTP POST /api/v1/chat/completions (Anthropic format).
2. Server Processing:
• Authentication middleware extracts or refreshes OAuth tokens.
• Account Manager selects a Google account based on strategy.
• Formatter converts Anthropic messages → Google Gen AI payload.
• Cloud Code Bridge wraps payload and issues HTTPS call to Antigravity Cloud Code API.
• SSE parser de-chunks streaming responses.
• Formatter converts Google responses → Anthropic message stream.
3. Server Response:
• Streams back to client in real time.
Architectural Patterns & Principles
• Layered Architecture: Clear separation between API layer, business logic (account-manager, format, cloudcode), and utility modules.
• Strategy Pattern: Pluggable load-balancing strategies for multi-account rotation.
• Adapter/Facade: format and cloudcode modules adapt between two incompatible APIs (Anthropic ↔ Google Gen AI).
• Single Responsibility: Each folder under src/ has a distinct concern (auth, cli, cloudcode, format, account-manager, webui).