How makaveli2p/sketchsync works
Project Type and Purpose
• This is a full‑stack, real‑time collaborative drawing application built with Next.js (React + SSR), Node.js (WebSocket server), and TypeScript.
File Structure
Top‑level areas:
• pages/ – Next.js pages (SSG/SSR). Contains the room page ([roomId].tsx), static index page, API route (pages/api/hello.ts).
• modules/ – Feature modules for “home” and “room.” Each module encapsulates React components, hooks, context, helpers, animations, and modals.
• common/ – Shared UI components (modals, portals), shared hooks, Recoil atoms & hooks (global state: background, modal, room, users, savedMoves, options), utility libs, constants, types.
• server/ – Standalone Node.js WebSocket (socket.io or ws) server to mediate real‑time drawing and chat events.
• public/, styles/, tailwind.config.ts – Static assets and styling.
• next.config.mjs, tsconfig*.json, package.json – Build/deploy configurations.
Main Components
A. Frontend (Next.js + React)
1. Next.js Server / CDN – serves pages, static assets, SSR.
2. React App –
• Home Module (landing page, room creation/join UI)
• Common Components & Recoil State – modal manager, portals, global state atoms/hooks
B. Backend
1. Next.js API (optional REST endpoint: hello)
2. WebSocket Server (server/index.ts) – receives drawing/chat events, broadcasts to room participants
C. Data/State
• In‑memory state in server (per‑room user list, canvas history?)
• Client‑side Recoil atoms for UI state, drawing moves, users
D. External Services (if any)
• None specified (no persistent DB, uses ephemeral in‑memory).
Relationships & Data Flows
• Browser ↔️ Next.js Server: initial page load, SSR, static assets.
• React Components ↔️ Recoil Store: UI reads/writes global state.
• React Hooks (useSocketDraw, useMovesHandlers) ↔️ Socket library wrapper (common/lib/socket.ts).
• WebSocket Server ↔️ All connected clients in the same “room” channel.
Architectural Patterns & Design Principles
• Module‑based frontend: each feature (home, room) self‑contained with its own components/hooks/context.
• Shared common library: DRY UI primitives, shared state wrappers, helpers.
• State management: Recoil for client‑side global state, separating atoms by domain.
• Real‑time pub/sub via WebSocket server.
• Next.js conventions: pages → automatic routing; API routes for light REST; server as separate real‑time service.
Key Technologies
• Next.js (React, SSR, routing)
• React + TypeScript + Tailwind CSS
• Recoil (state management)
• Node.js WebSocket server (socket.io or ws)
• PostCSS (styling), ESLint, tsconfig, package scripts