A modern monorepo containing a real-time collaborative drawing application with Next.js frontend, WebSocket backend, and PostgreSQL database# .
-
draw_app_frontend: Next.js 16 frontend - Main drawing application- Real-time canvas with WebSocket integration
- User authentication (sign-in/sign-up) with form validation
- Room-based collaboration system
- Multiple drawing tools (pencil, circle, rectangle)
- Responsive design with Tailwind CSS
-
http-backend: REST API backend - Handles shape persistence and data storage- Express.js server with TypeScript
- Prisma ORM for database operations
- Shape data persistence and retrieval
- User authentication endpoints
-
ws-backend: WebSocket backend - Manages real-time collaboration- WebSocket server for real-time communication
- Broadcasting drawing events to connected clients
- Room management and connection handling
-
web: Next.js app - Secondary frontend application- Additional UI components and pages
- Chat room functionality
- Socket-based real-time messaging
-
@repo/ui: React component library with reusable UI components- Button, Card, Code components
- Tailwind CSS styling
- TypeScript definitions
-
@repo/common: Shared TypeScript types and utilities- Shape type definitions
- Common interfaces and enums
-
@repo/db: Prisma database client and schemas- PostgreSQL database schema
- User and shape data models
- Database migrations
-
@repo/eslint-config: ESLint configurations- Next.js specific rules
- React best practices
- TypeScript linting
-
@repo/typescript-config: TypeScript configurations- Base TypeScript settings
- Next.js specific configs
- React library configurations
Each package/app is 100% TypeScript.
- Node.js 18+
- pnpm 9.0.0+
# Install all dependencies
pnpm install
# Start the draw app frontend (http://localhost:3000)
cd apps/draw_app_frontend
pnpm run devNote: The frontend requires backend services to be running for full functionality.
The app uses route-based rooms so users can join a shared canvas by room id.
- Frontend room URL:
http://localhost:3000/canvas/<roomId>- Example:
http://localhost:3000/canvas/123 - This loads the collaborative drawing canvas for room
123.
- Example:
- Backend chat/history endpoint:
http://localhost:3008/chats/<roomId>- Example:
http://localhost:3008/chats/123 - This endpoint returns saved drawing/chat data for the same room.
- Example:
- Draw App Frontend README - Complete guide for the drawing application
- TODO.md - Current tasks and known issues
This monorepo has the following tools configured:
- TypeScript - Static type checking
- ESLint - Code linting
- Prettier - Code formatting
- Turbo - Build system and task runner
- Prisma - Database ORM
Draw_App (Monorepo)
βββ apps/
β βββ draw_app_frontend/ # Main drawing app (Next.js)
β β βββ app/ # Next.js App Router
β β β βββ page.tsx # Landing page with hero section
β β β βββ signin/ # Authentication pages
β β β βββ signup/
β β β βββ canvas/[roomId]/ # Dynamic drawing rooms
β β βββ components/ # React components
β β β βββ AuthPage.tsx # Sign-in/sign-up forms
β β β βββ Canvas.tsx # Canvas wrapper component
β β β βββ IconButton.tsx # Reusable icon buttons
β β βββ draw/ # Drawing engine
β β β βββ Game.ts # Canvas game logic
β β β βββ http.ts # API calls
β β β βββ index.ts # Drawing initialization
β β βββ config.ts # Backend URLs configuration
β βββ http-backend/ # REST API (Express + TypeScript)
β βββ ws-backend/ # WebSocket server
β βββ web/ # Secondary frontend
βββ packages/
β βββ ui/ # Shared UI components
β βββ common/ # Shared types
β βββ db/ # Prisma database client
β βββ eslint-config/ # ESLint rules
β βββ typescript-config/ # TypeScript configs
βββ turbo.json # Turbo configuration
- WebSocket Integration: Instant synchronization across all connected clients
- Room-based Collaboration: Multiple users can join the same drawing room
- Shape Broadcasting: Every drawn shape is immediately shared with room participants
- Persistent Storage: All drawings are saved to database and restored on room entry
- Pencil Tool: Freehand drawing with smooth curves
- Circle Tool: Perfect circles with click-and-drag
- Rectangle Tool: Precise rectangles with corner coordinates
- Tool Selection: Visual toolbar with active tool highlighting
- Responsive Design: Works on desktop and mobile devices
- Modern UI: Gradient backgrounds, smooth animations, professional styling
- Form Validation: Email format checking, password requirements, error feedback
- Loading States: Visual feedback during authentication and drawing operations
- Sign-in/Sign-up: Secure user registration and login
- Form Validation: Client-side validation with error messages
- Success Feedback: Clear confirmation of successful operations
- Navigation: Seamless links between auth pages
- User Interaction: Click/drag on canvas triggers drawing event
- Shape Creation: Game engine creates shape object with coordinates
- WebSocket Broadcast: Shape data sent to all connected clients in room
- Canvas Update: Each client receives and renders the new shape
- Database Persistence: Shape saved to PostgreSQL via REST API
- Form Submission: User enters credentials and submits form
- Client Validation: Email format and password requirements checked
- API Call: Credentials sent to HTTP backend for verification
- Token Handling: JWT tokens managed for session persistence
- Redirect: Successful auth redirects to drawing interface
- Users: User accounts with email and password
- Shapes: Drawing shapes with room association
- Rooms: Drawing rooms for collaboration sessions
type Shape =
| { type: "rect"; x: number; y: number; width: number; height: number }
| { type: "circle"; centerX: number; centerY: number; radius: number }
| {
type: "pencil";
startX: number;
startY: number;
endX: number;
endY: number;
};- Next.js 16: App Router for file-based routing
- React 19: Latest React with concurrent features
- TypeScript: Full type safety across the application
- Tailwind CSS: Utility-first styling with custom gradients
- Lucide Icons: Consistent iconography throughout UI
- HTTP Backend: Express.js with TypeScript for RESTful APIs
- WebSocket Backend: Real-time communication server
- Database: PostgreSQL with Prisma ORM
- Authentication: JWT-based user sessions
- Turbo: Fast build system with caching
- ESLint: Code quality and consistency
- Prettier: Automatic code formatting
- pnpm: Efficient package management
# 1. Install dependencies
pnpm install
# 2. Start database (if using local PostgreSQL)
# Configure connection in packages/db/
# 3. Start HTTP backend
cd apps/http-backend
pnpm run dev
# 4. Start WebSocket backend (new terminal)
cd apps/ws-backend
pnpm run dev
# 5. Start frontend
cd apps/draw_app_frontend
pnpm run dev- Frontend: Configure
HTTP_BACKENDandWS_URLinconfig.ts - Database: Set up PostgreSQL connection in Prisma config
- Environment Variables: Use
.envfiles for sensitive configuration
- Manual Testing: UI interaction and drawing functionality
- Integration Testing: WebSocket communication verification
- API Testing: REST endpoints for shape persistence
- Unit Tests: Component and utility function testing
- E2E Tests: Full user workflow automation
- Performance Tests: Canvas rendering and WebSocket throughput
- Canvas Rendering: Efficient shape drawing and redrawing
- WebSocket Efficiency: Minimal data transmission for shapes
- Bundle Size: Tree-shaking and code splitting
- Database Queries: Optimized Prisma queries for shape retrieval
- Real-time Sync: <100ms latency for shape broadcasting
- Canvas Rendering: Smooth 60fps drawing experience
- Bundle Size: Optimized Next.js build with Turbopack
- Password Requirements: Minimum 6 characters
- Email Validation: Proper email format checking
- Session Management: Secure token handling
- Input Sanitization: Client and server-side validation
- SQL Injection Prevention: Prisma ORM protection
- WebSocket Security: Connection authentication
- Canvas Sizing: Fixed dimensions, needs responsive handling
- WebSocket Lifecycle: Connection cleanup on component unmount
- Error Handling: Comprehensive error states and recovery
- Undo Functionality: Drawing history and undo/redo features
- Color Picker: Multiple drawing colors
- Shape Editing: Modify existing shapes
- User Cursors: Show other users' cursor positions
- Drawing History: Version control for drawings
- Export Features: Save drawings as images/PDF
- Languages: TypeScript (95%), JavaScript (5%)
- Lines of Code: ~2,000+ across all packages
- Components: 10+ React components
- API Endpoints: 5+ REST endpoints
- Database Tables: 3 core tables
- Monorepo: Shared packages reduce duplication
- Type Safety: TypeScript prevents runtime errors
- Real-time: WebSocket enables instant collaboration
- Scalable: Modular architecture supports growth
- Next.js: React framework for production
- Prisma: Database toolkit and ORM
- Express: Web application framework
- WebSocket: Real-time communication protocol
- Tailwind CSS: Utility-first CSS framework
- Turbo: Build system for monorepos
- ESLint: Code linting and formatting
- TypeScript: Static type checking
- pnpm: Fast package manager
This project demonstrates modern full-stack development with real-time features, showcasing the power of combining Next.js, WebSockets, and database persistence for collaborative applications.
pnpm run buildpnpm run devpnpm run lintpnpm run check-typespnpm run formatThis monorepo is currently focused on the Draw App (draw_app_frontend), a real-time collaborative drawing application. See the full Draw App documentation for detailed information about features, architecture, and usage.