# vinaybhamre/drawin_frontend architecture

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

- Interactive diagram: https://gitdiagram.com/vinaybhamre/drawin_frontend
- Repository: https://github.com/vinaybhamre/drawin_frontend

## Overview

##### Project Type and Purpose
- Drawin is an interactive drawing app. The README indicates that it’s built using React.js, TypeScript, Vite.js, and Tailwind CSS on the frontend, with a Node.js/Express/Socket.IO backend.

##### File Structure
- The top-level files (e.g., index.html, package.json, vite.config.ts) show that the project is primarily a modern frontend application.
- The “src” directory holds most of the React components, utility functions, hooks, and state management.
- Within “src/modules/room”, there are subfolders for animations, components (e.g., different parts of the drawing board and toolbar), context providers, helpers, and hooks, indicating an organized modular design focusing on the “room” (drawing interface).
- The “src/recoil” directory reveals the usage of Recoil for state management with atoms and hooks, indicating a pattern of centralized application state.
- There are also custom hooks, utilities (“src/util/lib”), and type definitions to ensure type safety.

##### Key Components
a. Frontend:
- User Interface (UI): Represented by components in the “src/modules/room/components” folder, which include:
- The drawing board (canvas, background, move image, selection buttons).
- State Management: Highlight Recoil usage (src/recoil) which manages global state such as background, drawing options, room state, and saved moves.
- Context and Hooks: Illustrate how context (Room.context) and custom hooks (e.g., useDraw, useSocketDraw, useBoardPosition, etc.) encapsulate behavior and share state.
- Utilities: Represent helper functions and library utilities (e.g., canvas helper, optimize image, socket helper) that support core functionality.
- Bootstrapping: Note “src/main.tsx” as the entry point where the React app is rendered and “index.html” as the basic HTML shell.

b. Backend (as described in the README):
- Server: Node.js and Express server that handles API routes and real-time communication.
- Real-time Communication: Socket.IO integration to manage drawing events across multiple clients.
- Data Flow: API endpoints facilitating interactions such as image uploads or session management.

##### Relationships and Data Flow
- The UI components interacting with state management (Recoil atoms and hooks) to update the UI in response to user actions.
- The custom hooks, which handle functionalities such as drawing, board positioning, or socket-based events.
- The main React entry point bootstrapping the application and rendering all components.

##### Architectural Patterns and Design Principles
- Component-Based Architecture: Each part of the drawing room is isolated in components, making the UI modularized.
- Separation of Concerns: Different modules are segmented (animations, components, context, hooks, and utilities) to ensure clarity in maintenance.
- Real-time Communication: Emphasize how web socket communication (via Socket.IO on the backend) facilitates collaborative or interactive drawing experiences.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend"
        BootHTML["index.html"]:::boot
        BootMain["src/main.tsx"]:::boot

        subgraph "UI Components"
            UI_DB["Drawing Board UI Components"]:::ui
            UI_TB["Toolbar UI Components"]:::ui
        end

        Context["Room Context Providers"]:::context
        HooksRoom["Custom Hooks (Room)"]:::hooks
        HooksGlobal["Custom Hooks (Global)"]:::hooks
        Recoil["Recoil State Management"]:::state
        Utilities["Utility Functions"]:::util
        Animations["Animations"]:::anim
    end

    subgraph "Backend"
        Express["Express Server (Node.js)"]:::backend
        SocketIO["Socket.IO Integration"]:::backend
    end

    %% Bootstrapping and UI Flow
    BootHTML -->|"loads"| BootMain
    BootMain -->|"renders"| UI_DB
    BootMain -->|"renders"| UI_TB
    BootMain -->|"initiates"| HooksGlobal

    %% UI Components interactions
    UI_DB -->|"updates_to"| Recoil
    UI_TB -->|"updates_to"| Recoil
    UI_DB -->|"uses"| Context
    UI_TB -->|"uses"| Context
    Context -->|"supplies_state_to"| HooksRoom
    HooksRoom -->|"modifies"| UI_DB
    HooksGlobal -->|"adjusts_viewport_for"| UI_TB

    %% Utilities and Animations
    UI_DB -->|"invokes"| Utilities
    UI_TB -->|"invokes"| Utilities

    %% Real-time communication between Frontend and Backend
    HooksRoom -->|"triggers_socket"| SocketIO
    UI_DB -->|"sends_draw_events"| SocketIO
    UI_TB -->|"sends_interact_events"| SocketIO
    SocketIO -->|"forwards_to"| Express
    Express -->|"serves_API_to"| UI_TB

    %% Styling Classes
    classDef boot fill:#ffffcc,stroke:#333,stroke-width:2px;
    classDef ui fill:#a3c2e0,stroke:#333,stroke-width:2px;
    classDef state fill:#c0f9c0,stroke:#333,stroke-width:2px;
    classDef hooks fill:#ffcccb,stroke:#333,stroke-width:2px;
    classDef context fill:#d3b8ff,stroke:#333,stroke-width:2px;
    classDef util fill:#f0e68c,stroke:#333,stroke-width:2px;
    classDef anim fill:#ffa07a,stroke:#333,stroke-width:2px;
    classDef backend fill:#ffdead,stroke:#333,stroke-width:2px;

    %% Click Events for Component Mapping
    click BootHTML "https://github.com/vinaybhamre/drawin_frontend/blob/main/index.html"
    click BootMain "https://github.com/vinaybhamre/drawin_frontend/blob/main/src/main.tsx"
    click UI_DB "https://github.com/vinaybhamre/drawin_frontend/tree/main/src/modules/room/components/board"
    click UI_TB "https://github.com/vinaybhamre/drawin_frontend/tree/main/src/modules/room/components/toolbar"
    click Context "https://github.com/vinaybhamre/drawin_frontend/tree/main/src/modules/room/context"
    click HooksRoom "https://github.com/vinaybhamre/drawin_frontend/tree/main/src/modules/room/hooks"
    click HooksGlobal "https://github.com/vinaybhamre/drawin_frontend/tree/main/src/hooks"
    click Recoil "https://github.com/vinaybhamre/drawin_frontend/tree/main/src/recoil"
    click Utilities "https://github.com/vinaybhamre/drawin_frontend/tree/main/src/util/lib"
    click Animations "https://github.com/vinaybhamre/drawin_frontend/tree/main/src/modules/room/animations"
```
