Widget System Documentation
Complete widget system documentation covering 3-pillar architecture, management, development, multilingual support, and security
Last updated: 11/14/2025
Widget System Documentation
Welcome to the comprehensive SveltyCMS widget system documentation. The widget system is built on a modern 3-Pillar Architecture providing type safety, performance optimization, and developer-friendly patterns.
π Documentation Structure
Core Documentation
You are here] VISUAL[π Visual Overview
Mermaid diagrams & flows] OVERVIEW[ποΈ Widget System Overview
High-level concepts & features] ARCH[βοΈ Widget Architecture
Technical implementation] DEV[π¨βπ» Development Guide
Creating custom widgets] INDEX --> VISUAL INDEX --> OVERVIEW INDEX --> ARCH INDEX --> DEV style INDEX fill:#e1f5fe style VISUAL fill:#ffeb3b,color:#000 style OVERVIEW fill:#f3e5f5 style ARCH fill:#fff8e1 style DEV fill:#e8f5e8
0. Visual Overview β
Visual guide with comprehensive Mermaid diagrams explaining the entire system.
Covers:
- π― Complete system flow diagrams
- ποΈ 3-Pillar architecture deep dive
- π Widget lifecycle & data flow
- πͺ Store state management
- ποΈ Database relationships
- π Performance strategies
Read this when: You prefer visual learning or need to understand system interactions.
1. Widget System Overview
Start here for understanding the widget system concepts and capabilities.
Covers:
- ποΈ 3-Pillar Architecture (Definition, Input, Display)
- π― Widget types (Core vs Custom)
- π System features and lifecycle
- π Directory structure
- π Performance optimizations
Read this when: Youβre new to the widget system or need a high-level understanding.
2. Widget Architecture
Technical deep-dive into the widget system implementation.
Covers:
- π Widget Factory System
- πͺ Widget Store Management
- ποΈ Database Integration
- π§ Runtime Implementation
- π‘οΈ Type Safety
- π Performance Optimizations
- π Batch Data Loading (New
modifyRequestBatchAPI)
Read this when: You need to understand how the system works internally or debug issues.
3. Development Guide
Practical tutorial for creating and customizing widgets.
Covers:
- π Quick start tutorial
- π Step-by-step widget creation
- π§ Advanced features
- π§ͺ Testing strategies
- π¦ Widget management
- π Deployment best practices
Read this when: You want to create custom widgets or modify existing ones.
4. Widget Security
Comprehensive security guide for widget development and implementation.
Covers:
- π‘οΈ XSS prevention techniques
- π Injection attack protection
- π File upload validation
- π SSRF prevention
- π IDOR protection
- β Input sanitization patterns
- π§ͺ Security testing
Read this when: You need to understand or implement widget security measures.
5. Multilingual Widget Guide
Complete guide to building multilingual widgets.
Covers:
- π Translation architecture
- π Language-aware components
- πΎ Database storage patterns
- π― Content vs system languages
- β Best practices
Read this when: Youβre building widgets that need translation support.
π― Quick Navigation
For Different Roles
in collections] C2[Widget configuration
options] end subgraph "Developers" D1[Creating custom
widgets] D2[Understanding widget
architecture] D3[Testing and
debugging] end subgraph "Administrators" A1[Managing widget
activation] A2[Multi-tenant
configuration] A3[Performance
monitoring] end C1 --> OVERVIEW C2 --> DEV D1 --> DEV D2 --> ARCH D3 --> DEV A1 --> OVERVIEW A2 --> ARCH A3 --> ARCH style C1 fill:#e8f5e8 style D1 fill:#f3e5f5 style A1 fill:#fff8e1
By Task
| I want to⦠| Read this | Section |
|---|---|---|
| Understand widget concepts | System Overview | Core Concepts |
| Use widgets in collections | System Overview | Quick Start |
| Create a custom widget | Development Guide | Step-by-Step Tutorial |
| Understand the factory pattern | Architecture | Factory System |
| Debug widget issues | Architecture | Runtime Implementation |
| Configure widget validation | Development Guide | Advanced Features |
| Enable/disable widgets | System Overview | Widget Management |
| Optimize widget performance | Architecture | Performance |
| Implement widget security | Widget Security | Security Fixes |
| Add translation support | Multilingual Guide | Translation Patterns |
| Install widgets at runtime | Runtime Discovery | Dynamic Loading |
π Quick Start Examples
Using Existing Widgets
// In a collection schema
import { widgets } from '@src/widgets';
export default {
fields: [
widgets.Input({
label: 'Title',
required: true,
maxLength: 100
}),
widgets.RichText({
label: 'Content',
translated: true
}),
widgets.Date({
label: 'Published Date',
required: true
})
]
};
Creating a Simple Custom Widget
// src/widgets/custom/rating/index.ts
import { createWidget } from '@src/widgets/factory';
const RatingWidget = createWidget({
Name: 'Rating',
Icon: 'mdi:star',
Description: 'Star rating widget',
inputComponentPath: '/src/widgets/custom/rating/Input.svelte',
displayComponentPath: '/src/widgets/custom/rating/Display.svelte',
validationSchema: number(),
defaults: {
maxRating: 5,
allowHalfStars: false
}
});
export default RatingWidget;
π Individual Widget Documentation
Each widget includes its own comprehensive documentation:
Core Widgets
- Input Widget - Text input with validation
- Rich Text Widget - WYSIWYG editor
- Date Widget - Date and time picker
- Media Upload Widget - File upload
- Relation Widget - Entity relationships
Custom Widgets
- SEO Widget - SEO meta tags and schema
- Address Widget - Address with geocoding
- Currency Widget - Monetary values
- Color Picker Widget - Color selection
π οΈ System Features
3-Pillar Architecture
Every widget follows the same architectural pattern:
- π Definition (
index.ts) - Widget configuration and validation - βοΈ Input (
Input.svelte) - Interactive editing component - ποΈ Display (
Display.svelte) - Optimized display component
Key Capabilities
- β Type Safety - Full TypeScript support throughout
- π Dynamic Loading - Widgets loaded on-demand for performance
- π’ Multi-Tenant - Different widget configurations per tenant
- π Security - Permission-based widget access control
- π Self-Documenting - Each widget includes MDX documentation
- π§ͺ Testable - Comprehensive testing support
- π Multilingual - Built-in translation support via
contentLanguagefor all text-based widgets
Multilingual Widget Support
SveltyCMS widgets support multilingual content through the translated field property:
Enable Translation:
// Collection field configuration
{
widget: 'input',
label: 'Article Title',
db_fieldName: 'title',
translated: true, // β Enables multilingual support
required: true
}
Data Storage Format:
// Database-agnostic format (MongoDB nested, SQL relational)
{
"title": {
"en": "Hello World",
"de": "Hallo Welt",
"fr": "Bonjour le monde"
}
}
Supported Widgets:
| Widget Type | Multilingual | Use Case |
|---|---|---|
| input | β Yes | Text content per language |
| richText | β Yes | Rich HTML content per language |
| β Yes | Localized email templates | |
| phoneNumber | β Yes | International phone with localized labels |
| number | β Yes | Localized number formatting |
| seo | β Yes | SEO metadata per language |
| relation | β Conditional | Display fields translated |
| megaMenu | β Yes | Menu structure per language |
Learn More:
- Language Architecture - Complete multilingual system guide
- Widget Architecture - Multilingual Section - Implementation patterns
- Widget Development Guide - Translation Support - Building translatable widgets
π Related Documentation
API References
- Widget API - REST API endpoints
- Collection API - Collection management
- GraphQL API - GraphQL schema generation
Architecture Guides
- Runtime Widget Discovery - Zero-downtime widget installation
- Validation Instant Feedback - Smart validation system
- Collection Store Dataflow - Data flow patterns
- Database Methods - Database operations
- Code Structure - Overall codebase structure
- Language Architecture - Multilingual system
Security Documentation
- Widget Security - Comprehensive widget security guide
- Security Overview - System-wide security measures
- Authentication System - User authentication
- Cryptography Module - Encryption and hashing
Development Resources
- Widget Test Coverage - Testing documentation
- Contributing Guide - Contributing to widgets
π§ͺ Testing
Widget Test Coverage
SveltyCMS includes comprehensive testing for all widgets:
- β 359+ Tests: Covering core widgets, custom widgets, and factory architecture
- β 86% Coverage: Complete widget system code coverage
- β Type Safety: Full TypeScript validation testing
- β Multilingual: Translation support testing
- β Database: Aggregation and query testing
Test Suite Breakdown:
| Category | Tests | Status | Coverage |
|---|---|---|---|
| Core Widgets (10) | 150+ | β Created | Validation, multilingual, aggregations |
| Custom Widgets (9) | 120+ | β Created | Email, SEO, Phone, Number, Currency |
| Widget System | 60+ | β 35 Passing | Factory, types, schemas |
| Architecture | 16 | β 100% | Modern factory pattern |
Run Widget Tests
# All widget tests
bun test tests/bun/widgets/
# Specific test files
bun test tests/bun/widgets/core-widgets.test.ts
bun test tests/bun/widgets/custom-widgets.test.ts
bun test tests/bun/widgets/widget-system.test.ts
# With coverage
bun test --coverage tests/bun/widgets/
Test Documentation
For complete testing documentation, patterns, and best practices:
π Widget Test Coverage Documentation
Includes:
- Detailed test results by widget
- Test patterns and best practices
- Running tests and debugging
- CI/CD integration
- Performance benchmarks
- Known issues and solutions
π― Next Steps
- New to widgets? Start with Widget System Overview
- Want to create widgets? Follow the Development Guide
- Need technical details? Dive into Widget Architecture
- Testing widgets? Check Widget Test Coverage
- Looking for specific widgets? Browse the individual widget documentation above
- Structure: group, repeater
Custom Widgets (Optional)
Located in src/widgets/custom/:
- Forms & Input: colorPicker, rating, currency
- SEO: seo, metadata
- Advanced: phoneNumber, address
- E-commerce: product, pricing (marketplace)
- Social: socialShare, embedder (marketplace)
π Documentation
Core Documentation
-
- 3-pillar architecture details
- Widget lifecycle and dependencies
- Multi-tenant configuration
- API endpoints
-
- Marketplace integration
- Widget discovery and installation
- Payment and licensing
- Community features
-
- Recent improvements
- Enhanced dashboard features
- Migration guide
π― Quick Start
Using Widgets
// In collection schema
import { widgets } from '@widgets';
export default {
fields: [
widgets.Input({
label: 'Title',
inputType: 'text',
required: true
}),
widgets.RichText({
label: 'Content',
toolbar: 'full'
}),
widgets.MediaUpload({
label: 'Featured Image',
accept: 'image/*'
})
]
};
Creating Widgets
// src/widgets/custom/myWidget/index.ts
import { createWidget } from '@widgets/factory';
import * as v from 'valibot';
export default createWidget({
Name: 'MyWidget',
Icon: 'mdi:puzzle-plus',
Description: 'Custom widget with 3-pillar architecture',
// 3-Pillar paths
inputComponentPath: '/src/widgets/custom/myWidget/Input.svelte',
displayComponentPath: '/src/widgets/custom/myWidget/Display.svelte',
// Validation
validationSchema: v.object({
value: v.string([v.minLength(1)])
}),
// Defaults
defaults: {
value: ''
}
});
π₯οΈ Management Interface
Access widget management at /config/widgetManagement:
Features
- π Statistics Dashboard: Real-time metrics
- π Search & Filter: Quick widget discovery
- π 2-Column Layout: Professional grid (desktop)
- πͺ Marketplace Tab: Browse and install widgets
- π― 3-Pillar Visibility: See component implementation status
- βοΈ Quick Actions: One-click activation/deactivation
Statistics Explained
- Total Widgets: All registered widgets (core + custom)
- Active: Currently enabled and usable in collections
- Core: Essential widgets (cannot be disabled)
- Custom: Optional widgets (can be toggled)
- Input: Widgets with Input component (editing capability)
- Display: Widgets with Display component (viewing capability)
π§ Widget Store API
Key Functions
import { widgetStoreActions, isWidgetActive, canDisableWidget, getWidgetDependencies } from '@stores/widgetStore.svelte';
// Initialize widgets
await widgetStoreActions.initializeWidgets('tenant-id');
// Check status
const isActive = isWidgetActive('SEO');
const canDisable = canDisableWidget('SEO');
const deps = getWidgetDependencies('SEO');
// Update status
await widgetStoreActions.updateWidgetStatus('SEO', 'active', 'tenant-id');
π¦ File Structure
src/
βββ widgets/
β βββ core/ # Core widgets
β β βββ input/
β β β βββ index.ts # Definition
β β β βββ Input.svelte # Edit component
β β β βββ Display.svelte # View component
β β βββ ...
β βββ custom/ # Custom widgets
β β βββ seo/
β β β βββ index.ts
β β β βββ Input.svelte
β β β βββ Display.svelte
β β βββ ...
β βββ factory.ts # Widget factory
β βββ types.ts # Type definitions
βββ stores/
β βββ widgetStore.svelte.ts # Centralized state
βββ routes/
βββ (app)/config/widgetManagement/
βββ +page.svelte
βββ +page.server.ts
βββ WidgetDashboardEnhanced.svelte
βββ WidgetCard.svelte
π Security & Permissions
Permission Levels
config:widgetManagement- View widget managementconfig:widgetInstall- Install widgetsconfig:widgetUninstall- Uninstall widgetsconfig:widgetActivate- Activate/deactivate widgetsconfig:marketplace- Access marketplace
Multi-Tenant Isolation
- Each tenant has separate widget configurations
- Core widgets are always active for all tenants
- Custom widgets are tenant-specific
- Database stores per-tenant widget states
π Security Checklist
Use this checklist when creating new widgets:
Input Validation
- MIME type whitelist (file widgets)
- File size limits (upload widgets)
- Extension validation (file widgets)
- Path traversal prevention
- Input length limits (text widgets)
- Format validation (email, phone, URL)
- Regex pattern validation
- Whitelist-based validation
Output Encoding
- HTML entity escaping
- CSS value sanitization
- URL encoding
- JavaScript string escaping
- SQL parameterization
XSS Prevention
- Use
Sanitizecomponent for HTML - Escape user-generated content
- Content Security Policy compliance
- Avoid
{@html}without sanitization - Validate URLs before rendering
SSRF Prevention
- URL protocol whitelist (https only)
- Domain whitelist
- Block private IPs
- Block localhost
- Block cloud metadata endpoints
IDOR Prevention
- Tenant ID filtering
- User ID validation
- Permission checks
- Relation validation
DoS Prevention
- Input length limits
- File size limits
- Rate limiting considerations
- Regex complexity limits
- Resource consumption limits
π Best Practices
Widget Development
- Always implement 3 pillars: Definition, Input, Display
- Use factory pattern: Leverage
createWidget()for consistency - Validate with Valibot: Centralize validation in definition
- Document dependencies: Clearly specify widget dependencies
- Test thoroughly: Unit test each pillar independently
Widget Management
- Regular audits: Review installed widgets periodically
- Monitor dependencies: Track widget relationships
- Security updates: Keep widgets updated
- Usage analysis: Track which widgets are actively used
- Performance: Monitor impact on system performance
π Related Resources
- Content Types - Using widgets in collections
- API Development - Widget API integration
- Testing - Widget testing strategies
- Security - Widget security considerations
The Widget System provides a powerful, extensible foundation for content management in SveltyCMS with modern architecture and professional management tools.