APIs Architecture
Documentation for Architecture
APIs Architecture
The Three Backends
GoGrab runs three core backends. Each has ONE job. No overlap.
| Backend | Port | Role | One-liner |
|---|---|---|---|
| backend-api | 3000 | The Database | Stores all platform data, handles auth |
| backend-ai-api | 3001 | The Brain | Intelligence — thinks, learns, remembers patterns |
| backend-vitto-api | 3003 | The Hands | Execution — does things, uses tools, talks to users |
A fourth backend (backend-docs-api, port 3002) handles documentation. It's independent and not covered here.
backend-api (3000) — "The Database"
What belongs here: Any data that platform web apps read/write. Users, spaces, universes, modules, widgets, properties, themes, billing, deployment pipeline, git provider abstraction, admin.
What does NOT belong here: AI reasoning, tool execution, agent logic, LLM calls.
Key rule: This is the source of truth for all platform entities. Other backends call it to read/write platform data, never the reverse.
Domains
| Domain | Examples |
|---|---|
| Auth | JWT login, magic links, phone auth, OAuth |
| Users | Profiles, preferences, agent memories, privacy |
| Spaces & Universes | Space CRUD, universe lifecycle, galaxies |
| Modules & Widgets | Module config, widget variants, marketplace |
| Properties & Themes | Property definitions, theme management |
| Git Provider | GitLab/Gitea/Hetzner abstraction (GitProviderController) |
| Deployment | Build pipeline, Cloudflare Pages, subdomain management |
| Billing | Stripe subscriptions, MCP billing events |
| Data Collections | Per-universe MongoDB collections (dynamic) |
| Admin | Stats, user management, role management |
Databases
| Database | Contents |
|---|---|
gograb-api |
Primary — all platform data |
ai-agents |
Agent tasks, sessions, patterns (migrating to ai-api) |
ai-memory |
Vector embeddings for agent memory |
ai-context |
AI usage tracking, learning mappings |
| Per-space DBs | Dynamic space_{slug} databases for tenant isolation |
Calls no other backend. Is called by everyone.
backend-ai-api (3001) — "The Brain"
What belongs here: Intelligence. Anything that helps the system learn, decide, remember patterns, or expose AI tools via MCP.
What does NOT belong here: Tool execution, sandbox management, browser automation, code generation pipeline. (These belong in vitto-api — see consolidation note below.)
Domains (target state)
| Domain | What it does |
|---|---|
| MCP Gateway | HTTP + WebSocket + JSON-RPC transport for MCP tool access |
| Learning Pipeline | Decisions, patterns, outcomes, proactive triggers |
| Calibration | Confidence scoring, outcome correlation |
| Super-Intelligence | Episodic memory, causal reasoning, reflection |
| Agent Registry | Agent CRUD, vector memory, pattern mining |
| Sessions | Chat session persistence, conversation genome |
| Embeddings | Vector embedding generation and storage |
| Platform AI | Training pipeline, knowledge base, agent registry |
| Archive | Cold storage for old decisions and embeddings |
| Chat | Direct AI chat (Claude/OpenAI/Gemini) or proxied through Vitto |
Databases
| Database | Contents |
|---|---|
ai-agents |
Agent tasks, decisions, patterns |
ai-memory |
Vector embeddings, semantic search |
ai-mcp-dev |
MCP decisions, learning patterns, session intelligence |
ai-archive |
Cold storage |
gograb-api (shared read) |
User profiles for identity enrichment |
Calls
| Target | Why |
|---|---|
| backend-api (3000) | Platform code push, space data, billing events |
| backend-vitto-api (3003) | Task orchestration, chat proxy, decision events |
| backend-docs-api (3002) | Session doc sync |
Current state vs target
NOTE: As of March 2026, backend-ai-api also contains ~17 controllers that belong in backend-vitto-api: sandbox proxy, browser/desktop/computer-use automation, git proxy, code generation workflow, orchestration relay, observatory, skills, task runner. A consolidation is planned — see
docs/superpowers/specs/2026-03-24-backend-consolidation-design.md. Until that migration happens, these controllers remain functional in ai-api.
backend-vitto-api (3003) — "The Hands"
What belongs here: Execution. Anything that DOES something — runs tools, manages sandboxes, browses the web, generates code, talks to users via channels, proxies git operations.
What does NOT belong here: Pattern learning, decision storage, MCP protocol, agent registry.
Domains
| Domain | What it does |
|---|---|
| Engine | Core ANALYZE-PLAN-EXECUTE-VERIFY loop, sub-agents, autonomy |
| Tools | 20 plugins, ~55 tools (code execution, browser, git, messaging, etc.) |
| Mind | Persistent memory (vector), knowledge graph, mood, dossiers |
| Platform Generation | 6-phase module generation pipeline (SSE streaming) |
| Studio | Git operations (GitLab + Hetzner), deploy to Cloudflare |
| Space Builder | Universe lifecycle (blueprint, build, deploy, rollback) |
| Channels | WhatsApp, Slack, Discord, Telegram, Email |
| Security | Audit logs, compliance, circuit breakers, DLQ |
| Training | Self-learning, teach, pattern extraction |
| Connectors | External API connector framework |
| A2A | Google Agent-to-Agent protocol |
| MCP Server | Exposes Vitto as an MCP-compatible tool server |
Databases
| Database | Contents |
|---|---|
vitto-mind |
Engine state, sessions, memory, skills, sub-agents, audit |
vitto-users |
User dossiers, job playbooks |
Calls
| Target | Why |
|---|---|
| backend-api (3000) | Spaces, universes, modules, user data |
| backend-ai-api (3001) | Handoffs, learning intelligence, training data, vector search |
| backend-docs-api (3002) | Doc search, file operations |
| Hetzner orchestrator | Sandbox VMs, git repos (via ai-api until consolidation) |
| LLM providers | Core engine reasoning (Claude, OpenAI, Gemini, DeepSeek) |
| Channel APIs | Twilio, Slack, Discord, Telegram, SendGrid |
Data Flow Direction
┌──────────────┐
│ backend-api │
│ (3000) │
│ "The Database"│
└──────┬───────┘
│
reads/writes platform data
│
┌───────────────┼───────────────┐
│ │
┌───────▼────────┐ ┌────────▼───────┐
│ backend-ai-api │ │backend-vitto-api│
│ (3001) │ ──────────► │ (3003) │
│ "The Brain" │ decisions │ "The Hands" │
│ │ & plans │ │
│ │ ◄────────── │ │
│ │ outcomes │ │
└────────────────┘ & learning └─────────────────┘
Key principle: The Brain produces decisions and plans. The Hands execute them and report outcomes. No circular dependency — information flows in one direction per concern.
Shared Infrastructure
Authentication
All three backends use AuthCoreModule from @libs-api/auth-core with the same JWT_SECRET. A JWT issued by backend-api is valid on ai-api and vitto-api. UnifiedAuthGuard runs globally on all backends.
MongoDB
All backends connect to the same MongoDB Atlas cluster. They use different logical databases. backend-ai-api has shared read access to gograb-api (backend-api's database) for user profile enrichment.
Environment Variables
In Railway (production), all backends share env vars via variable groups. In local development, the shared .env.local at monorepo root is read by all backends via NestJS ConfigModule.
Cross-Service Auth
Service-to-service calls use BACKEND_API_INTERNAL_TOKEN (same value as SYSTEM_TOKEN) in the Authorization: Bearer header. No separate service mesh or mTLS.
Extension & Frontend Routing
| Client | Talks to | For |
|---|---|---|
| VSCode Extension | ai-api (3001) | MCP tools, preflight, decisions, handoffs, git operations |
| VSCode Extension | vitto-api (3003) | Chat SSE (/engine/agent-session) |
| gograb-space (5200) | backend-api (3000) | All platform CRUD |
| gograb-dev (6300) | ai-api (3001) via proxy | Infrastructure dashboard, observatory |
| gograb-dev (6300) | sandbox-orchestrator via /sandbox-api proxy |
Git operations dashboard |
| vitto-chat (5400) | vitto-api (3003) | Chat, engine, tools |
Hetzner Sandbox Orchestrator
The sandbox-orchestrator runs on Hetzner bare-metal servers (AX42-U, AX102-U). It is NOT a NestJS backend in our monorepo — it's a separate Express app deployed directly to the servers.
It manages:
- Firecracker microVMs (create, snapshot, exec, destroy)
- Git repositories (list, branches, commits, file tree, clone URLs)
- Host metrics (CPU, memory, disk, VM capacity)
Access pattern: backend-ai-api reaches it via SANDBOX_SERVER_URL + SANDBOX_API_KEY (native fetch()). After the consolidation, backend-vitto-api will reach it directly.
Port Reference
| Service | Port | Env Var |
|---|---|---|
| backend-api | 3000 | API_PORT |
| backend-ai-api | 3001 | AI_API_PORT |
| backend-docs-api | 3002 | DOCS_API_PORT |
| backend-vitto-api | 3003 | VITTO_API_PORT |
| gograb-space | 5200 | — |
| gograb-admin | 5100 | — |
| gograb-dev | 6300 (dev proxy) | — |
| vitto-chat | 5400 | — |
Rule: Never hardcode ports. Use yarn serve:* commands which read from .env.local. Never pass --port to backend serve commands (causes WebSocket 400 errors).