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:
- β All AI concerns mixed in one database
- β Vector-heavy collections mixed with operational data
- β No clear separation between agent orchestration and learning
- β 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:
- β
AI scales independently from core platform
- β
AI crash doesn't affect core platform
- β
Independent deployment cycles
- β
Clear separation of concerns
- β
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