HocusPocus Architecture
Overview
The HocusPocus server is the backbone of the collaborative editing for notebook. It provides real-time collaboration capabilities with a multi-layered data persistence strategy to ensure zero data loss during document editing.
The architecture is designed to handle:
- Multiple simultaneous connections
- Real-time document updates
- Graceful disconnections
- Version management
- System shutdowns
All while ensuring zero data loss during collaborative editing sessions.
Key Components
Core Components
- Hocuspocus Server: Central websocket server handling collaborative editing
- YJS Document Store: In-memory document representation
- Document Persistence Layers:
- Immediate operation journaling
- Redis for quick access caching (1-second debounce)
- Database for long-term persistence
- Periodic forced saves
Connection Lifecycle
Authentication Flow
Client HocusPocus Server Database
| | |
| --- Connect + JWT ------> | |
| | --- Verify JWT -----------> |
| | <-- User Info ------------- |
| | --- Track Activity -------> |
| <-- Auth Success -------- | |
| | |
Connection Handling
1. Authentication
The server authenticates users through JWT tokens: