- Add SQLCipher encryption for ait-mainnet database with configurable flag - Add db_encryption_enabled and db_encryption_key_path config settings - Implement encryption key loading and PRAGMA key setup via connection events - Add shutdown_db function for proper database cleanup - Export middleware classes in aitbc/__init__.py - Fix import path in sync.py for settings - Remove duplicate agent documentation from docs
3.4 KiB
API Gateway
Level: Intermediate
Prerequisites: Familiarity with AITBC microservices architecture
Estimated Time: 10 minutes
Last Updated: 2026-05-03
Version: 1.0
🧭 Navigation Path:
🏠 Documentation Home → 📦 Apps → 🏗️ Infrastructure → You are here
breadcrumb: Home → Apps → Infrastructure → API Gateway
🎯 See Also:
- 📖 About Documentation - Template standard and audit checklist
- 🧭 Master Index - Full documentation catalog
- 📁 Infrastructure Overview - Infrastructure services overview
Overview
The AITBC API Gateway is a central routing service that directs requests to appropriate microservices. It provides a unified entry point for all AITBC services, simplifying client integration and enabling service discovery.
Service Registry
The gateway routes requests to the following services:
| Service | Port | Routes | Description |
|---|---|---|---|
| GPU Service | 8101 | /gpu/* |
GPU resource management |
| Marketplace Service | 8102 | /marketplace/* |
GPU marketplace |
| Agent Service | 8103 | /agent/* |
Agent operations |
| Trading Service | 8104 | /trading/* |
Trading operations |
| Governance Service | 8105 | /governance/* |
Governance operations |
| Coordinator API | 8000 | /coordinator/* |
Coordinator API (default) |
Installation
cd /opt/aitbc
poetry install --with api-gateway
Running
Development
python -m api_gateway.main
Production (systemd)
sudo systemctl start api-gateway
sudo systemctl enable api-gateway
Endpoints
GET /health- Health checkGET /services- List registered services/*- Proxy all other requests to appropriate microservice
Configuration
Service URLs are configured in main.py under the SERVICES dictionary.
Testing
Health Check
curl http://localhost:8080/health
Expected response:
{"status": "healthy", "service": "api-gateway"}
Service Registry
curl http://localhost:8080/services
Test Routing
# Route to GPU service
curl http://localhost:8080/gpu/health
# Route to Marketplace service
curl http://localhost:8080/marketplace/health
# Route to Trading service
curl http://localhost:8080/trading/health
# Route to Governance service
curl http://localhost:8080/governance/health
Architecture
The API Gateway implements:
- Request Routing: Directs requests to appropriate microservices based on URL patterns
- Service Discovery: Maintains a registry of available services
- Health Monitoring: Checks service health before routing
- Load Balancing: Distributes requests across service instances (future enhancement)
Security
- TLS termination at gateway (future)
- Rate limiting (future)
- Authentication/Authorization (future)
Troubleshooting
Service Not Responding
- Check if target microservice is running
- Verify service URL configuration
- Check gateway logs for routing errors
Health Check Failing
- Verify gateway is running on port 8080
- Check systemd service status:
systemctl status api-gateway - Review logs:
journalctl -u api-gateway -f
Last updated: 2026-05-03
Version: 1.0
Status: Active service
Tags: api-gateway, infrastructure, routing, microservices