# diayoak/graphic-tool architecture

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

- Interactive diagram: https://gitdiagram.com/diayoak/graphic-tool
- Repository: https://github.com/diayoak/graphic-tool

## Overview

##### Main Components Identification

The system should be represented with these key components:

a. User Interface Layer
- Canvas Component (Main drawing area)
- Toolbar Component (Tool selection interface)

b. Tool Management Layer
- Tool Controller
- Individual Tools Implementation
- Event Handling System

##### Component Organization

**┌─────────────────────────────────────────┐**
- User Interface             │
- ┌─────────┐ ┌─────────┐ ┌─────────┐   │
- Toolbar │ │ Canvas  │ │ Future  │   │
- Panels  │   │
- ┘ └─────────┘ └─────────┘   │
- ┬─────────────────────┘

**┌───────────────────▼─────────────────────┐**
- Tool Management Layer         │
- ┌─────────────────────────────────┐    │
- Tool Controller         │    │
- ┘    │
- ┌─────────┐ ┌─────────┐ ┌─────────┐   │
- Pen    │ │  Brush  │ │  Text   │   │
- Tool   │ │  Tool   │ │  Tool   │   │
- ┘ └─────────┘ └─────────┘   │
- ┌─────────┐ ┌─────────┐ ┌─────────┐   │
- Polygon │ │ Select  │ │  Edit   │   │
- Tool   │ │  Tool   │ │ Pointer │   │
- ┘ └─────────┘ └─────────┘   │
- ┘

##### Specific Elements

- Blue: User Interface components
- Green: Tool management components
- Gray: Future/planned features

- Inheritance lines from Tool base class to specific tools

##### Implementation Details to Highlight

- Inheritance hierarchy from Tool.js to specific tool implementations
- Event flow from user interactions to tool execution
- Modular structure of different tools
- Relationship between lib.js and the tool implementations

##### Technical Stack Indicators

- HTML5 Canvas API
- Vanilla JavaScript
- CSS for styling
- Browser APIs for rendering

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef tool fill:#2ecc71,stroke:#27ae60,color:white
    classDef future fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef base fill:#e74c3c,stroke:#c0392b,color:white

    %% User Interface Layer
    subgraph UI["User Interface Layer"]
        HTML["index.html"]:::ui
        CSS["style.css"]:::ui
        Canvas["Canvas Component"]:::ui
        Toolbar["Toolbar Component"]:::ui
        FutureUI["Future Components<br/>(Color Picker, Layer Panel)"]:::future
    end

    %% Tool Management Layer
    subgraph TM["Tool Management Layer"]
        ToolController["Tool Controller"]:::base
        LibJS["lib.js"]:::base
        
        subgraph Tools["Tool Implementations"]
            BaseTool["Tool.js<br/>(Base Class)"]:::tool
            PenTool["PenTool"]:::tool
            BrushTool["BrushTool"]:::tool
            TextTool["TextTool"]:::tool
            PolygonTool["PolygonTool"]:::tool
            SelectTool["SelectTool"]:::tool
            EditPointer["EditPointer"]:::tool
        end
    end

    %% Relationships
    Toolbar --> ToolController
    Canvas <--> ToolController
    ToolController --> BaseTool
    LibJS --> ToolController
    
    BaseTool --> PenTool
    BaseTool --> BrushTool
    BaseTool --> TextTool
    BaseTool --> PolygonTool
    BaseTool --> SelectTool
    BaseTool --> EditPointer

    %% Click Events
    click HTML "https://github.com/diayoak/Graphic-Tool/blob/main/index.html"
    click CSS "https://github.com/diayoak/Graphic-Tool/blob/main/css/style.css"
    click BaseTool "https://github.com/diayoak/Graphic-Tool/blob/main/js/Tool.js"
    click PenTool "https://github.com/diayoak/Graphic-Tool/blob/main/js/PenTool.js"
    click BrushTool "https://github.com/diayoak/Graphic-Tool/blob/main/js/BrushTool.js"
    click TextTool "https://github.com/diayoak/Graphic-Tool/blob/main/js/TextTool.js"
    click PolygonTool "https://github.com/diayoak/Graphic-Tool/blob/main/js/PolygonTool.js"
    click SelectTool "https://github.com/diayoak/Graphic-Tool/blob/main/js/SelectTool.js"
    click EditPointer "https://github.com/diayoak/Graphic-Tool/blob/main/js/EditPointer.js"
    click LibJS "https://github.com/diayoak/Graphic-Tool/blob/main/js/lib.js"
    click ToolController "https://github.com/diayoak/Graphic-Tool/blob/main/js/app.js"

    %% Legend
    subgraph Legend
        UI_Legend["UI Components"]:::ui
        Tool_Legend["Tool Components"]:::tool
        Future_Legend["Future Features"]:::future
        Base_Legend["Core Components"]:::base
    end
```
