| Crates.io | kairos-rs |
| lib.rs | kairos-rs |
| version | 0.2.17 |
| created_at | 2025-09-13 21:08:52.206716+00 |
| updated_at | 2026-01-02 20:03:25.586016+00 |
| description | A Rust library for interacting with the Kairos Api Gateway |
| homepage | |
| repository | https://github.com/DanielSarmiento04/kairos-rs |
| max_upload_size | |
| id | 1838123 |
| size | 665,833 |
A production-ready HTTP gateway and reverse proxy built with Rust, featuring a modern web-based admin interface and pioneering AI-powered routing capabilities. The future of intelligent API gateways!
Kairos-rs is a production-ready multi-protocol gateway with modern web UI that:
/users/{id} → /users/123)Current status: Production-ready multi-protocol gateway supporting HTTP, WebSocket, FTP, and DNS with comprehensive security, reliability, load balancing, request/response transformation, and web-based management interface.
sequenceDiagram
participant Client
participant Gateway as API Gateway<br/>(Actix-web)
participant Auth as Auth Service
participant Cache as Redis Cache
participant AI as AI Orchestrator
participant Provider as AI Provider<br/>(OpenAI/Claude)
participant DB as Database
Client->>Gateway: POST /api/v1/chat/completions
Gateway->>Auth: Validate API Key
Auth-->>Gateway: ✓ Authorized
Gateway->>Gateway: Rate Limit Check
Gateway->>Cache: Check cached response
alt Cache Hit
Cache-->>Gateway: Return cached result
Gateway-->>Client: 200 OK (from cache)
else Cache Miss
Cache-->>Gateway: Not found
Gateway->>AI: Process AI Request
AI->>AI: Select Provider<br/>(load balance)
AI->>Provider: HTTP Request<br/>(with retry logic)
Provider-->>AI: AI Response
AI->>Cache: Store response
AI->>DB: Log request metadata
AI->>Gateway: Return result
Gateway-->>Client: 200 OK (streamed)
end
Gateway->>DB: Log analytics (async)
Kairos-rs now supports multiple protocols beyond HTTP:
| Protocol | Status | Features |
|---|---|---|
| HTTP/HTTPS | Production Ready | Load balancing, circuit breakers, retry logic, JWT auth, rate limiting |
| WebSocket | Beta | Bidirectional messaging, connection upgrading, binary/text support |
| FTP | Beta | File operations via HTTP API (list, download, upload), authentication |
| DNS | Beta | Query forwarding, response caching, load balancing across DNS servers |
See MULTI_PROTOCOL_GUIDE.md for detailed protocol documentation and examples.
# Pull the latest multi-platform image (supports AMD64 and ARM64)
docker pull ghcr.io/danielsarmiento04/kairos-rs:latest
# Run with your config.json
docker run -d \
-p 5900:5900 \
-v $(pwd)/config.json:/app/config.json:ro \
-e RUST_LOG=info \
ghcr.io/danielsarmiento04/kairos-rs:latest
# Or use a specific version
docker pull ghcr.io/danielsarmiento04/kairos-rs:0.2.10
With Docker Compose:
services:
kairos-gateway:
image: ghcr.io/danielsarmiento04/kairos-rs:latest
container_name: kairos-gateway
restart: unless-stopped
ports:
- "5900:5900"
volumes:
- ./config.json:/app/config.json:ro
environment:
- RUST_LOG=info
- KAIROS_HOST=0.0.0.0
- KAIROS_PORT=5900
Debugging containers:
# The image uses distroless:debug with busybox shell
docker exec -it kairos-gateway sh
git clone https://github.com/DanielSarmiento04/kairos-rs.git
cd kairos-rs
cargo run --bin kairos-gateway
Gateway starts on http://localhost:5900
# Install cargo-leptos (one-time)
cargo install cargo-leptos
# Start UI in development mode
cd crates/kairos-ui
cargo leptos serve
Admin UI available at http://localhost:3000
Create a config.json file with advanced features:
{
"version": 1,
"jwt_secret": "your-secret-key-here",
"rate_limit": {
"algorithm": "token_bucket",
"requests_per_second": 100,
"burst_size": 10
},
"routers": [
{
"external_path": "/cats/{id}",
"internal_path": "/{id}",
"methods": ["GET"],
"auth_required": false,
"backends": [
{"host": "https://http.cat", "port": 443, "weight": 1}
],
"load_balancing_strategy": "round_robin"
},
{
"external_path": "/api/users/{id}",
"internal_path": "/v1/user/{id}",
"methods": ["GET", "POST"],
"auth_required": true,
"backends": [
{"host": "http://api1.example.com", "port": 8080, "weight": 3},
{"host": "http://api2.example.com", "port": 8080, "weight": 2},
{"host": "http://api3.example.com", "port": 8080, "weight": 1}
],
"load_balancing_strategy": "weighted",
"retry_config": {
"max_retries": 3,
"initial_backoff_ms": 100,
"max_backoff_ms": 5000,
"backoff_multiplier": 2.0,
"retryable_status_codes": [502, 503, 504]
}
}
]
}
# Public endpoint (no auth required)
curl http://localhost:5900/cats/200
# Secure endpoint (requires JWT)
curl -H "Authorization: Bearer YOUR_JWT_TOKEN" \
http://localhost:5900/api/secure/123
# Install wscat
npm install -g wscat
# Connect to WebSocket route
wscat -c "ws://localhost:5900/ws/chat"
Or use the Admin UI at http://localhost:3000 to:
Add to your config.json:
{
"routers": [
{
"protocol": "websocket",
"backends": [
{
"host": "ws://localhost",
"port": 3000,
"weight": 1
}
],
"external_path": "/ws/chat",
"internal_path": "/ws",
"methods": ["GET"],
"auth_required": false
}
]
}
📖 See WEBSOCKET_GUIDE.md for comprehensive WebSocket documentation.
// Example route configuration
{
"external_path": "/api/users/{user_id}/posts/{post_id}",
"internal_path": "/users/{user_id}/posts/{post_id}"
}
// Request: GET /api/users/123/posts/456
// Forwards to: GET /users/123/posts/456
The route matcher:
┌─────────────────┐
│ Web Admin UI │
│ (Leptos 0.8) │
│ Port: 3000 │
└────────┬────────┘
│ HTTP
┌─────────────┐ HTTP ┌───────▼─────────┐ HTTP ┌─────────────┐
│ Client │ ────────▶ │ Kairos Gateway │ ────────▶ │ Backend │
│ │ │ Port: 5900 │ │ Service │
└─────────────┘ └─────────┬───────┘ └─────────────┘
│
┌──────┴───────┐
│ Config.json │
│ Routes │
│ JWT │
│ Rate Limits │
└──────────────┘
Architecture Components:
kairos-rs/
├── crates/
│ ├── kairos-rs/ # Core library (models, routing logic)
│ ├── kairos-gateway/ # Gateway binary (HTTP server)
│ ├── kairos-ui/ # Web admin interface (Leptos SSR)
│ ├── kairos-cli/ # Command-line interface
│ └── kairos-client/ # Rust client library
{
"version": 1,
"jwt_secret": "your-256-bit-secret-key-here",
"rate_limit": {
"algorithm": "token_bucket",
"requests_per_second": 100,
"burst_size": 50
},
"routers": [
{
"external_path": "/api/v1/users/{id}",
"internal_path": "/users/{id}",
"methods": ["GET", "PUT", "DELETE"],
"auth_required": true,
"backends": [
{"host": "http://backend1.example.com", "port": 8080, "weight": 2, "health_check_path": "/health"},
{"host": "http://backend2.example.com", "port": 8080, "weight": 1, "health_check_path": "/health"}
],
"load_balancing_strategy": "weighted",
"retry_config": {
"max_retries": 3,
"initial_backoff_ms": 100,
"max_backoff_ms": 5000,
"backoff_multiplier": 2.0,
"retryable_status_codes": [502, 503, 504]
}
},
{
"external_path": "/public/status",
"internal_path": "/health",
"methods": ["GET"],
"auth_required": false,
"backends": [
{"host": "https://public-api.com", "port": 443}
],
"load_balancing_strategy": "round_robin"
}
]
}
Kairos-rs supports 5 load balancing strategies:
Round Robin (round_robin) - Distributes requests evenly in circular order
Least Connections (least_connections) - Routes to backend with fewest active connections
Random (random) - Randomly selects a backend
Weighted (weighted) - Distributes based on backend weights
IP Hash (ip_hash) - Routes based on client IP address
Configure exponential backoff retry logic per route:
"retry_config": {
"max_retries": 3, // Maximum retry attempts
"initial_backoff_ms": 100, // Initial delay in milliseconds
"max_backoff_ms": 5000, // Maximum backoff delay
"backoff_multiplier": 2.0, // Multiplier for exponential backoff
"retryable_status_codes": [502, 503, 504] // Which HTTP status codes to retry
}
Transform requests and responses on-the-fly with powerful transformation rules:
"request_transformation": {
"headers": [
{
"action": "add",
"name": "X-Forwarded-By",
"value": "kairos-gateway"
},
{
"action": "remove",
"name": "Cookie"
},
{
"action": "replace",
"name": "User-Agent",
"pattern": "Mozilla/(\\d+\\.\\d+)",
"replacement": "KairosGateway/$1"
}
],
"path": {
"pattern": "^/api/v1/(.+)$",
"replacement": "/v2/$1"
},
"query_params": [
{
"action": "add",
"name": "api_key",
"value": "secret123"
},
{
"action": "remove",
"name": "debug"
}
]
}
"response_transformation": {
"headers": [
{
"action": "add",
"name": "X-Powered-By",
"value": "Kairos Gateway"
},
{
"action": "remove",
"name": "Server"
}
],
"status_code_mappings": [
{
"from": 404,
"to": 200,
"condition": null
}
]
}
Transformation Actions:
Use Cases:
Kairos-rs provides REST endpoints for dynamic route management:
# List all routes
GET /api/routes
# Get specific route
GET /api/routes/{path}
# Create new route
POST /api/routes
Content-Type: application/json
{
"external_path": "/api/new",
"internal_path": "/v1/new",
"methods": ["GET"],
"backends": [{"host": "http://backend", "port": 8080}],
"load_balancing_strategy": "round_robin"
}
# Update existing route
PUT /api/routes/{path}
# Delete route
DELETE /api/routes/{path}
# Validate route configuration
POST /api/routes/validate
Trigger configuration reload without restarting:
# Reload configuration from disk
POST /api/config/reload
# Check reload status
GET /api/config/status
KAIROS_HOST=0.0.0.0 # Server bind address
KAIROS_PORT=5900 # Server port
KAIROS_CONFIG_PATH=./config.json # Config file path
RUST_LOG=info # Log level
# Run all tests in workspace (85+ tests total)
cargo test --workspace
# Run gateway tests only
cargo test --package kairos-rs
# Run UI tests only
cd crates/kairos-ui && cargo test
# Performance tests
cargo test performance_tests -- --nocapture
# Integration tests
cargo test --test integration_tests
# JWT authentication tests
cargo test --test jwt_integration_test
# Rate limiting tests
cargo test rate_limit
# Circuit breaker tests
cargo test circuit_breaker
Current test coverage: 85+ comprehensive tests covering:
This project has completed Phase 1 (Gateway Core) and Phase 2 (Load Balancing & Advanced Routing)! Here's what's planned:
Recently completed (v0.2.7):
Recently completed (v0.2.10 - October 2025):
Recently completed (v0.2.11 - November 2025):
Current focus (Phase 3 - v0.3.0):
Previously completed (Phase 1 + 2 + UI Foundation):
Future phases:
Exciting AI Vision: Kairos-rs is pioneering the integration of AI/LLM capabilities into API gateway functionality:
This makes Kairos-rs potentially the first AI-powered open source API gateway - combining traditional gateway reliability with cutting-edge AI capabilities.
See ROADMAP.md for the complete development plan.
This project needs help! Areas where contributions would be especially valuable:
Code:
Other:
# Clone and setup
git clone https://github.com/DanielSarmiento04/kairos-rs.git
cd kairos-rs
# Install dev tools
rustup component add rustfmt clippy
cargo install cargo-leptos # For UI development
# Run checks
cargo fmt --check --all
cargo clippy --all-targets --all-features
cargo test --workspace
# Start gateway
cargo run --bin kairos-gateway
# Start UI (separate terminal)
cd crates/kairos-ui
cargo leptos serve
Current code style: Uses default rustfmt with workspace configuration. The codebase follows Rust best practices.
Current benchmarks on M1 MacBook Pro:
Gateway Performance:
Resource Usage:
UI Performance:
Note: These are micro-benchmarks and controlled load tests. Real-world performance depends on backend service latency and network conditions.
Gateway:
Admin UI:
Recently fixed:
MIT License - see LICENSE file.
This project utilizes AI assistance for:
Human Oversight: All AI suggestions are reviewed, tested, and validated by human developers before implementation. The core architecture decisions and project direction remain under human control.
We believe in transparency about development tools and methods used in open source projects.
See the prompt guidance in llm.txt for more details.
Built with these excellent Rust crates:
Core Gateway:
Admin UI:
Status: Production ready with multi-protocol support (HTTP, WebSocket, FTP, DNS), comprehensive security, reliability, load balancing features, modern web admin interface with configuration management, and advanced metrics visualization
Version: 0.2.11 (November 2025)
Maintainer: @DanielSarmiento04
Community: Issues and PRs welcome!