# vikasingh0897/drawly architecture

> Architecture diagram of the GitHub repository vikasingh0897/drawly, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vikasingh0897/drawly
- Repository: https://github.com/vikasingh0897/drawly

## Overview

1. **High-level shape**
   - Drawly is a two-process full-stack app: a React/Vite frontend and a Node.js/Express backend.
   - The primary architecture boundary is **HTTP for initial app delivery** and **Socket.IO for all live game interaction**.

2. **Frontend application boundary**
   - The frontend is a single-page app under `frontend/src`.
   - `main.tsx` boots the app, `App.tsx` owns top-level page selection, and the UI splits into a landing flow and an in-game flow.

3. **Client-side navigation and screens**
   - `pages/LandingPage.tsx` is the entry point for creating or joining a room.
   - `pages/GamePage.tsx` is the active gameplay screen and aggregates the real-time game widgets: canvas, chat, and leaderboard.

4. **Frontend component subsystem**
   - `components/Canvas.tsx` handles drawing interactions and rendering.
   - `components/Chat.tsx` handles message entry and guess display.
   - `components/Leaderboard.tsx` shows live scores.
   - `Header.tsx`, `Footer.tsx`, and `HowToPlay.tsx` provide shared chrome and onboarding.

5. **Client real-time transport**
   - `src/socket.ts` centralizes the Socket.IO client connection.
   - The UI components and pages likely consume this shared socket instance to emit events and subscribe to server broadcasts, keeping transport logic separate from presentation.

6. **Backend application boundary**
   - `backend/src/index.ts` is the bootstrapper; `app.ts` sets up the Express server layer.
   - The backend is structured around Socket.IO event handlers rather than REST APIs, which is consistent with a real-time multiplayer game engine.

7. **Backend event-handling subsystem**
   - `socketHandlers/roomHandler.ts` manages room creation, joining, and lifecycle changes.
   - `socketHandlers/gameHandler.ts` drives round state, turn progression, and game flow.
   - `socketHandlers/canvasHandler.ts` relays drawing events across clients.
   - `socketHandlers/chatHandler.ts` handles messages, guess validation, and scoring-related chat behavior.

8. **In-memory state subsystem**
   - `store/room.ts` holds active room state, player rosters, rounds, and related runtime state.
   - `store/words.ts` provides the guessable word set used during rounds.
   - The architecture suggests **server-side ephemeral state**, not a persistent database: rooms and scores live in memory for the duration of the server process.

9. **Core data flow**
   - A player enters the landing page, creates or joins a room, and the frontend sends socket events to the backend.
   - The backend updates room state in `store/room.ts`, then broadcasts room/game updates to all connected clients.
   - During play, canvas strokes and chat/guess events flow from one client to the server and back out to all room members.

10. **Game synchronization model**
   - Drawing is treated as a shared live event stream, not as saved images.
   - Guessing is server-authoritative: the backend decides whether a chat message is a valid guess and then updates scores and visibility accordingly.
   - This makes the server the single source of truth for gameplay state.

11. **Room isolation and multiplayer boundaries**
   - Each room is an isolated session with its own players and current round state.
   - The backend enforces separation between rooms so gameplay events only fan out to participants in the same room.

12. **Frontend build and styling boundary**
   - The frontend uses Vite for development/build tooling and React for UI composition.
   - `index.css` and the Vite setup indicate a utility-first styling approach, but these are presentation concerns rather than architectural drivers.

13. **External service/infrastructure implications**
   - The only clear runtime dependency that materially shapes architecture is **Socket.IO** for low-latency duplex messaging.
   - No database, cache, or message broker appears in the tree, so the system is intentionally lightweight and process-local on the backend.

14. **What an architecture diagram should emphasize**
   - Drawly should be diagrammed as:
     - a browser SPA,
     - a Socket.IO real-time channel,
     - a Node/Express server,
     - modular socket handlers,
     - and in-memory game/room stores.
   - The key flow is: UI interaction -> socket event -> server state update -> broadcast -> synchronized UI update.

