Backend Vitto Api Architecture
Ecosistema completo para organización y gestión de contenido con interfaces espaciales
Backend Vitto API — Architecture & AI Agent Guide
Purpose: Source of truth for backend-vitto-api structure, module boundaries, and refactoring guidance.
Audience: AI agents and developers extending or maintaining the Vitto super-agent backend.
Updated: March 2026 — Post Global Engineering Standard refactor (Session 214)
Overview
backend-vitto-api (port 3003) is the Vitto super-agent backend. It orchestrates:
- Task execution (4-phase pipeline: analyze → plan → execute → verify)
- Channel processing (WhatsApp, Web, A2A)
- Memory, awareness, and proactive intelligence
- Module generation and tool execution
Architecture
APIs/backend-vitto-api/src/app/
├── engine/ # Core brain — orchestration, phases, context
│ ├── controllers/ # VittoCoreController, domain controllers
│ ├── context-assembly/ # Prompt assembly, channel/web builders
│ ├── phase-executor/ # Phase-specific prompt building
│ ├── orchestration/ # Vitto config factory
│ └── adapters/ # Channel adapters (WhatsApp, Web)
├── mind/ # Memory, knowledge, intelligence
│ └── memory/ # Memory sub-services (store, recall, embedding)
├── connectivity/ # Channel gateway, WebSocket, handoff
├── llm/ # Smart routing, provider factory
├── tools/ # Tool registry (plugin-based)
├── module-generation/ # Module spec → code generation
├── awareness/ # Proactive awareness channels
├── proactive/ # Proactive monitoring
├── security/ # Resilience, DLQ
└── a2a/ # Google A2A protocol bridge
Module Boundaries
| Module | Responsibility | Key Services |
|---|---|---|
| Engine | Task lifecycle, phases, context assembly, channel processing | VittoEngineService, PhaseExecutorService, ContextAssemblyService |
| Mind | Memory, recall, embeddings, knowledge graph | VittoMemoryService, VisualMemoryService |
| Connectivity | Channels, WebSocket, handoff to backend-ai-api | ChannelGatewayService |
| LLM | Model routing, provider selection | SmartRouterService, ProviderFactoryService |
| Tools | Tool registry (plugins), handlers | ToolRegistryService |
| Module Generation | Spec → Nx library code | ModuleGenPhaseExecutor, AutoCorrectionService |
Key Refactor Patterns (Session 214)
- Controllers: Split by domain (e.g. VittoCoreController, tool utilities)
- Services: Extract sub-services when >500 lines; keep orchestrator thin
- Context Assembly:
context-assembly/— ChannelPromptBuilder, WebPromptBuilder, EmotionalContext - Memory:
mind/memory/— Store, Recall, HotCache, Importance, Embedding - Tools: Plugin-based registry with
tools/plugins/ - Auto-correction: Strategy pattern under
validation/corrections/strategies/
File Size Guidelines
| Target | Max Lines | Action |
|---|---|---|
| Services | ~400 | Extract sub-services or helpers |
| Controllers | ~300 | Split by domain |
| Utils | ~200 | Split by concern |
Extending the Codebase
Adding a new awareness channel
- Implement
AwarenessChannelinawareness/channels/ - Register in
AwarenessModule - See
docs/english/GoGrab-Space/architecture/for awareness design
Adding a new tool
- Create plugin in
tools/plugins/ - Register in
plugins.index.ts - Add handler if needed in
tools/handlers/
Adding a new module generation correction
- Add strategy in
module-generation/validation/corrections/strategies/ - Register in correction rules
Dependencies
- @libs-api/backend-core: Redis, CORS, throttling, database names, AI model config
- @libs-api/auth-core: JWT, guards
- @libs-api/r2-storage-core: File storage
- backend-ai-api: AI workloads via HTTP/WebSocket handoff
Testing
- Unit tests:
**/__tests__/*.spec.ts - Provide mocks for all injected services (e.g.
VittoMemoryServiceforVisualMemoryService) - Use
@nestjs/testingTest.createTestingModulewith explicit providers
Common Test Fixes
| Error | Fix |
|---|---|
Cannot resolve dependencies of X (?). Please make sure that the argument Y at index [n] is available |
Add { provide: Y, useValue: mockY } or { provide: getModelToken(Schema.name), useValue: mockModel } to providers |
sseSubject.complete() → Cannot read properties of undefined |
Use sseSubject?.complete() in afterEach — sseSubject may be undefined if beforeEach fails |
VittoMemoryService not found |
Provide by class: { provide: VittoMemoryService, useValue: mockMemoryService } (not string token) |
GenerationEventDocModel not found |
Add { provide: getModelToken(GenerationEventDoc.name), useValue: mockEventModel } |
TrustEscalationService not found |
Add { provide: TrustEscalationService, useValue: { getTrustLevel: jest.fn().mockResolvedValue(null), getTrustScore: jest.fn().mockResolvedValue(null) } } |
Segregation Checklist
When adding or refactoring:
- No service >500 lines — extract sub-services or helpers
- Controllers thin — delegate to services
- One responsibility per file
- Types in dedicated types/spec files
- Tests provide all required mocks