- Framework
- Core Concepts
- Architecture
Architecture
The DesignCombo Video Editor SDK is built with a modular, event-driven architecture that separates concerns between state management, timeline visualization, and user interface components.
System Architecture
βββββββββββββββββββ βββββββββββββββββββ ββββββββββββββββββββ React App β β State Manager β β Timeline ββ β β β β ββ β’ UI Components βββββΊβ β’ State Store βββββΊβ β’ Canvas ββ β’ Event Handlersβ β β’ Event Handlersβ β β’ Interactions ββ β’ User Actions β β β’ Business Logicβ β β’ Visualization ββββββββββββββββββββ βββββββββββββββββββ ββββββββββββββββββββ β ββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββ Event System ββ ββ β’ Event Bus ββ β’ Event Filters ββ β’ Event Handlersββββββββββββββββββββ
Core Components
1. State Manager (@designcombo/state)
The central state management system that serves as the single source of truth for all video editor data.
Key Features:
- Reactive Updates: Uses RxJS BehaviorSubject for reactive state updates
- History Management: Built-in undo/redo functionality
- Selective Subscriptions: Subscribe to specific state changes
- Immutable Updates: Uses Immer for immutable state updates
State Structure:
interface State {// Design propertiessize: ISize; // Canvas dimensionsfps: number; // Frames per secondbackground: {type: "color" | "image";value: string;};// Timeline datatracks: ITrack[]; // Array of trackstrackItemIds: string[]; // Ordered list of item IDstrackItemsMap: Record<string, ITrackItem>; // Item lookup maptransitionIds: string[]; // Ordered list of transition IDstransitionsMap: Record<string, ITransition>; // Transition lookup map// Timeline viewscale: ITimelineScaleState; // Zoom and scale settingsduration: number; // Total video duration// UI stateactiveIds: string[]; // Currently selected itemsstructure: ItemStructure[]; // Nested structure for compositions}
2. Timeline (@designcombo/timeline)
A canvas-based visualization system that renders the video timeline and handles user interactions.
Key Features:
- Canvas Rendering: Uses Fabric.js for high-performance rendering
- Drag & Drop: Intuitive item manipulation
- Resize & Trim: Visual trimming and resizing of items
- Multi-selection: Select and manipulate multiple items
- Snapping: Magnetic snapping to grid and other items
Timeline Components:
- 1Tracks: Horizontal rows that contain media items
- 2Track Items: Visual representations of media elements
- 3Transitions: Effects between track items
- 4Playhead: Current playback position indicator
- 5Scale Controls: Zoom and time scale controls
3. Event System (@designcombo/events)
A centralized event system for communication between components.
Event Architecture:
βββββββββββββββ βββββββββββββββ ββββββββββββββββ UI Layer βββββΊβ Event Bus βββββΊβ State Layer ββ β β β β ββ β’ Buttons β β β’ Dispatch β β β’ Handlers ββ β’ Menus β β β’ Filter β β β’ Updates ββ β’ Keyboard β β β’ Subscribe β β β’ Business ββββββββββββββββ βββββββββββββββ βββββββββββββββ
Event Types:
- 1Add Events:
add:text,add:video,add:audio, etc. - 2Edit Events:
edit:object,edit:background, etc. - 3Layer Events:
layer:select,layer:delete,layer:move, etc. - 4History Events:
history:undo,history:redo - 5Design Events:
design:load,design:resize
Package Structure
packages/βββ state/ # State management and business logicβ βββ src/β β βββ StateManager.tsβ β βββ state/β β βββ events/β β βββ utils/β βββ package.jsonβββ timeline/ # Canvas timeline and interactionsβ βββ src/β β βββ Timeline.tsβ β βββ canvas/β β βββ interactions/β β βββ rendering/β βββ package.jsonβββ types/ # TypeScript type definitionsβ βββ src/β β βββ index.tsβ β βββ state.tsβ β βββ timeline.tsβ β βββ events.tsβ βββ package.jsonβββ typescript-config/ # Shared TypeScript configurationapps/βββ react/ # Example React application
Data Flow
1. User Action Flow
User Action β Event Dispatch β State Update β UI Re-render
Example:
// 1. User clicks "Add Text" button// 2. Event is dispatcheddispatch('add:text', {payload: {name: 'My Text',details: { text: 'Hello World' }}});// 3. State manager processes event// 4. State is updated// 5. Timeline re-renders with new text element
2. State Subscription Flow
State Change β Subscription Notification β UI Update
Example:
// Subscribe to active element changesstateManager.subscribeToActiveIds(({ activeIds }) => {// Update UI to show selected elementsupdateSelectionUI(activeIds);});
3. Timeline Interaction Flow
Timeline Interaction β Event Dispatch β State Update β Timeline Re-render
Example:
// 1. User drags timeline item// 2. Timeline dispatches move eventdispatch('move:item', {payload: { id: 'item-1', x: 100, y: 200 }});// 3. State manager updates item position// 4. Timeline re-renders with new position
Design Principles
1. Separation of Concerns
- State Manager: Handles all business logic and data
- Timeline: Handles visualization and user interactions
- Event System: Handles communication between components
- UI Components: Handle user interface and user actions
2. Event-Driven Architecture
- All communication happens through events
- Components are loosely coupled
- Easy to extend and modify behavior
- Predictable data flow
3. Reactive Programming
- State changes automatically trigger updates
- Components react to state changes
- Efficient rendering and updates
- Real-time synchronization
4. Modular Design
- Each package has a specific responsibility
- Easy to use individual components
- Flexible integration options
- Scalable architecture
Integration Patterns
React Integration
function VideoEditor() {const [stateManager, setStateManager] = useState<StateManager>();const [timeline, setTimeline] = useState<Timeline>();useEffect(() => {// Initialize state managerconst sm = new StateManager(initialState);setStateManager(sm);// Initialize timelineconst tl = new Timeline(canvas, { state: sm });setTimeline(tl);return () => {tl.purge();sm.purge();};}, []);// Subscribe to state changesuseEffect(() => {if (!stateManager) return;const subscription = stateManager.subscribeToActiveIds(({ activeIds }) => {setSelectedItems(activeIds);});return () => subscription.unsubscribe();}, [stateManager]);return (<div><TimelineCanvas ref={canvasRef} /><Controls onAddText={() => dispatch('add:text', { payload: {...} })} /></div>);}
Vanilla JavaScript Integration
// Initialize componentsconst stateManager = new StateManager(initialState);const timeline = new Timeline(canvas, { state: stateManager });// Subscribe to changesstateManager.subscribeToActiveIds(({ activeIds }) => {updateUI(activeIds);});// Handle user actionsdocument.getElementById('add-text').addEventListener('click', () => {dispatch('add:text', { payload: {...} });});
Next Steps
- Learn about State Management in detail
- Explore the Timeline System
- Understand the Event System
- Check out Examples for practical usage