Documentation

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

graph TD INDEX[πŸ“š Widget System Index
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 modifyRequestBatch API)

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

graph LR subgraph "Content Creators" C1[Using existing widgets
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

Custom Widgets

πŸ› οΈ System Features

3-Pillar Architecture

Every widget follows the same architectural pattern:

  1. πŸ“‹ Definition (index.ts) - Widget configuration and validation
  2. ✏️ Input (Input.svelte) - Interactive editing component
  3. πŸ‘οΈ 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 contentLanguage for 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
email βœ… 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:

πŸ”— Related Documentation

API References

Architecture Guides

Security Documentation

Development Resources


πŸ§ͺ 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

  1. New to widgets? Start with Widget System Overview
  2. Want to create widgets? Follow the Development Guide
  3. Need technical details? Dive into Widget Architecture
  4. Testing widgets? Check Widget Test Coverage
  5. 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

🎯 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 management
  • config:widgetInstall - Install widgets
  • config:widgetUninstall - Uninstall widgets
  • config:widgetActivate - Activate/deactivate widgets
  • config: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 Sanitize component 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

  1. Always implement 3 pillars: Definition, Input, Display
  2. Use factory pattern: Leverage createWidget() for consistency
  3. Validate with Valibot: Centralize validation in definition
  4. Document dependencies: Clearly specify widget dependencies
  5. Test thoroughly: Unit test each pillar independently

Widget Management

  1. Regular audits: Review installed widgets periodically
  2. Monitor dependencies: Track widget relationships
  3. Security updates: Keep widgets updated
  4. Usage analysis: Track which widgets are actively used
  5. Performance: Monitor impact on system performance

πŸ”— Related Resources


The Widget System provides a powerful, extensible foundation for content management in SveltyCMS with modern architecture and professional management tools.

developerwidgetsdocumentation3-pillararchitecturei18nmultilingual