High-Level Architecture
Manifest is a single-service monorepo that deploys as one unified application. The architecture consists of four main components:Plugin Layer
Package: manifest (npm)
The OpenClaw plugin integrates with AI gateway platforms to capture telemetry and enable routing.
Location: packages/openclaw-plugin/
Architecture
Telemetry Flow
Hook Registration
Plugin registers lifecycle hooks with the gateway (
agent_start, agent_end, agent_error).Session Tracking
The plugin maintains session momentum in-memory:Routing Integration
The plugin registers Manifest as a provider:model: "auto", it routes to Manifest’s proxy endpoint.
Backend Layer
Package: manifest-backend (private)
NestJS 11 API server handling ingestion, routing, and analytics.
Location: packages/backend/
Module Structure
Guard Chain
Three global guards run on every request:- SessionGuard / LocalAuthGuard (mode-dependent)
- Cloud: Validates Better Auth cookie session
- Local: Checks loopback IP (127.0.0.1/::1)
- ApiKeyGuard
- Falls through if session exists
- Validates
X-API-Keyheader (timing-safe compare)
- ThrottlerGuard
- Rate limiting (default: 100 req/min)
Authentication Architecture
Cloud Mode (Better Auth)
main.ts before express.json() (Better Auth needs raw body control):
Local Mode (Loopback Auth)
OTLP Ingestion Deep Dive
OtlpAuthGuard
Validates Bearer tokens against hashed API keys:Trace Ingestion
Routing Engine Deep Dive
Request Flow
Proxy Controller
Database Layer
Schema Overview
Migration Management
TypeORM migrations run automatically on startup:Frontend Layer
Package: manifest-frontend (private)
SolidJS-based dashboard for monitoring and configuration.
Location: packages/frontend/
Architecture
Authentication Client
Real-time Updates
Charts (uPlot)
Manifest uses uPlot for high-performance timeseries charts:Deployment
Single-Service Build
- API routes:
/api/*,/otlp/*,/v1/* - Static frontend: Everything else →
frontend/dist/index.html(SPA fallback)
Environment Variables
Key variables for deployment:Docker Deployment
Security Architecture
Defense in Depth
- Content Security Policy: Strict CSP via Helmet (no external CDNs)
- API Key Hashing: scrypt KDF with random salt
- Provider Key Encryption: AES-256-GCM with per-user keys
- Session Security: HttpOnly cookies, 7-day expiry
- Rate Limiting: Global throttle (100 req/min)
- SQL Injection Prevention: TypeORM parameterized queries
- Multi-tenant Isolation: All queries filtered by
userId
Encryption Flow
Performance Optimizations
Caching Layers
- API Key Cache: 5-minute in-memory cache (OtlpAuthGuard)
- Model Pricing Cache: Full catalog in memory (ModelPricingCacheService)
- Dashboard Data Cache: 1-minute TTL via
@nestjs/cache-manager - Session Cache: Better Auth handles session caching
Database Indexing
Critical indexes:(agent_id, timestamp DESC)onagent_messages(agent_id, hour DESC)ontoken_usage_snapshots(trace_id)onagent_messages(user_id, provider)unique onuser_providers
Query Optimization
- Aggregation Pushdown: Use
SUM(),COUNT()in SQL - Batch Inserts: Insert multiple entities in single transaction
- Pagination: Cursor-based pagination for message log
- Connection Pooling: pg.Pool with 20 max connections
Next Steps
Deploy Manifest
Deploy to Railway, Render, or Docker
Cloud vs Local
Choose the right deployment mode