feagi-api
REST API layer for FEAGI with HTTP and ZMQ transport adapters.
Architecture Overview
feagi-api is responsible for business logic of API endpoints, while feagi-io handles transport infrastructure.
┌─────────────────────────────────────────────┐
│ feagi-api (Business Logic Layer) │
│ │
│ ┌────────────────────────────────────────┐ │
│ │ endpoints/ (Transport-agnostic) │ │
│ │ • health.rs │ │
│ │ • cortical_areas.rs │ │
│ │ • genome.rs │ │
│ └────────────────────────────────────────┘ │
│ ↓ Called by ↓ │
│ ┌──────────────────┬──────────────────────┐│
│ │ HTTP (Axum) │ ZMQ (feagi-io) ││
│ │ transports/http/ │ transports/zmq/ ││
│ └──────────────────┴──────────────────────┘│
└─────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────┐
│ feagi-io (Transport Infrastructure) │
│ • api_control.rs (ZMQ ROUTER/DEALER) │
│ • sensory.rs (PUSH/PULL) │
│ • motor.rs (PUB/SUB) │
│ • visualization.rs (PUB/SUB) │
└─────────────────────────────────────────────┘
Design Principles
Clear Separation of Concerns
feagi-api:
- ✅ Defines API endpoints (what operations are available)
- ✅ Implements business logic (transport-agnostic)
- ✅ Provides thin transport adapters (HTTP + ZMQ)
- ❌ Does NOT implement ZMQ infrastructure
feagi-io:
- ✅ Owns ALL ZMQ code (data + control plane)
- ✅ Provides
api_controlfor REST-over-ZMQ - ✅ Handles real-time streaming (sensory, motor, viz)
- ❌ Does NOT implement business logic
Unified Endpoint Layer
All endpoints are transport-agnostic:
// src/endpoints/health.rs
pub async
This endpoint is called by both HTTP and ZMQ adapters:
// HTTP adapter (Axum)
async .>>
// ZMQ adapter (feagi-io integration)
async
Integration with feagi-io
The ZMQ transport adapter in feagi-api uses feagi-io infrastructure:
// feagi-io provides the ZMQ transport
use ApiControlStream;
// feagi-api provides the business logic
use handle_api_control_request;
// In feagi-io::api_control, when a REST request arrives:
let response = handle_api_control_request.await;
Why Keep Them Separate?
| Concern | feagi-io | feagi-api |
|---|---|---|
| Responsibility | How to move data | What operations are available |
| Deployment | Main FEAGI process (hot path) | Could be separate process |
| Evolution | Add transports (WebSocket, QUIC) | Add endpoints (features, versioning) |
| Consumers | Agents, BV, connectors | Web UI, CLI, mgmt scripts |
| Compilation | Must compile for all I/O | Can compile with only API deps |
API Versioning
Supports multiple API versions:
/api/v1/health → Version 1 (stable)
/api/v2/health → Version 2 (future)
/health → Version-agnostic (always available)
Transport Support
HTTP (Axum)
GET /api/v1/health → Health check
GET /api/v1/cortical-areas → List cortical areas
POST /api/v1/cortical-areas → Create cortical area
Features:
- OpenAPI 3.0 documentation (utoipa)
- Custom Swagger UI styling
- CORS support
- Request/response logging
ZMQ (via feagi-io)
Same endpoints available over ZMQ ROUTER/DEALER:
Response:
Contract Testing
All endpoints tested for 100% compatibility with Python FastAPI:
Security (Stub Architecture)
Security stubs are in place for future implementation:
// Authentication (stub - always anonymous for now)
let auth_ctx = anonymous;
// Authorization (stub - always allowed for now)
authorize?;
Status
Current (Phase 1 - Infrastructure):
- ✅ Crate structure
- ✅ Common types (ApiRequest, ApiResponse, ApiError)
- ✅ Security stubs (AuthContext, Permission)
- ✅ HTTP server (Axum) with basic routing
- ✅ ZMQ server (feagi-io integration)
- ✅ Middleware (CORS, logging)
- ✅ Health endpoint (working for HTTP + ZMQ)
Next (Phase 2 - Endpoints):
- 🔄 OpenAPI/Swagger UI integration
- 🔄 Cortical area endpoints (CRUD)
- 🔄 Brain region endpoints
- 🔄 Genome endpoints
- 🔄 Analytics endpoints
Future (Phase 3 - Testing):
- ⏳ Contract tests (Python compatibility)
- ⏳ Integration tests
- ⏳ Performance benchmarks
Dependencies
= { = "../feagi-services" } # Service layer
= { = "../feagi-types" } # Core types
= { = "../feagi-io" } # ZMQ infrastructure
= "0.7" # HTTP server
= "4.0" # OpenAPI generation
= "0.5" # Middleware (CORS, logging)
Example Usage
Starting the HTTP API
use http;
let state = ApiState ;
let app = create_app;
bind
.serve
.await
.unwrap;
Integrating with feagi-io (ZMQ)
// In feagi-io::api_control when REST request arrives
use zmq;
let api_state = ZmqApiState ;
let response = handle_api_control_request.await;
// Send response back over ZMQ
License
Apache-2.0