Session 19.2 - Architecture Fix - Universe vs Module
Correcting the fundamental architecture confusion in vibe-universe-generator
Session 19.2: Architecture Fix - Universe vs Module
π― The Core Problem
The vibe-universe-generator is confusing "Platform" with "Module".
What We're Generating
User Input: "Create a fitness management platform"
β
AI Generates: 7 separate modules
- Member Management
- Trainer Management
- Class Schedule Management
- Workout Management
- Exercise Management
- Trainer Assignment Management
- Membership Type Management
What We're Currently Saving (WRONG)
// Creating a SINGLE MODULE called "Fitness Management"
this.moduleContext.createModule("Fitness Management", 'custom')
// Trying to stuff ALL 7 modules into ONE ModuleContext
// This breaks the architecture!
What We Should Be Saving (CORRECT)
// 1. Create/Update UNIVERSE
{
_id: "universe-fitness-management-1767058598901",
name: "Fitness Management",
slug: "fitness-management",
modules: ["mod-member-mgmt", "mod-trainer-mgmt", ...],
// ... universe metadata
}
// 2. Create 7 separate MODULES
{
_id: "mod-member-management-xxx",
name: "Member Management",
universeId: "universe-fitness-management-1767058598901",
entities: [Member],
actions: [CreateMember, UpdateMember, ...],
embeddables: [MemberList, MemberCard, ...]
}
// ... repeat for each of the 7 modules
π Architecture Reference
The Hierarchy (from BUILDING-BLOCKS-ARCHITECTURE.md)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β LEVEL 5: UNIVERSE (Platform) β
β Complete applications (SaaS, E-commerce, Blog, etc.) β
β Composed of: Multiple Galaxies + Tenant Config + Theme β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β LEVEL 4: GALAXY (Optional) β
β Feature collections with shared navigation (2+ modules) β
β Composed of: Related Modules + Shared Routes + Navigation β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β LEVEL 3: MODULES β
β Business features (User Management, E-commerce, Auth) β
β Composed of: Widgets, Actions, Events, Services β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β LEVEL 2: WIDGETS β
β UI Components (Button, Card, Form, Container) β
β Composed of: Properties with Inputs/Outputs β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β LEVEL 1: PROPERTIES β
β Atomic values (width, color, fontSize, padding) β
β Stored in: MongoDB, consumed by all widgets β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
MongoDB Collections
| Collection | Database | Purpose |
|---|---|---|
universes |
space_{slug}_{id} |
Deployable platforms/applications |
galaxies |
space_{slug}_{id} |
Optional feature groupings (2+ modules) |
space_modules |
space_{slug}_{id} |
Individual business features |
space_pages |
space_{slug}_{id} |
Content pages |
space_widgets |
space_{slug}_{id} |
Widget instances |
π§ The Fix
Step 1: Universe Creation/Update
When "Deploy to Universe" is clicked:
// Check if universe exists
let universe = await this.universeService.getBySlug(spaceId, platformSlug);
if (!universe) {
// Create new universe
universe = await this.universeService.create(spaceId, {
name: manifest.name,
slug: platformSlug,
description: manifest.description,
deploymentStatus: 'draft',
modules: [], // Will be populated as we create modules
structure: [], // Module tree structure
galaxyIds: []
});
}
Step 2: Create Each Module Separately
const createdModuleIds: string[] = [];
for (const moduleName of extractedModules) {
// Extract module-specific data from manifest
const moduleData = extractModuleDataFromManifest(manifest, moduleName);
// Create module in space_modules collection
const module = await this.backendModuleApi.createSpaceModule(spaceId, {
name: moduleName,
slug: toKebabCase(moduleName),
type: 'feature-module',
description: moduleData.description,
icon: moduleData.icon,
universeId: universe._id, // Link to universe
scope: 'universe', // Universe-scoped
// Full module data
defaultConfig: {
entities: moduleData.entities,
actions: moduleData.actions,
embeddables: moduleData.embeddables
},
// Metadata
ai: {
description: moduleData.description,
keywords: [platformName, moduleName],
capabilities: moduleData.entities.map(e => e.name),
complexity: 'moderate',
suggestionWeight: 80
}
});
createdModuleIds.push(module._id);
}
Step 3: Update Universe with Modules
// Update universe with all created modules
await this.universeService.update(spaceId, universe._id, {
modules: createdModuleIds,
structure: generateModuleTree(createdModuleIds),
moduleTreeVersion: universe.moduleTreeVersion + 1
});
Step 4: Navigation Behavior
Current (Wrong):
// Navigate to workbench with a "module" that's actually a platform
/modularity/workbench/fitness-management-1767058598901
Correct Options:
Option A: Navigate to Universe Canvas (modular-universe)
// Navigate to the universe canvas where user can arrange modules
/universe/fitness-management/canvas
Option B: Navigate to Module List
// Show list of generated modules, user picks which to edit
/modularity/modules?universeId=fitness-management
Option C: Open First Module
// Open the first generated module in workbench
/modularity/workbench/member-management-xxx?universeId=fitness-management
π¨ UI/UX Improvements
Module Cards Should Show
{
name: "Member Management",
description: "Manage gym members with profiles, memberships, and check-ins",
entities: ["Member", "Membership", "CheckIn"],
actions: 15, // CRUD x 3 entities
embeddables: 12, // List/Card/Form/Detail x 3 entities
status: "ready",
universeId: "fitness-management",
universeName: "Fitness Management Platform"
}
Better Module List UI
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π Platform Generated Successfully! β
β β
β Fitness Management Platform β
β 7 modules ready to use β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββββββββββββββ ββββββββββββββββββββββββ β
β β π₯ Member Management β β ποΈ Trainer Managementβ β
β β β β β β
β β Manage gym members β β Manage trainers and β β
β β with profiles and β β their schedules β β
β β memberships β β β β
β β β β β β
β β π 3 entities β β π 2 entities β β
β β β‘ 15 actions β β β‘ 10 actions β β
β β π¨ 12 components β β π¨ 8 components β β
β β β β β β
β β [Edit] [Preview] β β [Edit] [Preview] β β
β ββββββββββββββββββββββββ ββββββββββββββββββββββββ β
β β
β [Deploy to Universe] [Arrange on Canvas] [Export] β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π§ Implementation Plan
Phase 1: Fix Data Model (Priority 1)
- Stop creating a single "platform module"
- Start creating a Universe + separate Modules
- Save each module to
space_modulescollection - Link modules to universe via
universeId
Phase 2: Fix Navigation (Priority 2)
- "Deploy to Universe" β Create universe, save modules, navigate to
/universe/{slug}/canvas - "Edit Module" β Navigate to
/modularity/workbench/{moduleId}?universeId={universeId} - "Refine in Workbench" β Navigate to universe canvas, not workbench
Phase 3: Enhance Module Cards (Priority 3)
- Extract metadata from generated manifest
- Show entity/action/embeddable counts
- Show descriptions
- Add preview capability
Phase 4: MongoDB Sync (Priority 4)
- Use existing
UniverseModuleServicefor universe operations - Use existing
BackendModuleApiServicefor module operations - Implement offline queue for failed syncs
- Add sync status indicators
π Files to Modify
| File | Changes |
|---|---|
vibe-universe-generator.component.ts |
Refactor to create Universe + Modules |
platform-state.service.ts |
Add universe tracking |
universe-module.service.ts |
Ensure universe CRUD works |
backend-module-api.service.ts |
Ensure module CRUD works |
π Key Insights
- Platform = Universe (not Module)
- Universe contains Modules (not the other way around)
- Modules are reusable across universes
- ModuleContext is for building a single module in modularity-lib workbench
- Universe is for deploying a complete platform with multiple modules
Next: Implement the architecture fix with proper Universe + Module separation.