# anishsaha46/doodleflow architecture

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

- Interactive diagram: https://gitdiagram.com/anishsaha46/doodleflow
- Repository: https://github.com/anishsaha46/doodleflow

## Overview

##### Project type and purpose
- This is a full-stack, single-page web application: “DoodleFlow” is a React + TypeScript drawing app with real-time, multi-user collaboration.
- Frontend: Vite-bundled React app using HTML5 Canvas, Tailwind CSS.
- Backend: A simple Node.js server (server.js) providing a Socket.io endpoint for real-time sync.
- Persistence: Browser localStorage for save/load; PNG export; no external database.

##### File structure
- Top level
- package.json / package-lock.json: dependencies (React, Socket.io, Vite, TS, Tailwind, etc.)
- server.js: Node.js + Socket.io server entry point
- index.html + public/: static assets served at root
- vite.config.ts, tsconfig*.json, tailwind.config.js, eslint.config.js: build and lint config
- src/
- main.tsx, App.tsx: React entry and root component
- index.css: global Tailwind imports
- vite-env.d.ts: type declarations
- No “backend/” folder—backend lives in server.js at project root.

##### Extract insights from README
- Tech stack: React, TS, Tailwind, Socket.io, Canvas API
- Runtime: “npm run dev” (Vite dev server) + “node server.js” (Socket.io server).

##### Main components
a. Frontend client
- Vite Dev Server / Static host
- React App
- State Management (useState, useRef)
- Canvas Rendering module
- Export module (PNG)
- LocalStorage Adapter
- Socket.io Client
b. Backend server
- Node.js + Express (if any) or raw HTTP server
- Socket.io Server
- Event broadcaster (in memory)
c. External connections
- Browser’s localStorage
- WebSocket (Socket.io) channel

##### Relationships and interactions
- User → React UI → Canvas API
- UI actions → State updates → Canvas re-render
- “Save” / “Load” → localStorage read/write
- “Export” → Canvas → PNG blob → download
- React <→> Socket.io client ↔ WebSocket ↔ Socket.io server → broadcast to other clients
- HTTP/WS handshake at app startup:
- Client connects to server.js on port e.g. 3001
- Server acknowledges, joins room

##### Architectural patterns & principles
- Separation of concerns:
- Presentation (React + Canvas)
- State management (hooks)
- Networking (Socket.io layer)
- Persistence (localStorage adapter)
- Event-driven, pub/sub style for collaboration

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (Browser)" 
        direction TB
        VITE["Vite Dev Server / Static Host"]:::infra
        Main["main.tsx"]:::frontend
        App["App.tsx"]:::frontend
        UI["UI: Toolbar, Canvas, Color Picker"]:::frontend
        State["State Management (hooks)"]:::frontend
        Canvas["Canvas Renderer"]:::frontend
        Exporter["Export Module (PNG)"]:::frontend
        LSAdapter["LocalStorage Adapter"]:::frontend
        SocketClient["Socket.io Client"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Node.js Server)"
        direction TB
        Server["server.js"]:::backend
        SocketIO["Socket.io Server"]:::backend
    end

    %% External / Storage
    subgraph "External / Storage"
        direction TB
        LocalStorage["Browser localStorage"]:::storage
        WebSocketChannel["WebSocket Channel"]:::storage
        Download["File Download"]:::storage
    end

    %% Dev & Build Infrastructure
    subgraph "Dev & Build Infrastructure"
        direction TB
        ViteConfig["vite.config.ts"]:::infra
        TSConfigs["tsconfig.json / tsconfig.app.json / tsconfig.node.json"]:::infra
        TailwindConfig["tailwind.config.js"]:::infra
        ESLintConfig["eslint.config.js"]:::infra
        PackageJSON["package.json / package-lock.json"]:::infra
    end

    %% Connections
    VITE -->|"HTTP GET /index.html"| Main
    Main -->|boots| App
    App -->|renders| UI
    UI -->|user actions| State
    State -->|updates| Canvas
    UI -->|draw on| Canvas
    Exporter -->|create PNG blob| Download
    LSAdapter -->|localStorage.getItem / setItem| LocalStorage
    App -->|uses| LSAdapter
    App -->|uses| Exporter
    App -->|uses| SocketClient

    SocketClient <-->|"emit('draw'),on('draw')"| WebSocketChannel
    WebSocketChannel <-->|WebSocket handshake on connect| SocketIO
    SocketIO -->|broadcast events| SocketClient

    Server -->|hosts| SocketIO

    %% Click Events
    click Main "https://github.com/anishsaha46/doodleflow/blob/main/src/main.tsx"
    click App "https://github.com/anishsaha46/doodleflow/blob/main/src/App.tsx"
    click Server "https://github.com/anishsaha46/doodleflow/blob/main/server.js"
    click ViteConfig "https://github.com/anishsaha46/doodleflow/blob/main/vite.config.ts"
    click TSConfigs "https://github.com/anishsaha46/doodleflow/blob/main/tsconfig.json"
    click TailwindConfig "https://github.com/anishsaha46/doodleflow/blob/main/tailwind.config.js"
    click ESLintConfig "https://github.com/anishsaha46/doodleflow/blob/main/eslint.config.js"
    click PackageJSON "https://github.com/anishsaha46/doodleflow/blob/main/package.json"
    click LSAdapter "https://github.com/anishsaha46/doodleflow/blob/main/src/App.tsx"
    click Exporter "https://github.com/anishsaha46/doodleflow/blob/main/src/App.tsx"
    click SocketClient "https://github.com/anishsaha46/doodleflow/blob/main/src/App.tsx"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0284C7,color:#000
    classDef backend fill:#D0FFD0,stroke:#22C55E,color:#000
    classDef storage fill:#FFF5BA,stroke:#D97706,color:#000
    classDef infra fill:#EDEDED,stroke:#6B7280,color:#000
```
