# gauravsharma2003/kalidraw architecture

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

- Interactive diagram: https://gitdiagram.com/gauravsharma2003/kalidraw
- Repository: https://github.com/gauravsharma2003/kalidraw

## Overview

##### Project Type and Purpose
- Type: Single-page web application (React + Vite + Tailwind CSS).
- Purpose: A canvas-based drawing and text-editing tool with media (Spotify) integration.

##### File Structure and Extract Architectural Components
Top-level:
- index.html, src/main.jsx, src/index.css → Application shell & entry point
- package.json / Vite/Tailwind configs → Build & styling pipeline
src/App.jsx + src/components → Core UI components
src/hooks → React hooks for event wiring (useCanvasEvents)
Spotify.jsx under src/helpers/Music → External API integration

##### Sketch Out the Main System Components
a. User Interface Layer
- App (root)
- Navbar — top-level controls
- Main — container of Canvas & toolbars
- Canvas — drawing surface
- TextToolbar, ZoomControls, DirectTextInput — overlays & input widgets
b. Event-Handling & State Management
- useCanvasEvents hook → binds mouse/keyboard/wheel/double-click
- CursorHelper → tracks pointer state
c. Canvas Engine & Utilities
- CanvasSetup, CanvasTransform, CanvasRender, CanvasCoordinates, ViewportUtils
- drawUtils, geometryUtils, shapeManipulation, selectionUtils
d. Text Subsystem
- TextEditor, TextRenderer, TextGeometry
- ShapeDetection, ShapeGeometry, ShapeResize, TextUtils
f. External Service
- Spotify.jsx → handles embed/player calls to Spotify Web API
g. Build & Asset Pipeline
- Vite bundler → dev server, hot reload
- Tailwind CSS → utility-first styling

##### Relationships and Data Flows
- User → interacts via Navbar / Canvas UI → events captured by useCanvasEvents
- Events → dispatched to Canvas engine (CanvasSetup + CanvasRender + helpers)
- UI widgets (ZoomControls, TextToolbar) ↔ Canvas engine via helper modules
- Spotify helper ↔ External Spotify API → returns media data → rendered in UI

##### Architectural Patterns
- Component-based UI (React)
- Single source of truth for canvas state (in App or Context)
- Separation of concerns: UI components vs. pure helper modules vs. external service adapter
- Hook for event orchestration (useCanvasEvents)
- Utility layers for canvas math, geometry, and rendering

##### Detail Level
- “Spotify adapter” connecting to “Spotify Web API” outside your application boundary.
- Build tools (Vite) and styling (Tailwind) off to one side as infrastructure.

– Clearly shows all major code groupings and their interactions
– Reflects the event-driven rendering loop of your canvas app
– Illustrates how UI, state, helper logic, and external services collaborate

## Diagram (Mermaid)

