MongoDB Architectural Changes

Detailed breakdown of architectural changes from current to target state

MongoDB Architectural Changes

Purpose: Document all architectural changes being made to the MongoDB infrastructure for GoGrab Space.


πŸ“‹ Change Summary

Change From To Reason
Cluster Tier Flex M30 (at launch) Production requirements
API Architecture Single backend-api Separate backend-ai-api Workload isolation
Database Structure 1 AI database 4 specialized databases Clear separation of concerns
Vector Search Basic Search Nodes (when needed) Performance isolation

πŸ—οΈ Current Architecture (Before)

Single Backend API

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        backend-api (:3000)                              β”‚
β”‚                                                                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚ Core Features   β”‚  β”‚ AI Features     β”‚  β”‚ Platform Intelligence   β”‚ β”‚
β”‚  β”‚                 β”‚  β”‚                 β”‚  β”‚                         β”‚ β”‚
β”‚  β”‚ β€’ spaces        β”‚  β”‚ β€’ ai-agents     β”‚  β”‚ β€’ platform-intel        β”‚ β”‚
β”‚  β”‚ β€’ widgets       β”‚  β”‚ β€’ ai-learning   β”‚  β”‚ β€’ pattern mining        β”‚ β”‚
β”‚  β”‚ β€’ themes        β”‚  β”‚ β€’ mcp           β”‚  β”‚ β€’ calibration           β”‚ β”‚
β”‚  β”‚ β€’ users         β”‚  β”‚ β€’ generation    β”‚  β”‚                         β”‚ β”‚
β”‚  β”‚ β€’ ecommerce     β”‚  β”‚ β€’ assistant     β”‚  β”‚                         β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                                                                         β”‚
β”‚  PROBLEMS:                                                              β”‚
β”‚  β€’ AI workloads compete with core platform                              β”‚
β”‚  β€’ Can't scale AI independently                                         β”‚
β”‚  β€’ AI crash affects entire platform                                     β”‚
β”‚  β€’ Deployment coupled                                                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Current MongoDB Structure

MongoDB Atlas (Flex Cluster)
β”‚
β”œβ”€β”€ gograb-api                # Core platform
β”‚   β”œβ”€β”€ spaces
β”‚   β”œβ”€β”€ widgets
β”‚   └── ...
β”‚
β”œβ”€β”€ ai-agents             # AI (mixed concerns)
β”‚   β”œβ”€β”€ agent_calibrations    # 0 docs
β”‚   β”œβ”€β”€ agent_decisions       # 0 docs  
β”‚   β”œβ”€β”€ agent_embeddings      # 25 docs ← Vector
β”‚   β”œβ”€β”€ agent_metrics         # 0 docs
β”‚   β”œβ”€β”€ agent_outcome_correlations # 0 docs
β”‚   β”œβ”€β”€ agent_patterns        # 0 docs ← Vector
β”‚   β”œβ”€β”€ agent_tasks           # 0 docs
β”‚   β”œβ”€β”€ tenant_user_interactions # 0 docs ← Vector
β”‚   └── tenant_user_profiles  # 0 docs
β”‚
└── gograb-analytics          # Analytics (isolated)

Problems with Current Structure:

  1. ❌ All AI concerns mixed in one database
  2. ❌ Vector-heavy collections mixed with operational data
  3. ❌ No clear separation between agent orchestration and learning
  4. ❌ Tenant personalization mixed with platform AI

🎯 Target Architecture (After)

Separate Backend APIs

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                              FRONTEND                                       β”‚
β”‚                           (gograb-space)                                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚                                      β”‚
              β–Ό                                      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     backend-api (:3000)     β”‚    β”‚         backend-ai-api (:3001)          β”‚
β”‚                             β”‚    β”‚                                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚    Core Features      β”‚  β”‚    β”‚  β”‚          AI Features              β”‚  β”‚
β”‚  β”‚                       β”‚  β”‚    β”‚  β”‚                                   β”‚  β”‚
β”‚  β”‚  β€’ spaces             β”‚  β”‚    β”‚  β”‚  β€’ agents (MCP, orchestration)    β”‚  β”‚
β”‚  β”‚  β€’ widgets            β”‚  β”‚    β”‚  β”‚  β€’ intelligence (platform AI)     β”‚  β”‚
β”‚  β”‚  β€’ themes             β”‚  β”‚    β”‚  β”‚  β€’ learning (self-learning)       β”‚  β”‚
β”‚  β”‚  β€’ users              β”‚  β”‚    β”‚  β”‚  β€’ memory (vectors, embeddings)   β”‚  β”‚
β”‚  β”‚  β€’ ecommerce          β”‚  β”‚    β”‚  β”‚  β€’ generation (module/widget)     β”‚  β”‚
β”‚  β”‚  β€’ singularity        β”‚  β”‚    β”‚  β”‚  β€’ assistant (Space AI)           β”‚  β”‚
β”‚  β”‚  β€’ realtime           β”‚  β”‚    β”‚  β”‚  β€’ mcp (MCP endpoints)            β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                             β”‚    β”‚                                         β”‚
β”‚  Uses: gograb-api           β”‚    β”‚  Uses: ai-agents                    β”‚
β”‚        gograb-core          β”‚    β”‚        ai-memory                 β”‚
β”‚                             β”‚    β”‚        gograb-ai-tenants                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚                                      β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
                                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     MongoDB Atlas (Same Cluster)                            β”‚
