Architecture: Where should cross-API schemas and services live for the Two...
Documentation for Sessions
🏗️ Architecture: Where should cross-API schemas and services live for the Two...
Date: 2026-01-31
Time: 18:32:06 UTC
Session: editor2-75.18
Agent: backend
Confidence: 95%
Status: ✅ Documented
📋 Decision Context
Question:
Where should cross-API schemas and services live for the Two-Layer Agent Memory system?
Task: Session 75.15: Two-Layer Agent Intelligence & Preference Override System
🎯 Decision Made
Chosen:
Move schemas (UserAgentMemory, UserPreferences) and services (UserAgentService, UserPreferencesService) to @libs-api/backend-core shared library
Options Considered:
- Keep in backend-api only, have backend-ai-api call HTTP endpoints
- Duplicate code in both APIs
- Create new @libs-api/user-intelligence library
- Move to @libs-api/backend-core (chosen)
💭 Reasoning
Both backend-api and backend-ai-api need access to agent memories and user preferences. Duplicating code across APIs would violate DRY and cause maintenance nightmares. The shared library pattern already exists with auth-core, so this follows established conventions. Services are stateless and only depend on MongoDB models, making them safe to share. Controllers stay in individual APIs since they handle HTTP-specific logic.
📁 Files Involved
libs/libs-api/backend-core/src/lib/schemas/user-agent-memory.schema.tslibs/libs-api/backend-core/src/lib/schemas/user-preferences.schema.tslibs/libs-api/backend-core/src/lib/services/user-agent.service.tslibs/libs-api/backend-core/src/lib/services/user-preferences.service.ts
🔗 Related
- Decision ID:
dev_1769884326126_l5ea4hl - Session: 75
- Workspace: editor2
Auto-generated by MCP Smart Consolidation