ARCHITECTURE CLARIFICATION
Comprehensive guidelines for AI-assisted development within the Editor platform
Architecture Clarification - Modules vs Widgets/Embeddables
Date: December 9, 2025
Session: 9
Status: ✅ Understanding Complete
🎯 Critical Architecture Understanding
The Fundamental Relationship
MODULES (Most Important - NX Libraries)
├── Services (business logic)
├── Actions (operations)
└── Embeddables (UI widgets they expose)
└── These ARE the "widgets"
Key Insight: Widgets ARE embeddables. They are NOT separate concepts.
📦 What is a Module?
Definition: NX library with BrowserModuleContract that provides functionality
Characteristics:
- ✅ NX library (
project.json,tsconfig.lib.json) - ✅ Has services, state, business logic
- ✅ Has public actions
- ✅ Exposes embeddables in manifest
- ✅ Can be used inside other modules
- ✅ Independently buildable
Creation Methods:
- Module Workbench (
/modularity) - Visual builder → Generates NX library - Code-First (
nx g @nx/angular:lib) - Manual creation
Examples:
- User Management Module
- Product Catalog Module
- Analytics Module
🧩 What is an Embeddable (Widget)?
Definition: Standalone Angular component that can be plugged into modules or pages
Characteristics:
- ✅ Standalone Angular component
- ✅ UI-only (can have inputs/outputs)
- ✅ Gets plugged INTO modules or pages
- ✅ Registered via
WidgetsEmbeddableRegistryService - ✅ Discoverable platform-wide
- ❌ NOT an NX library (unless part of a module)
Types:
Module Embeddables (
source: 'builtin')- Defined in module's manifest
- Have static Angular component reference
- Example:
UserListWidgetComponentfrom User Management Module
User-Created Embeddables (
source: 'user-created')- Created via Widget Builder
- Saved to MongoDB (
space_widgets) - Have template/styles (compiled at runtime)
- NO static component reference (
component: null)
Examples:
- UserListWidget (from module)
- PricingCard (user-created)
- ProductCard (from module)
🔄 The Complete Flow
Module Creation (Module Workbench)
1. Navigate to /modularity
2. Define entities, actions, embeddables
3. Click "Export as NX Library"
4. Generated output:
├── libs/modules/my-module/
│ ├── project.json
│ ├── tsconfig.lib.json
│ ├── src/
│ │ ├── lib/
│ │ │ ├── my-module.module.ts (BrowserModuleContract)
│ │ │ ├── services/
│ │ │ ├── actions/
│ │ │ └── embeddables/
│ │ │ └── my-widget.component.ts
│ │ └── index.ts
5. Module registers with ModuleRegistryService
6. Embeddables register with WidgetsEmbeddableRegistryService
Widget Creation (Widget Builder)
1. Navigate to /space/:spaceId/widgets/builder
2. Choose creation method:
- AI Generate (describe in natural language)
- Templates (select pre-built template)
- From Component (select from embeddable registry)
3. Customize properties (visual editor)
4. Finalize (name, description, category)
5. Save:
├── POST /api/spaces/:spaceId/widgets
├── Widget saved to MongoDB (space_widgets collection)
└── Registered as embeddable:
embeddable: {
id: 'user-widget-{id}',
component: null, // No static component
source: 'user-created',
// ... metadata
}
6. Widget appears in:
- Widget showcase (/space/:spaceId/widgets/)
- Embeddable registry (platform-wide)
- Can be used in pages and modules
🚫 What I Got Wrong (Initially)
My Incorrect Assumption
"Priority 5: Widget Builder should generate NX libraries"
Why This Was Wrong:
- Widgets are embeddables (UI components)
- Embeddables don't need to be NX libraries
- Only MODULES need to be NX libraries
- Widget Builder creates embeddables, NOT modules
The Correct Understanding
Widget Builder:
- ✅ Creates embeddable definitions
- ✅ Saves to MongoDB
- ✅ Registers with embeddable registry
- ❌ Does NOT generate NX libraries
- ❌ Does NOT create modules
Module Workbench:
- ✅ Creates functional modules (NX libraries)
- ✅ Modules can INCLUDE embeddables
- ✅ Generates complete NX library structure
- ✅ Creates services, actions, and UI
📊 Comparison Matrix
| Aspect | Module | Widget/Embeddable |
|---|---|---|
| Is NX Library? | ✅ YES (required) | ❌ NO (unless part of module) |
| Has Business Logic? | ✅ YES (services, actions) | ❌ NO (UI only) |
| Created Via | Module Workbench OR code-first | Widget Builder OR module manifest |
| Saved To | Filesystem (libs/modules/) | MongoDB (space_widgets) OR module manifest |
| Has Component? | ⚠️ May include embeddables | ✅ YES (IS a component) |
| Independently Buildable? | ✅ YES (NX build) | ⚠️ Depends (user-created = runtime) |
| Usage | Platform infrastructure | UI element in pages/modules |
| Examples | UserManagement, ProductCatalog | Button, Card, Toast, Input |
🎯 What the Widget Builder SHOULD Do
Current System (Already Correct!)
// widget-storage.service.ts
private registerWidgetAsEmbeddable(widget: Widget): void {
const embeddable: EmbeddableDefinition = {
id: `user-widget-${widget.id}`,
name: widget.name,
description: widget.description || '',
category: widget.category || 'custom',
component: null as any, // User-created widgets have no static component
inputs: [...],
outputs: [...],
source: 'user-created',
tags: widget.tags || [],
};
this.widgetsEmbeddableRegistry.register(embeddable);
}
This is CORRECT! The widget builder:
- ✅ Creates widget definition
- ✅ Saves to MongoDB
- ✅ Registers as embeddable
- ✅ Makes it available platform-wide
What Needs Improvement (Per WIDGET-SYSTEM-IMPROVEMENTS.md)
NOT "Generate NX Libraries" - That was wrong!
Actual Improvements Needed:
- Configuration Editor - Visual editor for variant properties
- Save/Manage Variants - User-created variant persistence
- More Interactive Tests - Dialog, Menu, Panel testing
- Complex Widget Separation - Separate basic from configurable widgets
- Better UX/UI - More modern, clean, intuitive interface
- Smart Categorization - AI-powered widget organization
🔗 Key Relationships
Module → Embeddables
// In module manifest
@ModuleDecorator({
id: 'user-management',
// ...
})
export class UserManagementModule implements BrowserModuleContract {
readonly manifest: ModuleManifest = {
embeddableComponents: [
{
id: 'users:list-widget',
componentType: UserListWidgetComponent, // ✅ Static component reference
displayName: 'User List Widget',
category: 'widget',
inputs: [/* ... */]
}
]
};
}
Modules CAN Contain Embeddables
libs/modules/user-management/
├── project.json (NX library config)
├── src/
│ ├── lib/
│ │ ├── user-management.module.ts (BrowserModuleContract)
│ │ ├── services/
│ │ │ └── user.service.ts (business logic)
│ │ ├── actions/
│ │ │ └── create-user.action.ts (operations)
│ │ └── embeddables/
│ │ ├── user-list-widget.component.ts (embeddable)
│ │ └── user-card-widget.component.ts (embeddable)
│ └── index.ts
Result: Module is an NX library that EXPOSES embeddables in its manifest.
Widget Builder → Embeddables (NOT Modules)
Widget Builder
↓
MongoDB (space_widgets collection)
↓
Embeddable Registry
↓
Available for use in:
- Pages (via page editor)
- Modules (via module composition)
- Showcase (for testing)
✅ Session 9 Correction
Original Priority 5: "Add NX library generation to widget builder"
Status: ❌ CANCELLED - Fundamentally misunderstood architecture
Correct Understanding:
- Widget Builder creates embeddables (UI components)
- Module Workbench creates modules (NX libraries with functionality)
- These are separate tools for separate purposes
- Both can create embeddables, but via different methods
What Was Actually Completed in Session 9:
- ✅ Route consolidation
- ✅ Variant UI integration
- ✅ Widget builder consolidation (3 creation methods)
- ✅ Backend API documentation
- ✅ Architecture clarification (this document)
🎓 Key Takeaways
- Modules = NX libraries (generated by Module Workbench)
- Widgets = Embeddables (UI components)
- Widget Builder creates embeddables, NOT modules
- Module Workbench creates modules (which CAN include embeddables)
- Embeddables can exist independently (user-created) OR within modules (module embeddables)
- The current system is architecturally correct - it just needs UX improvements
Document Version: 1.0
Session: 9
Date: December 9, 2025
Status: ✅ Architecture Understanding Complete
Next: Focus on actual improvements (configuration editor, better UX, more tests)