Skip to content

A proof-of-concept study exploring real-time collaborative document editing systems built with event sourcing architecture.

Notifications You must be signed in to change notification settings

shug0/poc-collaborative-edit-study

Repository files navigation

Collaborative POC Study

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.

Study Focus Areas

📝 Block-Based Document System

  • 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

🔒 Conflict Resolution System

  • 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

✏️ Real-Time Draft System

  • 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

👥 Multi-User Collaboration

  • 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

⚡ Event Sourcing Architecture

  • 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

Test Coverage

The system includes comprehensive tests covering all major functionality:

🏗️ Core System Tests (core-system.test.ts)

  • 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

👥 Multi-User Collaboration Tests (multi-user-collaboration.test.ts)

  • 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

🚀 Real-Time Sync Tests (real-time-sync-*.test.ts)

  • 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

Technical Architecture

Core Implementation

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 Infrastructure

test/
├── test-helpers.ts         # Shared testing utilities
├── setup.ts               # Test configuration
└── *.test.ts              # Comprehensive test suites

Legacy Components (Moved to app/legacy/)

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.

Key Implementation Details

Event Sourcing Pattern

  • 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

Lock-Based Conflict Resolution

  • 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

Real-Time Draft System

  • 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

Getting Started

# 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 check

Purpose

This 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

Test Results

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.

About

A proof-of-concept study exploring real-time collaborative document editing systems built with event sourcing architecture.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published