```mermaid
graph TD
    %% External actor
    User((User)):::external

    %% UI Layer
    subgraph "UI Layer"
        App["App (Root)"]:::ui
        Navbar["Navbar"]:::ui
        Main["Main"]:::ui
        Canvas["Canvas"]:::ui
        TextToolbar["TextToolbar"]:::ui
        ZoomControls["ZoomControls"]:::ui
        DirectTextInput["DirectTextInput"]:::ui
    end

    %% Event Layer
    subgraph "Event Layer"
        useCanvasEvents["useCanvasEvents"]:::hook
        CursorHelper["CursorHelper"]:::helper
        CanvasEvents["Canvas Events"]:::helper
    end

    %% Canvas Engine
    subgraph "Canvas Engine"
        CanvasSetup["CanvasSetup"]:::helper
        CanvasTransform["CanvasTransform"]:::helper
        CanvasRender["CanvasRender"]:::helper
        CanvasCoordinates["CanvasCoordinates"]:::helper
        ViewportUtils["ViewportUtils"]:::helper
    end

    %% Shape Subsystem
    subgraph "Shape Subsystem"
        drawUtils["drawUtils"]:::helper
        geometryUtils["geometryUtils"]:::helper
        selectionUtils["selectionUtils"]:::helper
        shapeManipulation["shapeManipulation"]:::helper
        ShapeDetection["ShapeDetection"]:::helper
        ShapeGeometry["ShapeGeometry"]:::helper
        ShapeResize["ShapeResize"]:::helper
        TextUtils["TextUtils"]:::helper
    end

    %% Text Subsystem
    subgraph "Text Subsystem"
        TextEditor["TextEditor"]:::helper
        TextRenderer["TextRenderer"]:::helper
        TextGeometry["TextGeometry"]:::helper
    end

    %% External Service
    subgraph "External Service"
        SpotifyAdapter["Spotify Adapter"]:::external
        SpotifyWebAPI((Spotify Web API)):::external
    end

    %% Infrastructure
    subgraph "Infrastructure"
        Vite["Vite Bundler"]:::infra
        Tailwind["Tailwind CSS"]:::infra
    end

    %% Relationships
    User --> App
    App --> Navbar
    App --> Main
    Main --> Canvas
    Main --> TextToolbar
    Main --> ZoomControls
    Main --> DirectTextInput

    Canvas --> useCanvasEvents
    Navbar --> useCanvasEvents
    useCanvasEvents --> CanvasEvents
    useCanvasEvents --> CanvasSetup

    CanvasEvents --> CanvasSetup
    CanvasSetup --> CanvasTransform
    CanvasTransform --> CanvasRender
    CanvasRender --> Canvas
    CanvasRender --> CanvasCoordinates
    CanvasRender --> ViewportUtils

    CanvasRender --> drawUtils
    CanvasRender --> geometryUtils
    CanvasRender --> selectionUtils

    CanvasRender --> shapeManipulation
    shapeManipulation --> ShapeDetection
    shapeManipulation --> ShapeGeometry
    shapeManipulation --> ShapeResize
    shapeManipulation --> TextUtils

    CanvasRender --> TextRenderer
    TextRenderer --> TextEditor
    TextRenderer --> TextGeometry

    SpotifyAdapter -->|"API calls"| SpotifyWebAPI
    SpotifyAdapter --> App

    Vite --> App
    Tailwind --> App

    %% Click Events
    click App "https://github.com/gauravsharma2003/kalidraw/blob/main/src/App.jsx"
    click Navbar "https://github.com/gauravsharma2003/kalidraw/blob/main/src/components/Navbar.jsx"
    click Main "https://github.com/gauravsharma2003/kalidraw/blob/main/src/components/Main.jsx"
    click Canvas "https://github.com/gauravsharma2003/kalidraw/blob/main/src/components/Canvas.jsx"
    click TextToolbar "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/TextToolbar.jsx"
    click ZoomControls "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/ZoomControls.jsx"
    click DirectTextInput "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/DirectTextInput.jsx"
    click useCanvasEvents "https://github.com/gauravsharma2003/kalidraw/blob/main/src/hooks/useCanvasEvents.js"
    click CursorHelper "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/CursorHelper.js"
    click CanvasEvents "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/canvasEvents/index.js"
    click CanvasSetup "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/canvasUtils/CanvasSetup.js"
    click CanvasTransform "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/canvasUtils/CanvasTransform.js"
    click CanvasRender "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/canvasUtils/CanvasRender.js"
    click CanvasCoordinates "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/canvasUtils/CanvasCoordinates.js"
    click ViewportUtils "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/canvasUtils/ViewportUtils.js"
    click drawUtils "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/drawUtils.js"
    click geometryUtils "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/geometryUtils.js"
    click selectionUtils "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/selectionUtils.js"
    click shapeManipulation "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/shapeManipulation.js"
    click ShapeDetection "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/shapeUtils/ShapeDetection.js"
    click ShapeGeometry "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/shapeUtils/ShapeGeometry.js"
    click ShapeResize "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/shapeUtils/ShapeResize.js"
    click TextUtils "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/shapeUtils/TextUtils.js"
    click TextEditor "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/textutils/TextEditor.js"
    click TextGeometry "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/textutils/TextGeometry.js"
    click TextRenderer "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/textutils/TextRenderer.js"
    click SpotifyAdapter "https://github.com/gauravsharma2003/kalidraw/blob/main/src/helpers/Music/Spotify.jsx"

    %% Styles
    classDef ui fill:#AED6F1,stroke:#2980B9,stroke-width:1px
    classDef helper fill:#ABEBC6,stroke:#27AE60,stroke-width:1px
    classDef hook fill:#F9E79F,stroke:#D68910,stroke-width:1px
    classDef external fill:#D2B4DE,stroke:#8E44AD,stroke-width:1px
    classDef infra fill:#D5DBDB,stroke:#566573,stroke-width:1px
```
