# xachary/konva-designer-sample architecture

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

- Interactive diagram: https://gitdiagram.com/xachary/konva-designer-sample
- Repository: https://github.com/xachary/konva-designer-sample

## Overview

##### Project Type and Purpose
- This is a frontend single‐page application built with Vue 3, Vite, and TypeScript.
- It provides an interactive designer canvas using the Konva.js library.

##### High-Level Architecture
A. Browser / Client
- Vue Application (App.vue, PlayPage.vue)
- UI Components (AssetBar, MainHeader, settings panel)
B. Domain Logic Layer
- State Management (Vue reactive state in main.ts + log.ts)
- Tools (src/Render/tools/*) – AlignTool, AssetTool, LinkTool, etc.
- Handlers (src/Render/handlers/*) – DragHandlers, ZoomHandlers, SelectionHandlers, etc.
C. Rendering Engine
- Graph definitions (src/Render/graphs/*) define geometric primitives
D. Data Persistence & I/O
- ImportExportTool for loading/saving JSON design files
- Public/docs directories hold sample JSON and assets for docs
E. Build & Deployment
- Vite (vite.config.ts) for bundling dev/prod builds
- Husky & commitlint for pre-commit hooks
- GitHub Actions (deploy.yml) for CI/CD to GitHub Pages

##### Relationships and Data Flow
1. UI Components dispatch user events (click/drag/keyboard).
2. Handlers receive events, update reactive state & invoke Tools.
3. Tools modify Models (graph nodes, links) or call Import/Export logic.
6. Preview window subscribes to the same state and renders a secondary Konva view.

##### Architectural Patterns & Design Principles
- Separation of Concerns: UI vs. business logic (Tools & Handlers) vs. rendering code.
- Reactive State: Vue’s reactivity drives canvas updates without manual DOM manipulation.

##### Technologies & Frameworks
- Vue 3 + Composition API for UI and reactivity
- TypeScript for type safety (env.d.ts, tsconfig.json)
- Vite for fast dev server & production build
- Husky & commitlint for code hygiene
- GitHub Actions for automated deployment

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Browser / Client"
        Entry["main.ts"]:::domain
        UI_Main["App.vue"]:::ui
        UI_Play["PlayPage.vue"]:::ui
        subgraph "UI Components"
            AssetBar["AssetBar"]:::ui
            MainHeader["MainHeader"]:::ui
        end
        Entry --> UI_Main
        UI_Main --> UI_Play
        UI_Play --> AssetBar
        UI_Play --> MainHeader
        UI_Play --> State
    end

    subgraph "Domain Logic Layer"
        State["Reactive State"]:::domain
        subgraph "Handlers"
            DragHandlers["DragHandlers"]:::domain
            DragOutsideHandlers["DragOutsideHandlers"]:::domain
            GraphHandlers["GraphHandlers"]:::domain
            KeyMoveHandlers["KeyMoveHandlers"]:::domain
            LinkHandlers["LinkHandlers"]:::domain
            SelectionHandlers["SelectionHandlers"]:::domain
            ShutcutHandlers["ShutcutHandlers"]:::domain
            TextHandlers["TextHandlers"]:::domain
            ZoomHandlers["ZoomHandlers"]:::domain
        end
        subgraph "Tools"
            AlignTool["AlignTool"]:::domain
            AssetTool["AssetTool"]:::domain
            AttractTool["AttractTool"]:::domain
            CopyTool["CopyTool"]:::domain
            ImportExportTool["ImportExportTool"]:::domain
            LinkTool["LinkTool"]:::domain
            PositionTool["PositionTool"]:::domain
            SelectionTool["SelectionTool"]:::domain
            ZIndexTool["ZIndexTool"]:::domain
        end
        State --> Handlers
        Handlers --> Tools
        Tools --> State
    end

    subgraph "Rendering Engine"
        subgraph "Draw Modules"
            AttractDraw["AttractDraw"]:::render
            BgDraw["BgDraw"]:::render
            ContextmenuDraw["ContextmenuDraw"]:::render
            GraphDraw["GraphDraw"]:::render
            LinkDraw["LinkDraw"]:::render
            PreviewDraw["PreviewDraw"]:::render
            RefLineDraw["RefLineDraw"]:::render
            RulerDraw["RulerDraw"]:::render
        end
        subgraph "Graph Definitions"
            BaseGraph["BaseGraph"]:::render
            Bezier["Bezier"]:::render
            Circle["Circle"]:::render
            Curve["Curve"]:::render
            Line["Line"]:::render
            Rect["Rect"]:::render
        end
        subgraph "Konva Pipeline"
            KonvaStage["Konva.Stage"]:::render
            KonvaLayer["Konva.Layer"]:::render
            KonvaGroup["Konva.Group"]:::render
            KonvaShape["Konva.Shape"]:::render
            KonvaStage --> KonvaLayer --> KonvaGroup --> KonvaShape
        end
        subgraph "Core"
            RenderIndex["Render/index.ts"]:::render
            Types["types.ts"]:::render
            AStar["aStar.ts"]:::render
        end
        State --> GraphDraw
        Tools --> GraphDraw
        GraphDraw --> KonvaStage
        LinkDraw --> KonvaStage
    end

    subgraph "Data Persistence & I/O"
        ImportExportTool --> JSONFiles["JSON Files"]:::io
    end

    subgraph "Build & Deployment"
        Vite["vite.config.ts"]:::pipeline
        HuskyHooks[".husky/*"]:::pipeline
        Commitlint["commitlint.config.js"]:::pipeline
        GHAction["deploy.yml"]:::pipeline
        Vite --> HuskyHooks --> Commitlint --> GHAction
    end

    %% Click Events
    click Entry "https://github.com/xachary/konva-designer-sample/blob/master/src/main.ts"
    click UI_Main "https://github.com/xachary/konva-designer-sample/blob/master/src/App.vue"
    click UI_Play "https://github.com/xachary/konva-designer-sample/blob/master/src/PlayPage.vue"
    click AssetBar "https://github.com/xachary/konva-designer-sample/blob/master/src/components/asset-bar/index.vue"
    click MainHeader "https://github.com/xachary/konva-designer-sample/blob/master/src/components/main-header/index.vue"
    click AlignTool "https://github.com/xachary/konva-designer-sample/blob/master/src/Render/tools/AlignTool.ts"
    click AssetTool "https://github.com/xachary/konva-designer-sample/blob/master/src/Render/tools/AssetTool.ts"
    click AttractTool "https://github.com/xachary/konva-designer-sample/blob/master/src/Render/tools/AttractTool.ts"
    click CopyTool "https://github.com/xachary/konva-designer-sample/blob/master/src/Render/tools/CopyTool.ts"
    click ImportExportTool "https://github.com/xachary/konva-designer-sample/blob/master/src/Render/tools/ImportExportTool.ts"
    click LinkTool "https://github.com/xachary/konva-designer-sample/blob/master/src/Render/tools/LinkTool.ts"
    click PositionTool "https://github.com/xachary/konva-designer-sample/blob/master/src/Render/tools/PositionTool.ts"
    click SelectionTool "https://github.com/xachary/konva-designer-sample/blob/master/src/Render/tools/SelectionTool.ts"
    click ZIndexTool "https://github.com/xachary/konva-designer-sample/blob/master/src/Render/tools/ZIndexTool.ts"
    click DragHandlers "https://github.com/xachary/konva-designer-sample/blob/master/src/Render/handlers/DragHandlers.ts"
    click DragOutsideHandlers "https://github.com/xachary/konva-designer-sample/blob/master/src/Render/handlers/DragOutsideHandlers.ts"
    click GraphHandlers "https://github.com/xachary/konva-designer-sample/blob/master/src/Render/handlers/GraphHandlers.ts"
    click KeyMoveHandlers "https://github.com/xachary/konva-designer-sample/blob/master/src/Render/handlers/KeyMoveHandlers.ts"
    click LinkHandlers "https://github.com/xachary/konva-designer-sample/blob/master/src/Render/handlers/LinkHandlers.ts"
    click SelectionHandlers "https://github.com/xachary/konva-designer-sample/blob/master/src/Render/handlers/SelectionHandlers.ts"
    click ShutcutHandlers "https://github.com/xachary/konva-designer-sample/blob/master/src/Render/handlers/ShutcutHandlers.ts"
    click TextHandlers "https://github.com/xachary/konva-designer-sample/blob/master/src/Render/handlers/TextHandlers.ts"
    click ZoomHandlers "https://github.com/xachary/konva-designer-sample/blob/master/src/Render/handlers/ZoomHandlers.ts"
    click RenderIndex "https://github.com/xachary/konva-designer-sample/blob/master/src/Render/index.ts"
    click AStar "https://github.com/xachary/konva-designer-sample/blob/master/src/Render/utils/aStar.ts"
    click Vite "https://github.com/xachary/konva-designer-sample/blob/master/vite.config.ts"
    click HuskyHooks "https://github.com/xachary/konva-designer-sample/tree/master/.husky/pre-commit"
    click Commitlint "https://github.com/xachary/konva-designer-sample/blob/master/commitlint.config.js"
    click GHAction "https://github.com/xachary/konva-designer-sample/blob/master/.github/workflows/deploy.yml"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#4da3ff,color:#000;
    classDef domain fill:#d4edda,stroke:#28a745,color:#000;
    classDef render fill:#ffe5b4,stroke:#ffae42,color:#000;
    classDef io fill:#e2e3e5,stroke:#6c757d,color:#000;
    classDef pipeline fill:#f8f9fa,stroke:#adb5bd,color:#000;
```
