CollabDraw Documentation

Explore the technical architecture and implementation details of a real-time collaborative whiteboard application.

System Architecture

CollabDraw System Architecture

The system follows a monorepo architecture with two apps — a Next.js 15 frontend handling UI, authentication and API routes, and a standalone WebSocket server for real-time canvas collaboration. Both apps share a PostgreSQL database via Prisma ORM, and communicate through WebSocket connections for live drawing synchronization.

Core Components & Implementation

Monorepo Structure

Built with Turborepo + pnpm workspaces for efficient monorepo management.

Apps

apps/web:3000

Next.js 15 frontend + API routes

apps/ws-backend:8080

WebSocket server for real-time collab

Shared Packages

@repo/prisma

Prisma client, schema & migrations

@repo/zod

Shared Zod validation schemas

@repo/typescript-config

Shared TypeScript configs

@repo/eslint-config

Shared ESLint configs

@repo/ui

Shared UI components

API Endpoints

MethodRouteAuthDescription
POST/api/signupNoCreate a new user
POST/api/signinNoAuthenticate and get JWT token
POST/api/roomYesCreate or join a room by slug
GET/api/room?slug=<code>YesGet room details
GET/api/healthNoHealth check
GET/api/pingNoPing WebSocket server status

Drawing Tools & Shortcuts

SelectV / 1
Hand (pan)H / 2
RectangleR / 3
DiamondD / 4
EllipseO / 5
ArrowA / 6
LineL / 7
Pencil (freehand)P / 8
TextT / 9
EraserE / 0

Actions

UndoCtrl+Z
RedoCtrl+Shift+Z
Select AllCtrl+A
DeleteDelete
Zoom InCtrl++
Zoom OutCtrl+-
Reset ZoomCtrl+0
DuplicateAlt+Drag

Tech Stack

LayerTechnology
MonorepoTurborepo + pnpm workspaces
FrontendNext.js 15 (App Router), React 19, Tailwind CSS
UI ComponentsRadix UI, Lucide icons, shadcn/ui
CanvasRaw HTML5 Canvas 2D API
WebSocket ServerNode.js ws library
DatabasePostgreSQL 16
ORMPrisma 7
AuthJWT (jsonwebtoken)
ValidationZod
ContainerizationDocker + Docker Compose

Getting Started

Prerequisites: Node.js v20+, pnpm, Docker & Docker Compose

1. Clone the repository

bash
git clone https://github.com/your-username/collaborative-board.git
cd collaborative-board

2. Install dependencies

bash
pnpm install

3. Set up environment variables

Create a .env file in the root:

.env
DATABASE_URL="postgresql://user:password@localhost:5432/db"
SECRET_KEY="your-secret-key"
NODE_ENV=development
WEBSOCKET_PORT=8080
NEXT_PUBLIC_HTTP_BACKEND_URL=http://localhost:3001
NEXT_PUBLIC_WS_URL=ws://localhost:8080

4. Start the database

bash
docker compose up -d

5. Run database migrations

bash
pnpm --filter @repo/prisma db:push

6. Generate Prisma client

bash
pnpm --filter @repo/prisma build

7. Start development servers

bash
pnpm dev

This starts both the Next.js app (port 3000) and the WebSocket server (port 8080).

Docker Deployment

Use the provided Makefile for containerized deployment:

CommandDescription
make startBuild images and start all services
make buildBuild both frontend and backend Docker images
make build-webBuild frontend image only
make build-backendBuild backend image only
make runStart database, run migrations, launch containers
make stopStop and remove all containers
make cleanRemove containers, images, and network
make helpShow all available commands

Services after make start

Frontend

http://localhost:3000

WebSocket

ws://localhost:8080

PostgreSQL

localhost:5432