Main entry points: [`frontend/src/pages/GamePage.tsx`](https://github.com/vikasingh0897/drawly/blob/main/frontend/src/pages/GamePage.tsx) (Game), [`backend/src/app.ts`](https://github.com/vikasingh0897/drawly/blob/main/backend/src/app.ts) (app.ts), [`backend/src/store/room.ts`](https://github.com/vikasingh0897/drawly/blob/main/backend/src/store/room.ts) (room store), [`frontend/src/App.tsx`](https://github.com/vikasingh0897/drawly/blob/main/frontend/src/App.tsx) (App)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_main["main.tsx<br/>entry<br/>[main.tsx]"]
  node_frontend_app["App<br/>shell<br/>[App.tsx]"]
  node_landing_page["Landing<br/>page<br/>[LandingPage.tsx]"]
  node_game_page["Game<br/>page<br/>[GamePage.tsx]"]
  node_canvas_ui["Canvas<br/>game-ui<br/>[Canvas.tsx]"]
  node_chat_ui["Chat<br/>game-ui<br/>[Chat.tsx]"]
  node_leaderboard_ui["Leaderboard<br/>game-ui<br/>[Leaderboard.tsx]"]
  node_header_ui["Header<br/>chrome<br/>[Header.tsx]"]
  node_footer_ui["Footer<br/>chrome<br/>[Footer.tsx]"]
  node_howto_ui["HowToPlay<br/>onboarding<br/>[HowToPlay.tsx]"]
end

subgraph group_backend["Backend"]
  node_backend_index["index.ts<br/>server entry<br/>[index.ts]"]
  node_backend_app["app.ts<br/>express app<br/>[app.ts]"]
  node_room_handler["Room handler<br/>socket handler<br/>[roomHandler.ts]"]
  node_game_handler["Game handler<br/>socket handler<br/>[gameHandler.ts]"]
  node_canvas_handler["Canvas handler<br/>socket handler<br/>[canvasHandler.ts]"]
  node_chat_handler["Chat handler<br/>socket handler<br/>[chatHandler.ts]"]
end

subgraph group_shared["Shared runtime"]
  node_socket_client[("socket.ts<br/>socket client<br/>[socket.ts]")]
  node_room_store[("room store<br/>in-memory state<br/>[room.ts]")]
  node_words_store["words store<br/>word bank<br/>[words.ts]"]
end

node_frontend_main -->|"mounts"| node_frontend_app
node_frontend_app -->|"lobby flow"| node_landing_page
node_frontend_app -->|"game flow"| node_game_page
node_landing_page -->|"emit room events"| node_socket_client
node_game_page -->|"subscribe/emit"| node_socket_client
node_game_page -->|"renders"| node_canvas_ui
node_game_page -->|"renders"| node_chat_ui
node_game_page -->|"renders"| node_leaderboard_ui
node_game_page -->|"shared chrome"| node_header_ui
node_game_page -->|"shared chrome"| node_footer_ui
node_game_page -->|"onboarding"| node_howto_ui
node_socket_client -->|"Socket.IO"| node_backend_index
node_backend_index -->|"starts"| node_backend_app
node_backend_app -->|"registers"| node_room_handler
node_backend_app -->|"registers"| node_game_handler
node_backend_app -->|"registers"| node_canvas_handler
node_backend_app -->|"registers"| node_chat_handler
node_room_handler -->|"reads/writes"| node_room_store
node_game_handler -->|"updates"| node_room_store
node_game_handler -->|"selects words"| node_words_store
node_canvas_handler -->|"broadcasts via room"| node_room_store
node_chat_handler -->|"updates scores"| node_room_store

click node_frontend_main "https://github.com/vikasingh0897/drawly/blob/main/frontend/src/main.tsx"
click node_frontend_app "https://github.com/vikasingh0897/drawly/blob/main/frontend/src/App.tsx"
click node_landing_page "https://github.com/vikasingh0897/drawly/blob/main/frontend/src/pages/LandingPage.tsx"
click node_game_page "https://github.com/vikasingh0897/drawly/blob/main/frontend/src/pages/GamePage.tsx"
click node_canvas_ui "https://github.com/vikasingh0897/drawly/blob/main/frontend/src/components/Canvas.tsx"
click node_chat_ui "https://github.com/vikasingh0897/drawly/blob/main/frontend/src/components/Chat.tsx"
click node_leaderboard_ui "https://github.com/vikasingh0897/drawly/blob/main/frontend/src/components/Leaderboard.tsx"
click node_header_ui "https://github.com/vikasingh0897/drawly/blob/main/frontend/src/components/Header.tsx"
click node_footer_ui "https://github.com/vikasingh0897/drawly/blob/main/frontend/src/components/Footer.tsx"
click node_howto_ui "https://github.com/vikasingh0897/drawly/blob/main/frontend/src/components/HowToPlay.tsx"
click node_socket_client "https://github.com/vikasingh0897/drawly/blob/main/frontend/src/socket.ts"
click node_backend_index "https://github.com/vikasingh0897/drawly/blob/main/backend/src/index.ts"
click node_backend_app "https://github.com/vikasingh0897/drawly/blob/main/backend/src/app.ts"
click node_room_handler "https://github.com/vikasingh0897/drawly/blob/main/backend/src/socketHandlers/roomHandler.ts"
click node_game_handler "https://github.com/vikasingh0897/drawly/blob/main/backend/src/socketHandlers/gameHandler.ts"
click node_canvas_handler "https://github.com/vikasingh0897/drawly/blob/main/backend/src/socketHandlers/canvasHandler.ts"
click node_chat_handler "https://github.com/vikasingh0897/drawly/blob/main/backend/src/socketHandlers/chatHandler.ts"
click node_room_store "https://github.com/vikasingh0897/drawly/blob/main/backend/src/store/room.ts"
click node_words_store "https://github.com/vikasingh0897/drawly/blob/main/backend/src/store/words.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_frontend_main,node_frontend_app,node_landing_page,node_game_page,node_canvas_ui,node_chat_ui,node_leaderboard_ui,node_header_ui,node_footer_ui,node_howto_ui toneBlue
class node_backend_index,node_backend_app,node_room_handler,node_game_handler,node_canvas_handler,node_chat_handler toneAmber
class node_socket_client,node_room_store,node_words_store toneMint
```

## Components

### Frontend

React/Vite browser app

- [main.tsx](https://github.com/vikasingh0897/drawly/blob/main/frontend/src/main.tsx): entry · Bootstraps the SPA · `frontend/src/main.tsx`
- [App](https://github.com/vikasingh0897/drawly/blob/main/frontend/src/App.tsx): shell · Top-level page and flow selection · `frontend/src/App.tsx`
- [Landing](https://github.com/vikasingh0897/drawly/blob/main/frontend/src/pages/LandingPage.tsx): page · Room create/join entry point · `frontend/src/pages/LandingPage.tsx`
- [Game](https://github.com/vikasingh0897/drawly/blob/main/frontend/src/pages/GamePage.tsx): page · Active gameplay screen · `frontend/src/pages/GamePage.tsx`
- [Canvas](https://github.com/vikasingh0897/drawly/blob/main/frontend/src/components/Canvas.tsx): game-ui · Drawing surface and interactions · `frontend/src/components/Canvas.tsx`
- [Chat](https://github.com/vikasingh0897/drawly/blob/main/frontend/src/components/Chat.tsx): game-ui · Messages and guess input · `frontend/src/components/Chat.tsx`
- [Leaderboard](https://github.com/vikasingh0897/drawly/blob/main/frontend/src/components/Leaderboard.tsx): game-ui · Live score display · `frontend/src/components/Leaderboard.tsx`
- [Header](https://github.com/vikasingh0897/drawly/blob/main/frontend/src/components/Header.tsx): chrome · Shared top-level chrome · `frontend/src/components/Header.tsx`
- [Footer](https://github.com/vikasingh0897/drawly/blob/main/frontend/src/components/Footer.tsx): chrome · Shared footer chrome · `frontend/src/components/Footer.tsx`
- [HowToPlay](https://github.com/vikasingh0897/drawly/blob/main/frontend/src/components/HowToPlay.tsx): onboarding · Gameplay instructions · `frontend/src/components/HowToPlay.tsx`

### Backend

Node/Express real-time server

- [index.ts](https://github.com/vikasingh0897/drawly/blob/main/backend/src/index.ts): server entry · Server bootstrapper · `backend/src/index.ts`
- [app.ts](https://github.com/vikasingh0897/drawly/blob/main/backend/src/app.ts): express app · Express server setup · `backend/src/app.ts`
- [Room handler](https://github.com/vikasingh0897/drawly/blob/main/backend/src/socketHandlers/roomHandler.ts): socket handler · Room creation and lifecycle events · `backend/src/socketHandlers/roomHandler.ts`
- [Game handler](https://github.com/vikasingh0897/drawly/blob/main/backend/src/socketHandlers/gameHandler.ts): socket handler · Round and turn progression · `backend/src/socketHandlers/gameHandler.ts`
- [Canvas handler](https://github.com/vikasingh0897/drawly/blob/main/backend/src/socketHandlers/canvasHandler.ts): socket handler · Broadcasts drawing events · `backend/src/socketHandlers/canvasHandler.ts`
- [Chat handler](https://github.com/vikasingh0897/drawly/blob/main/backend/src/socketHandlers/chatHandler.ts): socket handler · Guess checks and chat scoring · `backend/src/socketHandlers/chatHandler.ts`

### Shared runtime

Cross-cutting transport and state

- [socket.ts](https://github.com/vikasingh0897/drawly/blob/main/frontend/src/socket.ts): socket client · Central Socket.IO client connection · `frontend/src/socket.ts`
- [room store](https://github.com/vikasingh0897/drawly/blob/main/backend/src/store/room.ts): in-memory state · Active rooms, players, and rounds · `backend/src/store/room.ts`
- [words store](https://github.com/vikasingh0897/drawly/blob/main/backend/src/store/words.ts): word bank · Guessable round words · `backend/src/store/words.ts`

## Connections

- main.tsx → App: mounts · Bootstraps the app shell
- App → Landing: lobby flow · Shows room entry experience
- App → Game: game flow · Switches into active play
- Landing → socket.ts: emit room events · Creates or joins rooms over Socket.IO
- Game → socket.ts: subscribe/emit · Coordinates live gameplay traffic
- Game → Canvas: renders · Hosts drawing interactions
- Game → Chat: renders · Hosts chat and guesses
- Game → Leaderboard: renders · Shows live scores
- Game → Header: shared chrome · Uses common header
- Game → Footer: shared chrome · Uses common footer
- Game → HowToPlay: onboarding · Provides play instructions
- socket.ts → index.ts: Socket.IO · Real-time client-server channel
- index.ts → app.ts: starts · Bootstraps the HTTP and socket server
- app.ts → Room handler: registers · Attaches room event logic
- app.ts → Game handler: registers · Attaches game flow logic
- app.ts → Canvas handler: registers · Attaches drawing event logic
- app.ts → Chat handler: registers · Attaches chat and guess logic
- Room handler → room store: reads/writes · Maintains session state in memory
- Game handler → room store: updates · Advances rounds and turns
- Game handler → words store: selects words · Chooses round prompts
- Canvas handler → room store: broadcasts via room · Fans drawing events to room members
- Chat handler → room store: updates scores · Applies authoritative game state changes
