57.1 Architecture Generation Router Service
Documentation for Sessions
57.1 Architecture: GenerationRouterService for Unified AI Generation
Date: January 20, 2026 Type: Architecture Decision Confidence: 95% (Certain)
Context
The "Generate Widget" button in the AI Panel's widget tab was not working - no logs appeared in backend-api or backend-ai-api. Investigation revealed that IntelligenceCoordinatorService.processCompletion() was returning placeholder code instead of parsing actual AI responses.
Decision
Create GenerationRouterService as a unified entry point for all AI generation requests that routes directly to the correct backend-api endpoints.
Options Considered
- Fix only IntelligenceCoordinatorService.processCompletion() - Quick fix but doesn't address fragmented generation paths
- Create GenerationRouterService + fix processCompletion() ✅ CHOSEN - Clean abstraction + backward compatibility
- Bypass all frontend services and call backend directly from components - Too scattered, no reusability
Implementation
GenerationRouterService Routes
| Generation Type | Backend Endpoint |
|---|---|
| widget | POST /api/ai/generate/widget |
| module | POST /api/ai/generate/module |
| image | POST /api/ai/images/generate |
| video | POST /api/ai/videos/generate |
| code | POST /api/ai/chat/generate-code |
| chat | POST /api/ai/chat |
Key Features
- Unified
UnifiedGenerationRequestinterface for all types - Normalized
GenerationResultresponse format - History tracking with
generationHistorysignal - Loading state management
- Error handling with proper logging
processCompletion() Fix
The fix includes:
- Regex patterns to extract TypeScript, HTML, SCSS, and spec code blocks
- Confidence scoring based on code completeness
- Fallback generation for when parsing fails
- Extraction of imports and dependencies from generated code
Alignment with Session 56 Decisions
Session 56 decided to integrate gograb-modules' PhaseExecutor into backend-ai-api. This aligns because:
- GenerationRouterService is an abstraction layer - When PhaseExecutor is integrated, we only need to change the routing targets
- We're not creating a new separate service - Following the "integrate into existing" principle
- Backend endpoints are already production-ready - Leveraging existing infrastructure
Files
libs/libs-ai/gograb-ai/src/lib/services/generation-router.service.ts(NEW)libs/libs-ai/gograb-ai/src/lib/services/intelligence-coordinator.service.ts(MODIFIED)
Consequences
Positive:
- Widget generation now routes to backend correctly
- Single entry point for all generation types
- Easy to add PhaseExecutor integration later
Neutral:
- Two ways to generate (old IntelligenceCoordinator, new GenerationRouter)
- This is intentional for backward compatibility
Negative:
- None identified