A real-time collaborative document editor built with Ruby on Rails, TipTap 3.x, and Hocuspocus. Features live multi-user editing, comments with @mentions, version history, and Markdown support.
- Real-time Collaboration: Multiple users can edit documents simultaneously with live cursor tracking
- Rich Text Editing: Full formatting support with TipTap 3.x - bold, italic, headings, lists, links, code blocks
- Comments System:
- Add comments to selected text
- @mention users in comments
- Resolve, reopen, and delete comments
- Toggle comments panel visibility
- Markdown Support:
- Paste Markdown that auto-formats in the editor
- Export content as Markdown
- Full syntax highlighting for code blocks
- Version History: Track and restore document changes
- AI Text Improvements: Enhance, simplify, fix grammar, and more (mock implementation, ready for AI integration)
- Modern UI: Clean interface with Tailwind CSS, bubble menus, and floating toolbars
- Ruby on Rails 7.x (API mode)
- PostgreSQL - Database for documents, users, and comments
- Action Cable - WebSocket support
- RESTful API - Clean API design
- React 18 with Vite
- TipTap 3.x - Headless rich text editor
- Yjs - CRDT for conflict-free collaboration
- Hocuspocus Provider - WebSocket collaboration client
- Tailwind CSS - Utility-first styling
- tiptap-markdown - Markdown support
- Hocuspocus - WebSocket server for real-time sync
- Node.js - Server runtime
- Yjs - Document synchronization
- Docker and Docker Compose installed
- That's it! π
- Ruby 3.x
- Rails 7.x
- Node.js 18.x or higher
- PostgreSQL 14.x or higher
# Clone the repository
git clone https://github.com/yourusername/tiptap-rails-collab.git
cd tiptap-rails-collab
# Start all services with Docker Compose
docker compose up --build
# That's it! π
After containers are running:
- Frontend: http://localhost:3002
- Rails API: http://localhost:3000
- Hocuspocus WebSocket: ws://localhost:1234
- PostgreSQL: localhost:5432
- Redis: localhost:6379
# In a new terminal, run migrations and seed data
docker-compose exec rails rails db:create
docker-compose exec rails rails db:migrate
docker-compose exec rails rails db:seed
Click to expand manual setup instructions
git clone https://github.com/yourusername/tiptap-rails-collab.git
cd tiptap-rails-collab
# Install Ruby dependencies
bundle install
# Setup database
rails db:create
rails db:migrate
rails db:seed # Creates 25 test users and sample documents
# Start Rails server
rails server
# API runs on http://localhost:3000
cd hocuspocus-server
# Install dependencies
npm install
# Start the collaboration server
npm start
# WebSocket server runs on ws://localhost:1234
cd frontend
# Install dependencies
npm install
# Start development server
npm run start
# Frontend runs on http://localhost:3002 (or 3003 if port is taken)
The docker-compose.yml
file includes:
Service | Port | Description |
---|---|---|
rails | 3000 | Rails API backend |
frontend | 3002 | React application |
hocuspocus | 1234 | WebSocket collaboration server |
postgres | 5432 | PostgreSQL database |
redis | 6379 | Redis cache (for ActionCable) |
tiptap-rails-collab/
βββ app/ # Rails backend
β βββ controllers/
β β βββ api/v1/
β β βββ documents_controller.rb # Document CRUD
β β βββ comments_controller.rb # Comment management
β β βββ users_controller.rb # User search for @mentions
β βββ models/
β βββ document.rb # Document model
β βββ comment.rb # Comment model
β βββ user.rb # User model
βββ frontend/ # React frontend
β βββ src/
β β βββ components/
β β β βββ CollabEditor-v3.jsx # Main editor (TipTap 3.x)
β β β βββ DocumentList.jsx # Document sidebar
β β β βββ ChangeHistory.jsx # Version history
β β βββ services/
β β βββ documentService.js # Document API
β β βββ commentService.js # Comment API
β β βββ aiService.js # AI text improvements
β βββ package.json
β βββ vite.config.js
βββ hocuspocus-server/ # Collaboration server
β βββ server.js # WebSocket server setup
β βββ package.json
βββ db/
β βββ migrate/ # Database migrations
β βββ seeds.rb # Sample data
βββ docker-compose.yml # Docker services orchestration
βββ Dockerfile.rails # Rails container definition
βββ config/
βββ routes.rb # API routes
GET /api/v1/documents # List all documents
GET /api/v1/documents/:id # Get single document
POST /api/v1/documents # Create document
PATCH /api/v1/documents/:id # Update document
DELETE /api/v1/documents/:id # Delete document
GET /api/v1/documents/:document_id/comments # List comments
POST /api/v1/documents/:document_id/comments # Create comment
PATCH /api/v1/documents/:doc_id/comments/:id # Update (resolve/reopen)
DELETE /api/v1/documents/:doc_id/comments/:id # Delete comment
GET /api/v1/users # List all users
GET /api/v1/users/search?q= # Search users for @mentions
- Select a document from the sidebar or create a new one
- Use the toolbar for formatting (Bold, Italic, Headings, Lists)
- Select text to see the bubble menu with quick formatting options
- Open the same document in multiple browser tabs/windows
- You'll see live cursors of other users
- Changes sync instantly across all clients
- User names appear on their cursors
- Select any text in the editor
- Click "Add Comment" in the bubble menu
- Type your comment (use @ to mention users)
- Comments appear in the right panel
- Toggle panel visibility with the "Comments" button
- Resolve, reopen, or delete comments as needed
- Paste Markdown: Copy any Markdown text and paste - it auto-formats
- Test Markdown: Click "Test Markdown" button to see sample formatting
- Export: Click "Get as Markdown" to export current content
- Click "Show History" to see document versions
- View changes with timestamps
- Restore previous versions if needed
# View logs for all services
docker-compose logs -f
# View logs for specific service
docker-compose logs -f rails
docker-compose logs -f frontend
# Access Rails console
docker-compose exec rails rails console
# Run Rails migrations
docker-compose exec rails rails db:migrate
# Access bash shell in container
docker-compose exec rails bash
docker-compose exec frontend sh
# Rebuild specific service
docker-compose build rails
docker-compose build frontend
# Stop all services
docker-compose down
# Stop and remove volumes (full reset)
docker-compose down -v
# Rails tests
docker-compose exec rails rails test
# Frontend tests
docker-compose exec frontend npm test
# Rails tests
rails test
# Frontend tests
cd frontend && npm test
# With Docker
docker-compose -f docker-compose.production.yml build
docker-compose -f docker-compose.production.yml up
# Without Docker
RAILS_ENV=production rails assets:precompile
RAILS_ENV=production rails db:migrate
cd frontend && npm run build
- New API endpoint: Add controller in
app/controllers/api/v1/
- New editor feature: Modify
frontend/src/components/CollabEditor-v3.jsx
- New TipTap extension: Add to extensions array in editor setup
- Collaboration logic: Update
hocuspocus-server/server.js
- After changes: Rebuild containers with
docker-compose build
- Container won't start
# Check logs
docker-compose logs rails
docker-compose logs frontend
# Rebuild from scratch
docker-compose down -v
docker-compose build --no-cache
docker-compose up
- Port conflicts with Docker
# Check what's using the port
lsof -i :3000
lsof -i :3002
lsof -i :1234
# Change ports in docker-compose.yml if needed
- Database connection errors in Docker
# Ensure postgres is running
docker-compose ps postgres
# Reset database
docker-compose exec rails rails db:drop
docker-compose exec rails rails db:create
docker-compose exec rails rails db:migrate
docker-compose exec rails rails db:seed
- Vite "Outdated Optimize Dep" errors
cd frontend
rm -rf node_modules/.vite
npm run start
- Port already in use (local dev)
# Kill process on port 3000
lsof -ti:3000 | xargs kill -9
# Frontend auto-tries ports 3002, 3003
- WebSocket connection failed
- Check Hocuspocus server is running on port 1234
- Verify no firewall blocking WebSocket connections
- Check browser console for specific errors
- With Docker: ensure all containers are running
- Database connection issues (local)
# Reset database
rails db:drop
rails db:create
rails db:migrate
rails db:seed
- Missing @mention users
# With Docker
docker-compose exec rails rails db:seed
# Without Docker
rails db:seed
- Check browser console for JavaScript errors
- Check Rails logs for API errors:
tail -f log/development.log
- Check Hocuspocus logs in the terminal running the server
- Verify services are running on correct ports
Create .env
files:
Backend (.env)
DATABASE_URL=postgresql://localhost/tiptap_collab_dev
RAILS_ENV=development
SECRET_KEY_BASE=your-secret-key
Frontend (frontend/.env)
VITE_API_URL=http://localhost:3000
VITE_WS_URL=ws://localhost:1234
- Styling: Modify Tailwind classes in components
- Editor toolbar: Edit toolbar buttons in
CollabEditor-v3.jsx
- TipTap extensions: Add/remove in extensions array
- AI features: Implement real AI in
aiService.js
- Uses
CollaborationCaret
instead ofCollaborationCursor
- Imports from
@tiptap/extensions
for consolidated extensions - Named imports for Color, TextStyle, FontFamily
- Yjs documents for CRDT-based sync
- Hocuspocus provider manages WebSocket connection
- Each document has unique collaboration session
- Conflict-free merging of concurrent edits
- Comments linked to text positions
- Preserved through collaborative edits
- Rich text support with @mentions
- Separate active/resolved states
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit changes (
git commit -m 'Add some AmazingFeature'
) - Push to branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- TipTap - Incredible headless editor framework
- Hocuspocus - Plug & play collaboration backend
- Yjs - CRDT framework powering real-time sync
- Rails - The web framework that doesn't hurt
- Tailwind CSS - For rapid UI development
For issues, questions, or suggestions:
- Open an issue on GitHub
- Check existing issues for solutions
- Include browser console logs and error messages when reporting bugs