How controlcoder/sketch-velvet works
Purpose and Entry Points
A full-stack collaborative drawing-board application: React client renders and edits a canvas; Node/Express server provides authentication, board persistence/sharing, and real-time board updates. Client bootstraps at client/src/main.tsx and routes through client/src/routes/AppRouter.tsx; server HTTP and socket startup are separated in server/src/server.ts and server/src/app.ts.
Client Application Shell and Access Control
Page-level flows cover landing, authentication, dashboard, and individual boards. Authentication state is centralized in client/src/context/AuthContext.tsx; route guards distinguish anonymous versus authenticated access in client/src/components/Routes/ProtectedRoute.tsx and client/src/components/Routes/PublicRoute.tsx. API clients are partitioned by concern in client/src/api/auth.api.ts and client/src/api/board.api.ts, sharing Axios setup in client/src/api/axios.ts.
Board Workspace and Canvas Rendering
client/src/pages/Board/Board.tsx composes the interactive workspace: canvas, toolbar, history, zoom, persistence, and collaboration hooks. The rendering boundary is client/src/components/Canvas/Canvas.tsx, with camera coordinate management in client/src/components/Canvas/Camera.ts and drawing orchestration in client/src/components/Canvas/Renderer.ts. Canvas elements are client-side drawing-model objects rather than DOM shapes.
Editing and Drawing Pipeline
Pointer/tool actions create or incrementally update drawable elements through client/src/tools/createElement.ts and client/src/tools/updateDrawingElement.ts, with tool implementations such as client/src/tools/drawRectangle.ts and client/src/tools/drawPencil.ts. Selection, hit testing, and resize behavior form a distinct manipulation layer under client/src/editing/selection/hitTest.ts, client/src/editing/resize/resizeElement.ts, and client/src/editing/move/moveElement.ts. This layer feeds the renderer and board state, while client/src/components/TextEditor/TextEditor.tsx handles text-specific input.
State History, Persistence, and Collaboration
Board changes are tracked for undo/redo by client/src/hooks/useHistory.ts and propagated via client/src/hooks/historyChange.ts. client/src/hooks/useAutosave.ts and client/src/hooks/useSavedElements.ts bridge in-memory elements to persisted board state. client/src/hooks/useBoardSocket.ts, backed by client/src/config/socket.ts, is the real-time synchronization boundary; it connects board editing events to the server socket namespace/handlers.
Server HTTP, Authorization, and Domain Services
Express routes divide auth and board operations in server/src/routes/auth.routes.ts and server/src/routes/board.routes.ts. Controllers are thin HTTP adapters (server/src/controllers/auth.controller.ts, server/src/controllers/board.controller.ts), delegating domain work to server/src/services/auth.service.ts, server/src/services/board.service.ts, and server/src/services/permission.service.ts. JWT authentication is enforced at the middleware boundary in server/src/middleware/auth.middleware.ts; centralized error handling is in server/src/middleware/error.middleware.ts.
Realtime and Data Infrastructure
Socket server setup and board-event handling reside in server/src/sockets/server.ts and server/src/sockets/board.socket.ts, with socket middleware/error adapters protecting the realtime boundary. Prisma is the persistence runtime, configured by server/src/config/prisma.ts and modeled in server/prisma/schema.prisma; migrations establish users, boards, memberships, and viewer permissions under server/prisma/migrations/. The material external interfaces are the browser Canvas API, HTTP/JSON API, Socket.IO-style realtime transport, JWTs, and the Prisma-supported database.
Components 21
React client
- Client bootstrap
client/src/main.tsx - App router
client/src/routes/AppRouter.tsx - Auth state
client/src/context/AuthContext.tsx - Route guards
client/src/components/Routes/ProtectedRoute.tsx - HTTP API clients · Auth and board clients share Axios setup.
client/src/api/axios.ts - Board workspace · Composes editing, history, persistence, and collaboration.
client/src/pages/Board/Board.tsx - Canvas renderer · Renders drawing-model elements through camera and renderer layers.
client/src/components/Canvas/Canvas.tsx - Drawing tools · Creates and incrementally updates drawable elements.
client/src/tools/createElement.ts - Manipulation layer · Handles hit testing, resize, and movement.
client/src/editing/selection/hitTest.ts - Text editor
client/src/components/TextEditor/TextEditor.tsx - History and autosave · Tracks undo/redo and saves in-memory elements.
client/src/hooks/useHistory.ts - Board socket client
client/src/hooks/useBoardSocket.ts
Node/Express server
- HTTP startup · Separates HTTP application construction from server startup.
server/src/server.ts - Express app
server/src/app.ts - Auth and board routes · Routes dispatch to thin auth and board controllers.
server/src/routes/board.routes.ts - JWT middleware
server/src/middleware/auth.middleware.ts - Domain services · Owns authentication, board operations, and sharing permissions.
server/src/services/board.service.ts - Socket board handlers · Socket setup and board event handling boundary.
server/src/sockets/board.socket.ts
Persistence
- Prisma data runtime
server/src/config/prisma.ts - Board data model · Models users, boards, memberships, and viewer permissions.
server/prisma/schema.prisma
Other components
- Browser Canvas API
Connections 25
- Client bootstrap → App router: mounts
- App router → Auth state: uses
- App router → Route guards: enforces access
- Route guards → Board workspace: admits authenticated users
- Auth state → HTTP API clients: auth requests
- Board workspace → Canvas renderer: renders board
- Board workspace → Drawing tools: dispatches tools
- Board workspace → Manipulation layer: selects and transforms
- Board workspace → Text editor: edits text
- Board workspace → History and autosave: tracks and saves changes
- Board workspace → Board socket client: synchronizes edits
- Drawing tools → Canvas renderer: updates elements
- Manipulation layer → Canvas renderer: updates elements
- Canvas renderer → Browser Canvas API: draws to
- History and autosave → HTTP API clients: persists boards
- HTTP API clients → HTTP startup: HTTP/JSON
- HTTP startup → Express app: starts
- Express app → Auth and board routes: mounts
- Auth and board routes → JWT middleware: protects board operations
- JWT middleware → Domain services: authorizes requests
- Auth and board routes → Domain services: delegates controllers
- Domain services → Prisma data runtime: reads and writes
- Prisma data runtime → Board data model: uses model
- Board socket client → Socket board handlers: realtime board events
- Socket board handlers → Domain services: authorizes and persists events