Real-Time Collaborative Design Tool - A modern multiplayer canvas application with AI-powered design assistance built with React, Firebase, and Konva.js
- Overview
- Features
- Tech Stack
- Quick Start
- Installation
- Development
- Architecture
- AI Agent Features
- Deployment
- Troubleshooting
- Contributing
- License
CollabCanvas is a real-time collaborative design tool that allows multiple users to create, edit, and interact with shapes on a shared canvas. Built with modern web technologies, it provides smooth multiplayer experiences with instant synchronization across all connected users, enhanced with AI-powered design assistance.
- π₯ Real-time Sync - Multiple users work simultaneously with <100ms sync latency
- π₯ Multiplayer Cursors - See where other users are working with colorblind-friendly colors
- π Smart Locking - Prevent conflicts with automatic shape locking using Firestore transactions
- π Presence Awareness - See who's online and what they're editing in real-time
- π¨ Interactive Shapes - Create rectangles, circles, and triangles with customizable colors
- π Christmas Textures - Apply festive textures with Santa's Magic button
- π― Multi-Select - Select and move multiple shapes together (Shift+Click or drag-select)
- π Boundary Constraints - Shapes stay within canvas bounds during drag and resize
- π Optimistic Updates - Instant UI feedback with background Firebase synchronization
- β¨οΈ Keyboard Shortcuts - Power-user features for efficient workflow
- π€ AI Design Assistant - Natural language commands to create and manipulate shapes
- π¬ Intelligent Chat - LangChain-powered agent with ReAct reasoning
- π Web Search - Agent can research design patterns and best practices via Tavily
- π¨ Complex Layouts - Create login forms, navigation bars, and UI components with simple commands
- βΏ Accessibility - Colorblind-friendly palette for user cursors
- π οΈ Admin Tools - Create random shapes for testing, clear locks, and manage canvas
- π Performance Monitor - Real-time FPS and performance metrics
- π§ Debug Tools - Browser console commands for testing and debugging
- React 18 - Modern UI with hooks and functional components
- TypeScript - Type-safe development
- Vite - Lightning-fast development and optimized builds
- Konva.js + React-Konva - High-performance 2D canvas graphics
- Tailwind CSS - Utility-first styling for responsive UI
- Firebase Authentication - Secure user authentication
- Firestore - Real-time NoSQL database for shapes and persistent data
- Realtime Database - Ultra-fast presence and cursor tracking
- Vercel Functions - Serverless API for secure AI integration
- LangChain - AI agent framework with ReAct pattern
- OpenAI GPT-4 - Natural language understanding and generation
- Tavily API - Web search integration for contextual design assistance
- Zustand - Lightweight, performant state management
Get up and running in 5 minutes:
# 1. Clone the repository
git clone https://github.com/amanyrath/collabcanvas-fresh.git
cd collabcanvas-fresh
# 2. Install dependencies
npm install
# 3. Copy environment template
cp env.example .env
# 4. Start Firebase emulators (in one terminal)
firebase emulators:start
# 5. Start dev server (in another terminal)
npm run dev
# 6. Open http://localhost:5173 in your browserThat's it! You're now running CollabCanvas locally with Firebase emulators.
Before you begin, ensure you have the following installed:
- Node.js 18.x or higher (Download)
- npm (comes with Node.js)
- Firebase CLI (optional, for emulators)
npm install -g firebase-tools
git clone https://github.com/amanyrath/collabcanvas-fresh.git
cd collabcanvas-freshnpm installThis will install all required packages including:
- React and related libraries
- Firebase SDK
- Konva.js for canvas rendering
- LangChain and AI dependencies
- Development tools
Create a .env file in the project root:
cp env.example .envFor local development without Firebase costs:
# Firebase Configuration
VITE_FIREBASE_API_KEY=demo-api-key
VITE_FIREBASE_AUTH_DOMAIN=demo-project.firebaseapp.com
VITE_FIREBASE_PROJECT_ID=demo-project
VITE_FIREBASE_STORAGE_BUCKET=demo-project.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID=123456789
VITE_FIREBASE_APP_ID=1:123456789:web:abcdef
VITE_FIREBASE_DATABASE_URL=http://localhost:9000/?ns=demo-project
# Use emulators
VITE_USE_EMULATOR=true
# AI Features (optional for basic canvas features)
VITE_USE_BACKEND_API=false
VITE_OPENAI_API_KEY=your_openai_api_key_here
VITE_TAVILY_API_KEY=your_tavily_api_key_hereFor production deployment or testing with real Firebase:
# Firebase Configuration (get these from Firebase Console)
VITE_FIREBASE_API_KEY=your-api-key
VITE_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
VITE_FIREBASE_PROJECT_ID=your-project-id
VITE_FIREBASE_STORAGE_BUCKET=your-project.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID=your-sender-id
VITE_FIREBASE_APP_ID=your-app-id
VITE_FIREBASE_DATABASE_URL=https://your-project-default-rtdb.firebaseio.com
# Disable emulators
VITE_USE_EMULATOR=false
# For production, use backend API
VITE_USE_BACKEND_API=trueπ Security Note: Never commit your
.envfile. API keys prefixed withVITE_are exposed to the browser. For production, use serverless functions to keep AI API keys secure.
If using emulators, start them in a separate terminal:
firebase emulators:startThe Firebase Emulator UI will be available at http://localhost:4000
Services running:
- Authentication: localhost:9099
- Firestore: localhost:8080
- Realtime Database: localhost:9000
In a new terminal window:
npm run devThe application will start at http://localhost:5173
- Open http://localhost:5173 in your browser
- Click "Register" or "Sign Up"
- Create a test account with any email/password
- Start collaborating!
To test real-time collaboration, open the app in multiple browsers:
Method 1: Different Browsers
Chrome β http://localhost:5173 (User A)
Firefox β http://localhost:5173 (User B)
Safari β http://localhost:5173 (User C)
Method 2: Incognito Windows
Regular Chrome β User A
Chrome Incognito (β+Shift+N / Ctrl+Shift+N) β User B
Another Chrome Incognito β User C
Method 3: Browser Profiles
Create separate Chrome profiles for each test user
| Command | Description |
|---|---|
npm run dev |
Start Vite development server at http://localhost:5173 |
npm run build |
Build optimized production bundle |
npm run preview |
Preview production build locally |
npm run lint |
Run ESLint to check code quality |
firebase emulators:start |
Start Firebase emulators (separate terminal) |
collabcanvas-fresh/
βββ src/
β βββ agent/ # AI agent implementation
β β βββ executor.ts # Command executor
β β βββ llm.ts # LangChain LLM setup
β β βββ prompts/ # System prompts
β β βββ tools/ # LangChain tools
β βββ api/ # API integration
β β βββ agentApi.ts # Vercel function API client
β βββ components/
β β βββ Auth/ # Authentication components
β β βββ Canvas/ # Canvas, shapes, cursors, presence
β β βββ Chat/ # AI chat interface
β β βββ Comments/ # Commenting system
β β βββ Debug/ # Performance monitoring
β β βββ Layout/ # Navbar and layout
β βββ constants/ # Texture manifests and constants
β βββ hooks/ # Custom React hooks
β β βββ useAuth.ts # Authentication hook
β β βββ useShapeSync.ts # Shape synchronization
β β βββ useAgent.ts # AI agent hook
β β βββ ... # Other hooks
β βββ store/ # Zustand state management
β β βββ canvasStore.ts # Canvas state
β β βββ userStore.ts # User state
β βββ utils/ # Utility functions
β β βββ firebase.ts # Firebase initialization
β β βββ shapeUtils.ts # Shape CRUD operations
β β βββ lockUtils.ts # Lock management
β β βββ presenceUtils.ts# Presence tracking
β β βββ ... # Other utilities
β βββ App.tsx # Main application component
β βββ main.tsx # Application entry point
βββ api/ # Vercel serverless functions
β βββ agent/
β βββ chat.ts # AI agent API endpoint
βββ public/
β βββ textures/ # Christmas texture assets
βββ scripts/ # Development scripts
β βββ test-agent-setup.js # Verify AI agent setup
β βββ test-llm.js # Test LLM connection
β βββ validate-build.js # Build security validation
βββ ai-process/ # Development documentation
βββ ARCHITECTURE.md # Detailed architecture guide
βββ CONTRIBUTING.md # Contribution guidelines
βββ firebase.json # Firebase configuration
βββ firestore.rules # Firestore security rules
βββ database.rules.json # Realtime Database rules
βββ vercel.json # Vercel deployment config
-
Feature Development
# Create a feature branch git checkout -b feature/your-feature-name # Make changes # Test locally with emulators npm run dev # Lint your code npm run lint # Build to check for issues npm run build
-
Testing
- Test with Firebase emulators first
- Open multiple browsers to test collaboration
- Use the Debug panel to monitor performance
- Check browser console for errors
-
Code Quality
- Follow TypeScript best practices
- Use ESLint to catch issues
- Keep components small and focused
- Add comments for complex logic
Admin Panel (π οΈ button in navbar):
- Create random shapes for stress testing
- Clear all locks if shapes are stuck
- Delete all shapes to reset canvas
Browser Console Commands (Dev mode):
clearAllLocks() // Clear stuck locks
clearAllShapes() // Delete all shapes
getPerformanceStats() // View FPS and metricsCollabCanvas uses a lock-based collaboration model where selection equals locking. This prevents race conditions and ensures data consistency across multiple users.
- Optimistic Updates: UI updates instantly, Firebase syncs in background
- Two-Database Strategy:
- Firestore for persistent data (shapes, comments)
- Realtime Database for transient data (cursors, presence)
- Virtual Group Multi-Select: Shapes move together without actual Konva Groups
- Presence-Based Lock Cleanup: Auto-release locks when users disconnect
- ReAct Agent Pattern: AI agent uses reasoning and action cycles
| Component | Purpose |
|---|---|
Canvas.tsx |
Main canvas, tool selection, keyboard shortcuts, zoom/pan |
ShapeLayer.tsx |
Shape rendering, selection, dragging, resizing (most complex!) |
SimpleCursorLayer.tsx |
Real-time multiplayer cursors |
FastPresenceSidebar.tsx |
Online users list with status indicators |
AgentChat.tsx |
AI chat interface with LangChain integration |
Navbar.tsx |
User info, admin tools, logout with presence cleanup |
Zustand Stores:
canvasStore: Shapes, selection, optimistic updatesuserStore: Authentication, user profile, cursor color
Key Utils:
shapeUtils.ts: CRUD operations for shapes (Firestore)lockUtils.ts: Lock management with Firestore transactionspresenceUtils.ts: Real-time presence (RTDB)firebase.ts: Firebase initialization and emulator config
For detailed architecture documentation, see ARCHITECTURE.md
CollabCanvas includes an AI-powered design assistant built with LangChain.
The AI agent can understand natural language commands like:
Creation Commands:
- "Create a red circle at 200, 300"
- "Make a blue rectangle 150x200 at 500, 400"
- "Create 10 random colored shapes"
- "Build a login form"
- "Design a navigation bar with 4 menu items"
Manipulation Commands:
- "Move the selected shape to 600, 700"
- "Make it twice as big"
- "Change the color to green"
- "Delete that shape"
- "Arrange all shapes horizontally"
Complex Commands:
- "Create a card layout with title and button"
- "Design a Christmas tree"
- "Build a color palette with 5 colors"
-
Get API Keys
- OpenAI API Key: https://platform.openai.com/api-keys
- Tavily API Key: https://tavily.com/ (for web search)
-
Configure Environment
VITE_OPENAI_API_KEY=sk-... VITE_TAVILY_API_KEY=tvly-... VITE_USE_BACKEND_API=false
-
Test Setup
node scripts/test-agent-setup.js
-
Use AI Chat
- Open the chat panel in the app
- Type natural language commands
- Watch the AI create and manipulate shapes!
π Production: For production deployments, set
VITE_USE_BACKEND_API=trueand configure serverless functions to keep API keys secure.
For detailed AI documentation, see src/agent/README.md
Vercel provides the best experience with zero-config deployment and serverless functions for AI features.
Quick Deploy:
-
Push to GitHub
git push origin main
-
Connect to Vercel
- Go to vercel.com
- Import your GitHub repository
- Vercel auto-detects Vite configuration
-
Configure Environment Variables
Add these in Vercel Dashboard β Settings β Environment Variables:
VITE_USE_EMULATOR=false VITE_FIREBASE_API_KEY=your-api-key VITE_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com VITE_FIREBASE_PROJECT_ID=your-project-id VITE_FIREBASE_STORAGE_BUCKET=your-project.appspot.com VITE_FIREBASE_MESSAGING_SENDER_ID=your-sender-id VITE_FIREBASE_APP_ID=your-app-id VITE_FIREBASE_DATABASE_URL=https://your-project-default-rtdb.firebaseio.com # For AI features VITE_USE_BACKEND_API=true OPENAI_API_KEY=sk-... TAVILY_API_KEY=tvly-... -
Deploy
- Click "Deploy"
- Vercel builds and deploys automatically
- Get your production URL!
Automatic Deployments:
- Every push to
mainβ Production deployment - Every PR β Preview deployment
For detailed deployment guide, see VERCEL_DEPLOYMENT.md
# Build the app
npm run build
# Deploy to Firebase
firebase deploy --only hosting# Build command: npm run build
# Publish directory: dist
# Add same environment variables as VercelSymptom: Blank screen or loading indefinitely
Solution:
- Check browser console for errors
- Verify
.envfile exists and has correct values - If using emulators, ensure they're running:
firebase emulators:start
- Clear browser cache and hard reload (Ctrl+Shift+R)
Symptom: User A creates shape, User B doesn't see it
Solution:
- Check Firestore emulator connection at http://localhost:4000
- Look for
ERR_CONNECTION_RESETin console - Ensure emulators use
127.0.0.1notlocalhostin connection strings - Verify Firestore rules allow reads/writes
Symptom: Can't see other users' cursors
Solution:
- Check Realtime Database connection
- Verify RTDB rules allow reads
- Check presence data in Firebase console
- Ensure
VITE_FIREBASE_DATABASE_URLis correct
Symptom: Shape locked but user is offline
Solution:
- Use Admin Panel β Clear All Locks
- Wait for automatic cleanup on disconnect
- Check
usePresenceMonitoris running
Symptom: AI chat doesn't respond to commands
Solution:
- Verify API keys are set in
.env - Run:
node scripts/test-agent-setup.js - Check OpenAI billing and quota
- Look for error messages in browser console
- Ensure network connectivity
Symptom: npm run build fails
Solution:
- Check for TypeScript errors:
npx tsc --noEmit - Run linter:
npm run lint - Clear node_modules and reinstall:
rm -rf node_modules package-lock.json npm install
Symptom: Slow rendering or laggy interactions
Solution:
- Check Performance Display (top-right corner)
- Limit shapes on canvas (admin tools)
- Reduce number of concurrent users
- Check browser console for warnings
- Close other tabs and applications
For more troubleshooting, see ARCHITECTURE.md or open an issue on GitHub.
We welcome contributions! Please see CONTRIBUTING.md for detailed guidelines.
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature
- Make your changes
- Follow existing code style
- Add comments for complex logic
- Test thoroughly
- Commit your changes
git commit -m 'Add amazing feature' - Push to your fork
git push origin feature/amazing-feature
- Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- React - UI framework
- Konva.js - High-performance 2D canvas library
- Firebase - Backend and real-time infrastructure
- LangChain - AI agent framework
- OpenAI - GPT-4 language model
- Zustand - Lightweight state management
- Tailwind CSS - Utility-first styling
- Vite - Lightning-fast build tool
- TypeScript - Type safety
- Figma - Multiplayer interactions and UX patterns
- Excalidraw - Collaborative whiteboard simplicity
- tldraw - Canvas performance optimizations
- Built with assistance from Claude (Anthropic)
- Documentation-first approach throughout development
- Iterative refinement based on real-world testing
- Paul Tol for colorblind-friendly color schemes
- Firebase team for excellent real-time infrastructure
- Konva.js community for canvas rendering solutions
- LangChain team for AI agent framework
Documentation:
- π ARCHITECTURE.md - Technical deep dive
- π CONTRIBUTING.md - How to contribute
- π€ AI Agent Guide - AI features documentation
- π Development Docs - Process documentation
Repository:
- π GitHub
- π Report Issues
- π‘ Feature Requests
Connect:
- πΌ LinkedIn