How 0x-nan/nexus works
Purpose and Entry Points
Nexus is a self-hosted, real-time governance control plane for AI agents that initiate payments. It evaluates transaction requests inline, records every decision, can globally revoke activity, and streams events to an operator dashboard.
Primary runtime entry points are FastAPI in backend/app/main.py, the React client in frontend/src/main.jsx, and local multi-service orchestration in docker-compose.yml.
API and Control Plane
FastAPI routers expose the external governance surface: agent registration/listing, transaction evaluation and audit export, kill-switch control, and simulation controls. The API is deliberately agent-framework-agnostic: any caller that can submit a transaction can be governed.
Core route boundaries are in:
• backend/app/routers/transactions.py
• backend/app/routers/agents.py
• backend/app/routers/kill_switch.py
Authentication-specific endpoints and service logic are separated in backend/app/routers/auth.py and backend/app/services/auth.py.
Policy Evaluation Pipeline
Transaction evaluation is the central synchronous control flow. A request passes through configured checks in order: global kill-switch state, agent scope/category, spend-cap thresholds, and burst/rate detection. The first denial wins; flags are recorded without halting subsequent checks.
The policy engine owns this enforcement boundary, while deployment-time YAML defines permitted agent behavior and rules:
• backend/app/services/policy_engine.py
• backend/config/policy_rules.yaml
• backend/config/agents.yaml
Rules are loaded at startup rather than edited through an API, preserving version-controlled policy ownership.
Persistent Audit and State
PostgreSQL is the authoritative persistence layer for agents, evaluated transactions, decision reasons, and operational state. The transaction logger provides the audit-writing boundary; schema and initialization data establish append-oriented storage and initial fleet configuration.
Relevant paths:
• backend/app/database.py
• backend/app/services/transaction_logger.py
• backend/db/schema.sql
The backend uses async PostgreSQL access; migrations under backend/db/migrations/ evolve schema behavior.
Kill Switch and Fleet Revocation
The kill switch is a dedicated service and API concern rather than a dashboard-only state. Its state is consulted during every policy evaluation, allowing fleet-wide denial before downstream policy checks. State changes are also audit-worthy events.
Relevant paths:
• backend/app/services/kill_switch.py
• backend/app/routers/kill_switch.py
• backend/app/services/policy_engine.py
Real-Time Event Distribution and Dashboard
After decisions/state changes are persisted, the backend broadcasts server-push updates over WebSockets. The frontend consumes these updates to render live agent status, audit activity, controls, and developer-oriented views; it is not the enforcement authority.
Relevant paths:
• backend/app/ws_manager.py
• frontend/src/App.jsx
• frontend/src/components/DashboardLayout.jsx
Client session/auth state is centralized at frontend/src/context/AuthContext.jsx.
Simulation and Optional LLM Traffic
A built-in simulator produces ambient agent transactions and can inject overspend, off-scope, or burst behavior to exercise the same public enforcement path. The Travel Agent can optionally use a local Ollama endpoint, with deterministic fallback behavior when unavailable.
Relevant paths:
• backend/app/simulator/engine.py
• backend/app/simulator/llm_agent.py
• backend/app/routers/simulator.py
Deployment and External Dependencies
Docker Compose coordinates frontend, FastAPI backend, PostgreSQL 17, and optional locally reachable Ollama. Frontend production serving is containerized behind Nginx; Prometheus configuration exists for metrics scraping.
Relevant paths:
• docker-compose.yml
• backend/Dockerfile
• frontend/Dockerfile
• prometheus/prometheus.yml
Main entry points: main.py FastAPI control plane · policy_engine.py Policy engine · App.jsx React dashboard · kill_switch.py Fleet kill switch
Components 21
Operator UI
- React dashboard · Operator-facing live governance console.
frontend/src/App.jsx - Dashboard layout
frontend/src/components/DashboardLayout.jsx - Auth context
frontend/src/context/AuthContext.jsx
Governance API
- FastAPI control plane · Framework-agnostic external governance surface.
backend/app/main.py - Transaction API
backend/app/routers/transactions.py - Agent API
backend/app/routers/agents.py - Kill-switch API
backend/app/routers/kill_switch.py - Authentication
backend/app/services/auth.py - Simulator API
backend/app/routers/simulator.py
Enforcement services
- Policy engine · First denial wins; later checks may still record flags.
backend/app/services/policy_engine.py - Versioned policy rules
backend/config/policy_rules.yaml - Agent fleet config
backend/config/agents.yaml - Fleet kill switch · Globally denies activity before downstream checks.
backend/app/services/kill_switch.py - Agent simulator · Exercises the same public transaction enforcement path.
backend/app/simulator/engine.py - Travel LLM agent · Uses Ollama when reachable, otherwise deterministic fallback.
backend/app/simulator/llm_agent.py
State and events
- Transaction logger
backend/app/services/transaction_logger.py - WebSocket broadcaster
backend/app/ws_manager.py - PostgreSQL · Stores agents, decisions, reasons, and operational state.
backend/app/database.py - Audit schema · Append-oriented storage and initial fleet data.
backend/db/schema.sql
Runtime dependencies
- Docker Compose · Coordinates the local service stack.
docker-compose.yml - Ollama
Connections 28
- Docker Compose → React dashboard: runs
- Docker Compose → FastAPI control plane: runs
- Docker Compose → PostgreSQL: runs
- React dashboard → Dashboard layout: renders
- React dashboard → Auth context: uses
- React dashboard → FastAPI control plane: API requests
- WebSocket broadcaster → React dashboard: live updates
- FastAPI control plane → Transaction API: mounts
- FastAPI control plane → Agent API: mounts
- FastAPI control plane → Kill-switch API: mounts
- FastAPI control plane → Authentication: authenticates via
- FastAPI control plane → Simulator API: mounts
- Transaction API → Policy engine: evaluates transaction
- Policy engine → Fleet kill switch: checks first
- Policy engine → Versioned policy rules: loads at startup
- Policy engine → Agent fleet config: loads at startup
- Policy engine → Transaction logger: records decision
- Kill-switch API → Fleet kill switch: changes state
- Fleet kill switch → Transaction logger: records state change
- Agent API → PostgreSQL: manages agents
- Transaction logger → PostgreSQL: writes audit
- Audit schema → PostgreSQL: defines
- Transaction logger → WebSocket broadcaster: broadcasts persisted decisions
- Fleet kill switch → WebSocket broadcaster: broadcasts state changes
- Simulator API → Agent simulator: controls
- Agent simulator → Transaction API: submits transactions
- Agent simulator → Travel LLM agent: uses travel behavior
- Travel LLM agent → Ollama: optional inference