How coderomm/collabydraw works
Project Overview & Purpose
• CollabyDraw is a web-based collaborative whiteboard application with a focus on real-time, encrypted drawing sessions.
• The system is split into multiple concerns including a Next.js frontend application (with its own canvas engine and UI components), a dedicated WebSocket server for real-time syncing, and a database layer (managed via Prisma) for persistence and authentication state.
Main Components
a. Client/Frontend Application:
• This is implemented in the CollabyDraw app under apps/collabydraw.
• It utilizes a modern React-based framework (Next.js) with TypeScript, Tailwind CSS, and a custom canvas engine.
• The “app” directory is organized into layouts (auth, main), API routes (for authentication via NextAuth), and UI components (drawing tools, sidebars, menus, etc.).
• Additional client-side libraries such as Rough.js and Perfect-freehand for sketch effects.
b. Canvas Engine:
• It is crucial to highlight that the canvas engine supports encryption and decryption routines on the client side – the encryption key is parsed from a URL fragment and is never sent to the server.
c. Realtime WebSocket Service:
• Located in apps/ws, this service powers the live collaboration aspect.
• It handles real-time bi-directional communication with the frontend, routing drawing data over WebSocket.
• It integrates with the application’s message queuing mechanism for auto retry on connection issues.
d. Backend API Endpoints:
• Exposed through Next.js API routes (e.g., apps/collabydraw/app/api/auth/[...nextauth]) to manage authentication and possibly session management.
• This layer is distinct from the WebSocket service and provides security and auth validation.
e. Database/Prisma Layer:
• Managed in the packages/db folder built with Prisma, it includes the schema and migrations.
• This service is responsible for storing room details, authentication data (if applicable), and other persistence-related configurations.
f. Shared Libraries & Configurations:
• Packages like packages/common, packages/ui, and others denote shared utilities, UI components, and configuration (ESLint, TypeScript) that help maintain consistency across the monorepo.
Relationships & Interactions
• The user’s actions on the frontend (drawing, editing, authentication) trigger processes in the Client Application.
• The Canvas Engine (client-side) handles rendering and encryption/decryption tasks locally.
• API calls for authentication and user management flow between the frontend’s API routes and external auth services.
• Backend communication with the Database is done via Prisma – this may include storing room sessions or user events.
Architectural Patterns & Design Principles
• The overall architecture follows a modular, microservices-like pattern with separate concerns:
• A full-stack Next.js client for UI and API endpoints.
• A distinct WebSocket server for real-time communication.
• A dedicated, managed database using Prisma.
• “privacy by design” where encryption logic is solely client-side.