A proof-of-concept study exploring real-time collaborative document editing systems built with event sourcing architecture. This implementation serves as a research platform for understanding collaborative editing patterns, conflict resolution strategies, and real-time synchronization mechanisms.
- Block Creation: Users can create text blocks that form the document structure
- Content Editing: Real-time editing of individual blocks with change tracking
- Block Management: Insert, update, delete, and reorder blocks within documents
- Position-Aware Operations: Blocks can be inserted at specific positions
- Block Locking: Exclusive editing locks prevent concurrent modifications
- First-Lock-Wins: Clear conflict resolution strategy for competing edits
- Lock Expiration: Automatic 30-second timeouts prevent stuck locks
- Lock Management: Clean acquisition and release workflows
- Live Drafts: Track users' typing in real-time before committing changes
- Draft Synchronization: All users see live drafts from other collaborators
- Draft Commits: Convert drafts to permanent block content
- Multi-User Drafts: Handle multiple users drafting on different blocks
- User Management: Add/remove users with unique IDs and visual colors
- User Presence: Track active/inactive user states
- Concurrent Operations: Support multiple users working simultaneously
- User Attribution: Track which user made each change
- Immutable Event Log: All changes stored as events, never mutated
- State Projection: Current document state derived from event replay
- Version Control: Sequential event versioning for consistency
- State Reconstruction: Complete state can be rebuilt from events
The system includes comprehensive tests covering all major functionality:
- Event Sourcing Foundation: Event dispatch, atomic updates, versioning
- Block Management: CRUD operations, content updates, ordering
- Locking System: Lock acquisition, conflicts, expiration handling
- Draft System: Real-time updates, commits, cleanup
- Performance: Bulk operations (50+ blocks under 100ms)
- Data Integrity: Event replay and state reconstruction
- User Management: Adding/removing users, unique IDs, color assignment
- Concurrent Operations: Multiple users creating/editing blocks simultaneously
- Collaborative Locking: Lock conflicts and resolution across users
- Real-Time Draft Sharing: Live draft visibility between users
- Complex Workflows: Complete collaborative editing sessions
- Stress Testing: High-load scenarios with many users and operations
- Async Operations: Simulated network delays with proper timing
- Cross-Tab Synchronization: Multi-tab consistency verification
- Race Conditions: Lock competition with realistic timing
- Event Ordering: Proper sequencing of concurrent operations
- State Consistency: Verification across all connected clients
app/
├── stores/
│ ├── event-core.store.ts # Event sourcing engine
│ ├── document.store.ts # Block and document operations
│ ├── collaboration.store.ts # User, lock, and draft management
│ └── index.ts # Store exports
├── collaboration.types.ts # Core data structures
└── event.types.ts # Event definitions and utilities
test/
├── test-helpers.ts # Shared testing utilities
├── setup.ts # Test configuration
└── *.test.ts # Comprehensive test suites
The UI components have been moved to app/legacy/ as this project focuses on the core collaborative editing logic and architecture rather than user interface implementation.
- All changes captured as immutable events with metadata
- Current state computed by reducing over the event log
- Full audit trail and replay capabilities
- Version control through sequential event numbering
- Optimistic locking allows users to attempt any operation
- Block-level exclusive locks prevent concurrent modifications
- First-to-lock wins in conflict scenarios
- Automatic cleanup prevents orphaned locks
- Drafts tracked separately from committed content
- Live updates shared across all users instantly
- Clean commit workflow updates block content atomically
- Draft cleanup prevents memory leaks
# Install dependencies
pnpm install
# Run all tests
pnpm run test
# Run tests with detailed output
pnpm run test:run
# Type checking
pnpm run typecheck
# Code quality checks
pnpm run checkThis project serves as a Proof of Concept (POC) and Study for:
- Research: Exploring collaborative editing architectures and patterns
- Learning: Understanding event sourcing in real-time systems
- Prototyping: Testing different conflict resolution strategies
- Documentation: Creating reference implementations for collaborative features
All tests pass with comprehensive coverage:
- ✅ Event sourcing and state management
- ✅ Block operations and document management
- ✅ Multi-user collaboration workflows
- ✅ Real-time synchronization and conflict resolution
- ✅ Performance under load
- ✅ Data consistency and integrity
The test suite validates that the system properly handles complex collaborative scenarios and maintains consistency across all operations.