Architecture Overview
Antigravity Manager is a desktop application that transforms web-based AI sessions (Google/Anthropic) into standardized API endpoints. Built with modern technologies, it provides a robust, high-performance AI request proxy system.Technology Stack
Frontend
- React - Modern UI framework
- Tauri v2 - Cross-platform desktop framework
- TypeScript - Type-safe application logic
Backend
- Rust - High-performance, memory-safe system programming
- Tokio - Asynchronous runtime for concurrent request handling
- Axum - Fast, ergonomic web framework for proxy server
Key Dependencies
System Architecture Diagram
Core Components
1. Tauri Application (src-tauri/src/lib.rs)
The main application entry point that:
- Initializes the Tauri runtime
- Manages application lifecycle
- Coordinates between frontend and backend
- Handles headless mode for Docker/server deployments
- Logger initialization
- Database setup (token stats, security, user tokens)
- Tray icon management
- Auto-start configuration
- Background task scheduling
2. Axum Proxy Server (src-tauri/src/proxy/server.rs)
A high-performance HTTP server that:
- Listens on configurable port (default: 8045)
- Handles multiple protocol formats (OpenAI, Anthropic, Gemini)
- Manages authentication and rate limiting
- Provides admin API for management
3. Token Manager (src-tauri/src/proxy/token_manager.rs)
Central account and token management system:
- Loads accounts from disk (
~/.antigravity_tools/accounts/) - Manages access/refresh token lifecycle
- Implements intelligent account selection algorithms
- Handles quota protection and rate limiting
- Capability Filtering - Only accounts with the target model
- Tier Priority - Ultra > Pro > Free
- Quota Sorting - Higher remaining quota first
- Health Score - Account reliability tracking
- P2C Algorithm - Power of 2 Choices for load balancing
4. Model Router
Maps incoming model requests to appropriate upstream models:- Custom model ID mapping
- Protocol-specific transformations
- Dynamic model forwarding rules
- Fallback handling for deprecated models
Request Flow
- Client Request → Client sends OpenAI/Anthropic/Gemini API request
- Authentication → API key validation (middleware)
- IP Filtering → Whitelist/blacklist check (middleware)
- Model Mapping → Transform model ID to target model
- Account Selection → TokenManager chooses best account
- Protocol Conversion → Transform request to upstream format
- Upstream Request → Send to Google/Anthropic API
- Response Mapping → Convert response to client format
- Monitoring → Log request metrics and statistics
Deployment Modes
Desktop Mode (GUI)
- Full Tauri application with React frontend
- Tray icon integration
- Auto-start on system boot
- Local management interface
Headless Mode (Docker/Server)
- CLI-only operation with
--headlessflag - Web UI served from
/distdirectory - Environment variable configuration
- Systemd/Docker container support
Data Storage
File System Structure
Databases
- token_stats.db - Request metrics, token usage, model trends
- security.db - IP access logs, blacklist/whitelist
- user_tokens.db - Multi-user token management
Security Features
-
Authentication Modes
Off- No authenticationAuto- Auth for non-health endpointsAllExceptHealth- Auth required except/healthStrict- Auth required for all endpoints
-
IP Filtering
- Whitelist/blacklist support
- Per-request logging
- Geographic access control
-
Rate Limiting
- Per-account rate limits
- Automatic cooldown handling
- 429 error auto-retry with account rotation
-
Token Isolation
- Separate admin and API keys
- Multi-user token system
- Session-based account binding
Performance Optimizations
Concurrency
- Tokio async runtime - Handle thousands of concurrent requests
- DashMap - Lock-free concurrent hashmap for token pool
- Parking Lot - Fast RwLock for shared state
Caching
- In-memory quota cache - Avoid disk reads during selection
- Model limits cache - Pre-load max_output_tokens
- Project ID caching - Reduce upstream API calls
Request Optimization
- HTTP/2 connection pooling - Reuse connections
- JA3 fingerprint spoofing - Bypass bot detection (rquest)
- Streaming responses - Low-latency SSE forwarding
Monitoring & Observability
- Structured logging - Tracing with log levels
- Request metrics - Token usage, latency, error rates
- Health checks -
/healthand/healthzendpoints - Admin dashboard - Real-time stats and logs
Next Steps
- Proxy Server Architecture - Deep dive into Axum server
- Token Manager - Account management system
- Model Router - Request routing logic