Skip to main content

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
Startup Sequence:
  1. Initialize shared state - Wrap all config in Arc<RwLock<_>>
  2. Create proxy pool - Initialize connection pool manager
  3. Build routes - Set up all API endpoints
  4. Apply middleware - Add CORS, auth, monitoring layers
  5. Bind TCP listener - Listen on {host}:{port}
  6. Spawn server task - Run in background Tokio task
  7. Return handle - Allow graceful shutdown

Listening Address

Default Configuration:
  • 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 running

2. CORS Layer

Purpose: Enable cross-origin requests for Web UI

3. IP Filter Middleware

Purpose: Enforce whitelist/blacklist

4. Authentication Middleware

Purpose: Validate API key based on auth_mode

5. Monitor Middleware

Purpose: Log requests and collect metrics

Request 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 APIs

Client Selection

  • Standard Client (reqwest) - Default for most requests
  • JA3 Client (rquest) - For fingerprint spoofing to bypass bot detection

Connection Pooling

Graceful Shutdown

Server Loop:

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