# personalizedrefrigerator/js-draw architecture

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

- Interactive diagram: https://gitdiagram.com/personalizedrefrigerator/js-draw
- Repository: https://github.com/personalizedrefrigerator/js-draw

## Overview

##### Main Components Overview
The system should be divided into these major components:

**Core Components:**
- Editor (Central Controller)
- Image Management
- Tools System
- Rendering System
- Input/Event System
- Command System (Undo/Redo)
- Toolbar/UI System
- Localization System

**Supporting Components:**
- Math Library
- SVG Processing
- Storage/Export System
- Debug Tools

##### Component Relationships

a) Core Flow:
**User Input → Input System → Tool Controller → Command System → Image Management → Rendering System → Display**

b) Key Interactions:
- Editor coordinates all components and manages the state
- Tools interact with the Command System to make changes
- Rendering System observes Image Management for updates
- Toolbar System communicates with Tool Controller
- Localization System integrates with UI components

##### Detailed Component Breakdown

Editor Core:
**Editor**
- Viewport Management
- Event Dispatching
- State Management
- Component Coordination

Tools System:
**Tools**
- Base Tool
- Pen Tool
- Eraser Tool
- Selection Tool
- Text Tool
- Custom Tools Support

Rendering System:
**Rendering**
- Canvas Renderer
- SVG Renderer
- Cache Management
- Display Optimization

##### Implementation Details

- Support for SVG import/export
- Command pattern for undo/redo
- Demonstrate the tool extension system
- Localization flow
- Rendering pipeline
- Touch/stylus input handling

##### External Integrations

- File system interaction
- Browser APIs
- SVG processing
- Touch/Pointer APIs
- Clipboard integration

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core
        Editor["Editor (Central Controller)"]
        ImageMgmt["Image Management"]
        ToolSystem["Tools System"]
        RenderSystem["Rendering System"]
        InputSystem["Input/Event System"]
        CommandSystem["Command System"]
        ToolbarSystem["Toolbar/UI System"]
        LocalSystem["Localization System"]
    end

    subgraph Support
        MathLib["Math Library"]
        SVGProc["SVG Processing"]
        StorageSystem["Storage/Export System"]
        DebugTools["Debug Tools"]
    end

    subgraph Tools
        BaseTool["Base Tool"]
        PenTool["Pen Tool"]
        EraserTool["Eraser Tool"]
        SelectTool["Selection Tool"]
        TextTool["Text Tool"]
        CustomTools["Custom Tools"]
    end

    subgraph Rendering
        CanvasRender["Canvas Renderer"]
        SVGRender["SVG Renderer"]
        CacheMgmt["Cache Management"]
        DisplayOpt["Display Optimization"]
    end

    %% Core Component Relationships
    Editor --> ImageMgmt
    Editor --> ToolSystem
    Editor --> RenderSystem
    Editor --> InputSystem
    Editor --> CommandSystem
    Editor --> ToolbarSystem
    Editor --> LocalSystem

    %% Tool Relationships
    ToolSystem --> BaseTool
    BaseTool --> PenTool
    BaseTool --> EraserTool
    BaseTool --> SelectTool
    BaseTool --> TextTool
    BaseTool --> CustomTools

    %% Rendering Relationships
    RenderSystem --> CanvasRender
    RenderSystem --> SVGRender
    RenderSystem --> CacheMgmt
    RenderSystem --> DisplayOpt

    %% Support System Relationships
    ImageMgmt --> MathLib
    RenderSystem --> MathLib
    ImageMgmt --> SVGProc
    StorageSystem --> SVGProc
    Editor --> DebugTools

    %% Data Flow
    InputSystem -.-> ToolSystem
    ToolSystem -.-> CommandSystem
    CommandSystem -.-> ImageMgmt
    ImageMgmt -.-> RenderSystem

    %% External Integrations
    SVGProc --> StorageSystem
    LocalSystem --> ToolbarSystem

    %% Styling
    classDef core fill:#2374ab
    classDef support fill:#ff7f50
    classDef tools fill:#4caf50
    classDef rendering fill:#9c27b0

    class Editor,ImageMgmt,ToolSystem,RenderSystem,InputSystem,CommandSystem,ToolbarSystem,LocalSystem core
    class MathLib,SVGProc,StorageSystem,DebugTools support
    class BaseTool,PenTool,EraserTool,SelectTool,TextTool,CustomTools tools
    class CanvasRender,SVGRender,CacheMgmt,DisplayOpt rendering

    %% Click Events
    click Editor "https://github.com/personalizedrefrigerator/js-draw/blob/main/packages/js-draw/src/Editor.ts"
    click ImageMgmt "https://github.com/personalizedrefrigerator/js-draw/blob/main/packages/js-draw/src/image/EditorImage.ts"
    click ToolSystem "https://github.com/personalizedrefrigerator/js-draw/blob/main/packages/js-draw/src/tools/ToolController.ts"
    click RenderSystem "https://github.com/personalizedrefrigerator/js-draw/tree/main/packages/js-draw/src/rendering/renderers/"
    click InputSystem "https://github.com/personalizedrefrigerator/js-draw/blob/main/packages/js-draw/src/EventDispatcher.ts"
    click CommandSystem "https://github.com/personalizedrefrigerator/js-draw/blob/main/packages/js-draw/src/commands/Command.ts"
    click ToolbarSystem "https://github.com/personalizedrefrigerator/js-draw/blob/main/packages/js-draw/src/toolbar/AbstractToolbar.ts"
    click LocalSystem "https://github.com/personalizedrefrigerator/js-draw/blob/main/packages/js-draw/src/localizations/getLocalizationTable.ts"
    click MathLib "https://github.com/personalizedrefrigerator/js-draw/blob/main/packages/math/src/lib.ts"
    click SVGProc "https://github.com/personalizedrefrigerator/js-draw/blob/main/packages/js-draw/src/SVGLoader/SVGLoader.ts"
    click StorageSystem "https://github.com/personalizedrefrigerator/js-draw/blob/main/packages/js-draw/src/image/export/editorImageToSVG.ts"
```