β”‚                                                                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚ gograb-api   β”‚ β”‚ai-agents β”‚ β”‚gograb-ai-mem β”‚ β”‚gograb-ai-tenants β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Benefits:

  1. βœ… AI scales independently from core platform
  2. βœ… AI crash doesn't affect core platform
  3. βœ… Independent deployment cycles
  4. βœ… Clear separation of concerns
  5. βœ… Optimized resources per workload

πŸ—„οΈ Database Structure Changes

From (Current)

ai-agents (MIXED CONCERNS)
β”œβ”€β”€ agent_calibrations        ─┐
β”œβ”€β”€ agent_decisions           ─── Operational data
β”œβ”€β”€ agent_tasks               ──
β”œβ”€β”€ agent_metrics             β”€β”˜
β”‚
β”œβ”€β”€ agent_embeddings          ─┐
β”œβ”€β”€ agent_patterns            ─── Vector-heavy learning
β”œβ”€β”€ agent_outcome_correlationsβ”€β”˜
β”‚
β”œβ”€β”€ tenant_user_interactions  ─┐
└── tenant_user_profiles      β”€β”˜β”€ Tenant personalization

To (Target)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    RESTRUCTURED DATABASE LAYOUT                         β”‚
β”‚                                                                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  ai-agents (ORCHESTRATION)                                  β”‚   β”‚
β”‚  β”‚  Purpose: Agent runtime operations                              β”‚   β”‚
β”‚  β”‚                                                                 β”‚   β”‚
β”‚  β”‚  β”œβ”€β”€ sessions        # Agent session management                 β”‚   β”‚
β”‚  β”‚  β”‚   └── Indexes: tenantId, createdAt, status                  β”‚   β”‚
β”‚  β”‚  β”œβ”€β”€ decisions       # Decision log (lightweight)               β”‚   β”‚
β”‚  β”‚  β”‚   └── Indexes: sessionId, agentId, timestamp                β”‚   β”‚
β”‚  β”‚  β”œβ”€β”€ tasks           # Task tracking                            β”‚   β”‚
β”‚  β”‚  β”‚   └── Indexes: userId, status, createdAt                    β”‚   β”‚
β”‚  β”‚  └── agent_state     # Current agent states                     β”‚   β”‚
β”‚  β”‚      └── Indexes: agentId (unique)                             β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                                                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  ai-memory (LEARNING) ← Vector-heavy                     β”‚   β”‚
β”‚  β”‚  Purpose: AI learning and memory                                β”‚   β”‚
β”‚  β”‚                                                                 β”‚   β”‚
β”‚  β”‚  β”œβ”€β”€ embeddings      # Vector embeddings ⬅️ MAIN VECTOR INDEX   β”‚   β”‚
β”‚  β”‚  β”‚   └── Vector Index: embedding (1536 dims)                   β”‚   β”‚
β”‚  β”‚  β”œβ”€β”€ patterns        # Learned patterns                         β”‚   β”‚
β”‚  β”‚  β”‚   └── Indexes: type, successRate                            β”‚   β”‚
β”‚  β”‚  β”œβ”€β”€ context_cache   # Pre-computed context (TTL)               β”‚   β”‚
β”‚  β”‚  β”‚   └── Indexes: key, expiresAt (TTL)                         β”‚   β”‚
β”‚  β”‚  └── calibrations    # Model calibration data                   β”‚   β”‚
β”‚  β”‚      └── Indexes: modelId, updatedAt                           β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                                                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  gograb-ai-tenants (PERSONALIZATION)                            β”‚   β”‚
β”‚  β”‚  Purpose: Per-tenant AI customization                           β”‚   β”‚
β”‚  β”‚                                                                 β”‚   β”‚
β”‚  β”‚  β”œβ”€β”€ user_profiles   # Per-user AI profiles                     β”‚   β”‚
β”‚  β”‚  β”‚   └── Indexes: tenantId+userId (compound unique)            β”‚   β”‚
β”‚  β”‚  β”œβ”€β”€ user_interactions # Interaction history                    β”‚   β”‚
β”‚  β”‚  β”‚   └── Indexes: tenantId+userId, timestamp                   β”‚   β”‚
β”‚  β”‚  └── preferences     # AI preferences                           β”‚   β”‚
β”‚  β”‚      └── Indexes: tenantId+userId                              β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Why This Separation?

