Components
Nexus is composed of four host services and three infrastructure containers, plus a per-developer bridge. Each has a narrow responsibility.
Gateway (services/gateway, port 4000)
Entry point for everything inbound: Rocket.Chat outgoing webhooks plus every developer's bridge WebSocket.
Responsibilities:
- Subscribe to Rocket.Chat events (DDP / webhook) and ingest every message into Redis (working buffer) + Postgres (
messagesaudit trail). - Detect bot mentions and DM-to-bot, push an
invokejob onto Redis / BullMQ. - Serve the WebSocket hub for bridges (auth, dispatch, reconnect).
- Provide the Admin REST API consumed by the Web UI: login, bridge CRUD, MCP server CRUD, agent stats.
Composer (services/composer, port 4001)
The brain. Consumes invoke jobs and produces the prompt that will be handed to the runtime.
Pipeline per invocation:
- Pull the working memory window for the room/DM from Redis.
- Pull user profiles for active participants.
- Pull project memory if the room is tagged.
- Run Mem0 semantic search against the latest message (
run_idfilter applied). - Estimate token usage; if > 70%, trigger compaction inline.
- Resolve the MCP tool list allowed in this room (via
room_tool_acl). - Build the final prompt with the attribution header.
- Hand off to the runtime via Redis.
Runtime (services/runtime, port 4002, host-only)
Spawner / dispatcher. Receives prompts from the composer and routes each to the correct destination:
- Local CLI — for built-in agents (
@claude,@hermes,@cursor,@gemini), spawns a PTY using the matching adapter inruntime/src/adapters/. - Remote bridge — for per-user bridge bots (e.g.
@claude-alice-backend), forwards over the gateway's WebSocket hub.
In both cases, output is streamed back chunk-by-chunk and posted to Rocket.Chat as the matching bot user.
Adapter pattern: each CLI gets its own file under adapters/ with three shared concerns — spawn, parse stdout, detect tool_call. See Adding a CLI adapter for the recipe.
Bridge (packages/nexus-bridge)
Lightweight WebSocket client that runs on a developer's laptop. It:
- Authenticates to the gateway with a token issued by
make create-bridge. - Announces its identity (slug, CLI kind, working directory) on connect.
- Forwards prompts received over WS to the local CLI's stdin.
- Streams the CLI's stdout back over WS chunk-by-chunk.
- Auto-reconnects on network drop with backoff.
The bridge is the only piece each developer runs — everything else lives on the host. See Add an AI partner.
Mem0 API (services/mem0-api, port 4100, Docker)
Python sidecar wrapping Mem0 with a thin FastAPI surface (add / search / delete). Composer talks to it over HTTP.
We chose to keep Mem0 in its native Python (rather than port to Bun) because the upstream extraction pipeline is Python-only for full feature parity. Loose coupling via HTTP keeps the rest of the stack TypeScript.
Postgres + pgvector (port 5433)
Single source of truth for:
- Identity:
users,agents,rooms,projects. - Audit / replay:
messages. - Episodic memory:
summaries(withvector(1536)embeddings). - Landmarks:
landmarks(pinned messages, never compacted). - Structured facts:
facts(per-user, per-project, per-room). - MCP:
mcp_servers,room_tool_acl. - Audit trail:
audit_log.
See DATA-MODEL on GitHub for the full schema.
Redis (port 6380)
Three concerns:
- Working memory — per-room rolling buffer of the last N messages.
- Job queue (BullMQ) —
invokeandexecutejobs flowing from gateway to composer to runtime. - Distributed locks — per-room mutex when two invokes hit the same room concurrently.
Rocket.Chat (port 3000)
The chat UI. Nexus does not fork Rocket.Chat — it consumes the REST
- Realtime APIs. Every AI agent gets a bot user in Rocket.Chat (created during
make bootstrapormake create-bridge).
Web UI (services/web, served by gateway at /admin/*)
Vite + React 19 + Tailwind v4 admin app. Provides:
- Login (uses
NEXUS_ADMIN_TOKEN). - Bridge management (create, edit persona, list connected, regenerate token).
- MCP server management.
- Channel + user listing.
Built artifact lives in services/web/dist/ and is served by the gateway under /admin/*.