Overview
The Antigravity proxy server is built on Axum 0.7, a modern, ergonomic web framework for Rust. It handles all incoming API requests, manages authentication, routes to appropriate handlers, and communicates with upstream AI services.Server Structure
Core Components
Application State
All request handlers share immutable access to the application state:Server Startup
Location:src-tauri/src/proxy/server.rs:293
- Initialize shared state - Wrap all config in
Arc<RwLock<_>> - Create proxy pool - Initialize connection pool manager
- Build routes - Set up all API endpoints
- Apply middleware - Add CORS, auth, monitoring layers
- Bind TCP listener - Listen on
{host}:{port} - Spawn server task - Run in background Tokio task
- Return handle - Allow graceful shutdown
Listening Address
- Desktop Mode:
127.0.0.1:8045(localhost only) - Headless Mode:
0.0.0.0:8045(LAN access)
Routing Architecture
Route Structure
The server defines two main route groups:1. Proxy Routes (AI APIs)
Location:src-tauri/src/proxy/server.rs:372
Handles all AI API requests with optional authentication:
2. Admin Routes (Management API)
Location:src-tauri/src/proxy/server.rs:455
Management endpoints with forced authentication:
Full Application
Middleware Stack
Execution Order (Onion Model)
Axum middleware executes in reverse order (outside-in for requests, inside-out for responses):1. Service Status Middleware
Purpose: Check if proxy service is running2. CORS Layer
Purpose: Enable cross-origin requests for Web UI3. IP Filter Middleware
Purpose: Enforce whitelist/blacklist4. Authentication Middleware
Purpose: Validate API key based onauth_mode
5. Monitor Middleware
Purpose: Log requests and collect metricsRequest Handlers
Handlers are organized by protocol:OpenAI Protocol
Location:src-tauri/src/proxy/handlers/openai.rs
Claude Protocol
Location:src-tauri/src/proxy/handlers/claude.rs
Similar structure with Claude-specific request/response mapping.
Gemini Protocol
Location:src-tauri/src/proxy/handlers/gemini.rs
Direct passthrough with minimal transformation.
Upstream Client
Purpose: Manage HTTP requests to Google/Anthropic APIsClient Selection
- Standard Client (reqwest) - Default for most requests
- JA3 Client (rquest) - For fingerprint spoofing to bypass bot detection
Connection Pooling
Graceful Shutdown
Hot Reloading
Server supports config hot-reload without restart:Performance Characteristics
- Concurrent Connections: Thousands via Tokio async runtime
- Request Latency: Less than 10ms overhead (excluding upstream)
- Memory Usage: ~50-100MB baseline
- Throughput: Limited by upstream API, not by server
Related Documentation
- Token Manager - Account selection logic
- Model Router - Request transformation