API Dispatch & IPC Middleware
Relevant source files
The following files were used as context for generating this wiki page:
The API Dispatch and Inter-Process Communication (IPC) system serves as the communication backbone of the Infinity OS ecosystem. It facilitates seamless interaction between the frontend Shell, the Edge-native Cloudflare Workers, and the backend microservices. The architecture is designed around a "Three-Lane Mesh" that segregates traffic into AI/Nexus, User/Infinity, and Data/Hive lanes to ensure high performance and strict security boundaries.
The system utilizes a central Dispatch Worker as an OS Kernel that routes requests to specific tenant environments. Communication is further hardened by the 2060 Smart Resilience Layer, which provides standardized telemetry, circuit breaking, and adaptive rate limiting across all service interactions.
Sources: README.md, PLATFORM_ARCHITECTURE_ANALYSIS.md, todo.md:12-25
1. Dispatch Kernel & Request Routing
The Dispatch Worker acts as the entry point (L1 Dispatch Kernel) for all platform requests. It performs tenant lookups and routes incoming traffic to the appropriate User Worker or stateful TenantDO (Durable Object).
Data Flow and Lifecycle
When a request enters the platform, the Dispatch Kernel applies a series of middleware before routing.
The Dispatch Worker leverages Workers for Platforms to provide per-tenant isolation at the edge.
Sources: dashboard/index.html:70-75, todo.md:12-25
Key Components of Dispatch
| Component | Function |
|---|---|
| Auth Middleware | Validates JWT/PBKDF2 credentials via the Identity service. |
| CORS Middleware | Manages cross-origin resource sharing for multi-tenant domains. |
| TenantDO | A stateful kernel per tenant utilizing SQLite, RPC, and Alarms. |
| Ports & Adapters | Decouples logic from Cloudflare-specific bindings (D1, R2, KV). |
Sources: todo.md:1-11, PROJECT_PULSE_SESSION18.md:19-25
2. 2060 Smart Resilience Middleware
Modern services in the ecosystem (Wave 6 Studios) are "auto-wired" with a Smart Resilience Layer. This middleware ensures that IPC remains stable even during partial service failures.
Resilience Components
- Smart Circuit Breaker: Monitors failure thresholds (default: 5) and manages state (Closed → Open → Half-Open).
- Smart Telemetry: Handles request tracking and trace propagation using W3C Trace Context.
- Adaptive Rate Limiting: Adjusts limits dynamically based on IAM-level awareness (e.g., higher limits for Super Admins).
- Smart Event Bus: Facilitates asynchronous, type-safe platform events using pattern matching (e.g.,
tenant.*).
3. IPC Tokenization & The Lighthouse
Security within the IPC layer is managed by The Lighthouse, which issues Universal Entity Tokens (UET). These tokens are required for every entity communication, including AI agents and internal microservices.
Token Verification Logic
The system uses HS512 or SHA-512 for auditing and signature verification of internal IPC traffic.
function verifyIAMToken(token: string): JWTClaims | null {
try {
const parts = token.split('.');
if (parts.length !== 3) return null;
const [h, p, sig] = parts;
const header = JSON.parse(b64urlDecode(h));
const alg = header.alg === 'HS512' ? 'sha512' : 'sha256';
const expected = createHmac(alg, IAM_JWT_SECRET).update(`${h}.${p}`).digest('base64url');
return (sig === expected) ? JSON.parse(b64urlDecode(p)) : null;
} catch { return null; }
}
Sources: wave6-studios/the-digitalgrid/src/api/server.ts:20-35, README.md:100-115
4. Frontend API Integration (BackendProvider)
The Shell application interacts with the API through the BackendProvider, which centralizes authentication, token refreshing, and distributed tracing.
Unified API Calling
The apiCall wrapper handles the inclusion of Bearer tokens and implements an automatic 401-unauthorized retry logic using a refresh token stored in localStorage.
| Feature | Implementation |
|---|---|
| Auth Injection | Automatically adds Authorization: Bearer <token> to headers. |
| Trace Propagation | Generates or forwards x-trace-id for observability. |
| Automatic Retry | Attempts a /api/v1/auth/refresh before failing a request. |
Sources: apps/shell/src/providers/BackendProvider.tsx:44-75
5. Deployment & Validation
Production deployments are validated using a suite that checks the reachability of all 22+ core API routers and validates security headers.
# Example router validation list
ROUTERS=(
"ai" "appstore" "artifacts" "assets" "billing" "build"
"codegen" "compliance" "documents" "files" "integrations"
"itsm" "kanban" "kb" "notifications" "observability"
"organisations" "repositories" "security" "users"
"workflows" "vulnerability"
)
Sources: scripts/validate-production.sh:110-120
Conclusion
The API Dispatch & IPC Middleware provides a high-resilience, multi-tenant communication layer. By combining Cloudflare Edge Workers for dispatching with standardized resilience middleware for microservices, the system achieves sub-10ms response times while maintaining a zero-trust, quantum-safe security posture.
Sources: infinity-os/architecture.html, PLATFORM_ARCHITECTURE_ANALYSIS.md