Database Purpose Characteristics
ai-agents Runtime orchestration High write, moderate read, operational
ai-memory Learning & vectors Vector-heavy, memory-intensive, searchable
gograb-ai-tenants Personalization Per-tenant isolation, GDPR-friendly

πŸ”§ Service Migration Map

Services Moving to backend-ai-api

Service Current Location New Location
AgentTaskService backend-api/ai-agents backend-ai-api/agents
AgentSessionService backend-api/ai-agents backend-ai-api/agents
AgentContextService backend-api/ai-agents backend-ai-api/agents
AgentOrchestratorService backend-api/ai-agents backend-ai-api/agents
AgentLearningBridgeService backend-api/ai-agents backend-ai-api/learning
AgentVectorMemoryService backend-api/ai-agents backend-ai-api/memory
AgentPatternMiningService backend-api/ai-agents backend-ai-api/intelligence
ModuleGenerationAgentService backend-api/ai-agents backend-ai-api/generation
WidgetGenerationAgentService backend-api/ai-agents backend-ai-api/generation
SpaceAssistantService backend-api/ai-agents backend-ai-api/assistant
TenantAIService backend-api/ai-agents backend-ai-api/tenants
UnifiedAgentStorageService backend-api/ai-agents backend-ai-api/storage
PlatformIntelligenceService backend-api/platform-intelligence backend-ai-api/intelligence
AiLearningService backend-api/ai-learning backend-ai-api/learning
AIService backend-api/ai backend-ai-api/core

Services Staying in backend-api

Service Reason
SpacesService Core platform
WidgetsService Core platform
ThemesService Core platform
UsersService Core platform
AuthService Shared (library)
SingularityService Core platform
EcommerceService Core platform

πŸ” Shared Authentication

Both APIs will share authentication via a common library:

// libs/libs-api/auth-core/src/lib/auth.module.ts
@Module({
  imports: [
    PassportModule,
    JwtModule.registerAsync({
      imports: [ConfigModule],
      useFactory: (config: ConfigService) => ({
        secret: config.get('JWT_SECRET'),
        signOptions: { expiresIn: '7d' },
      }),
      inject: [ConfigService],
    }),
  ],
  providers: [JwtStrategy, AuthGuard],
  exports: [JwtStrategy, AuthGuard],
})
export class AuthCoreModule {}
// Usage in backend-ai-api
@Module({
  imports: [
    AuthCoreModule, // Same auth as backend-api
    // ... AI modules
  ],
})
export class AppModule {}

🌐 Frontend Changes

Environment Configuration

// environments/environment.ts
export const environment = {
  production: false,
  apiUrl: 'http://localhost:3000',
  aiApiUrl: 'http://localhost:3001',  // NEW
};

// environments/environment.prod.ts
export const environment = {
  production: true,
  apiUrl: 'https://api.gograb.space',
  aiApiUrl: 'https://ai-api.gograb.space',  // NEW
};

Service Updates

// Before
@Injectable()
export class AIService {
  constructor(private http: HttpClient) {}
  
  chat(message: string) {
    return this.http.post('/api/ai/chat', { message });
  }
}

// After
@Injectable()
export class AIService {
  private aiApiUrl = inject(AI_API_URL); // New injection token
  
  chat(message: string) {
    return this.http.post(`${this.aiApiUrl}/api/assistant/chat`, { message });
  }
}

πŸ“Š Migration Timeline

Phase Duration Changes
Phase 1 Day 1 Create backend-ai-api application
Phase 2 Days 2-3 Migrate services, create shared auth
Phase 3 Day 4 Database restructure, migrate data
Phase 4 Day 5 Frontend updates, testing
Phase 5 Launch Upgrade Flex β†’ M30

⚠️ Breaking Changes

API Endpoint Changes

Old Endpoint New Endpoint Notes
localhost:3000/api/ai-agents/* localhost:3001/api/agents/* New API
localhost:3000/api/platform-intelligence/* localhost:3001/api/intelligence/* New API
localhost:3000/api/ai-learning/* localhost:3001/api/learning/* New API
localhost:3000/api/ai/* localhost:3001/api/assistant/* New API

Database Connection Changes

// Old (in backend-api)
MongooseModule.forRootAsync({
  connectionName: 'ai-agents',
  useFactory: () => ({
    uri: process.env.MONGODB_CONNECTION_STRING,
    dbName: 'ai-agents',
  }),
});

// New (in backend-ai-api) - Multiple connections
MongooseModule.forRootAsync({
  connectionName: 'agents',
  useFactory: () => ({
    dbName: 'ai-agents',  // Orchestration
  }),
});

MongooseModule.forRootAsync({
  connectionName: 'memory',
  useFactory: () => ({
    dbName: 'ai-memory',  // Vector-heavy
  }),
});

MongooseModule.forRootAsync({
  connectionName: 'tenants',
  useFactory: () => ({
    dbName: 'gograb-ai-tenants',  // Personalization
  }),
});

πŸ”— Related Documentation