# new-sankaku/sp-mangaediter architecture

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

- Interactive diagram: https://gitdiagram.com/new-sankaku/sp-mangaediter
- Repository: https://github.com/new-sankaku/sp-mangaediter

## Overview

##### Main Components
- User Interface (UI) Layer:
– The UI is composed of HTML files (index.html, various HTML documents under html/), CSS stylesheets (in css/ with several component-based files), and JavaScript modules (located throughout the js/ folder).
– This layer covers the visual aspects including image drop zones, panel editing, speech bubble customization, prompt helpers, grid lines, and dark/light mode toggles.
- Canvas and Image Management:
– Directories like js/canvas-manager.js, js/layer, js/fabric, and js/ui illustrate the handling of image composition, layer management, drawing tools (pen, scissors/knife tools), and brush effects.
– SVG processing tools (e.g., 01_build/SvgBuilder.py and js/svg/ scripts) support vector-based graphic generation (for panels or speech bubbles).
- API and External Integration Layer:
– The application interfaces with external image-generation backends:
∙ WebUI: Supported by SD1.5, SDXL, and Pony workflows.
∙ Forge: Supporting similar generation schemes plus Flux1.
∙ ComfyUI: With dedicated JSON workflow definitions (in the comufyUI directory) and complementary JavaScript modules under js/ai.
– These integrations are represented in the code via specific workflow scripts and utility functions (see files in js/ai/*, js/db/*, and js/third/* folders).
- Configuration & Resource Components:
– Config files and assets include JSONs for workflow setups, font files (in font/), and preset assets for images (in 02_images_svg/ and 03_images/).
– Additional support files (bats in html/Minual and preset directories) show that some build or conversion scripts assist with resource management.

##### Relationships and Interactions
- The UI Layer initiates user actions (e.g., drag-and-drop, panel adjustments, text insertion) which are captured by event listeners in the JS modules.
- These events trigger image processing and layer adjustments through dedicated canvas managers, which then update the visual state of the editor.
- Returned images or workflow configurations are then handled by further processing such as scaling, cropping, or overlay adjustments within the image manager and canvas modules.
- Auxiliary services like project management (save/load projects) and settings management (js/db/settings-repository.js) provide persistence and configurability, which the UI layer accesses as needed.

##### Architectural Patterns and Technologies
- Modular Design – The project is broken up into clear domains:
∙ UI/rendering components (HTML, CSS, JavaScript in js/ui and js/sidebar)
∙ Image and canvas management (js/canvas-manager, js/fabric, js/layer)
∙ API integration and workflow management (js/ai, comufyUI logs, JSON config files)
- Separation of Concerns – Each directory differentiates parts of the overall functionality (for example, image prompt helpers in js/ui/imagePromptHelper vs. font management in js/core/font).
- Use of External Libraries – Third‑party libraries (such as Fabric.js, glfx, and Tippy.js) that are placed under the third/ directory assist with rendering, image compression, and user interaction enhancements.

##### Additional Notes
- Be as detailed as possible – break the system into all the logical components and sub-components as discovered (UI, canvas, API-integration, external services, resource management).
- Don’t worry about overly granular details (like every single file or script). Instead, concentrate on the core elements and their interactions.

## Diagram (Mermaid)

```mermaid
graph TD
    %% UI Layer – HTML, CSS, JS Components
    subgraph "UI Layer – HTML, CSS, JS Components"
        IndexHTML["Index HTML"]:::ui
        HTMLDir["HTML Directory"]:::ui
        CSSDir["CSS Directory"]:::ui
        JSUIDir["JS UI Modules"]:::ui
        JSUIImagePrompt["JS UI ImagePrompt"]:::ui
    end

    %% Canvas & Image Management
    subgraph "Canvas & Image Management"
        CanvasManager["Canvas Manager"]:::canvas
        LayerManager["Layer Manager"]:::canvas
        FabricIntegration["Fabric Integration"]:::canvas
        PythonSVGBuilder["Python SVG Builder"]:::canvas
        JSSVGTools["JS SVG Tools"]:::canvas
    end

    %% API & External Integration Layer
    subgraph "API & External Integration Layer"
        ComfyUIJSON["ComfyUI JSON Workflows"]:::api
        ComfyUIJS["ComfyUI JS Modules"]:::api
        WebUIIntegration["WebUI & SDWebUI Integration"]:::api
        SharedAIManagement["Shared AI Management"]:::api
    end

    %% Configuration & Resource Components
    subgraph "Configuration & Resource Components"
        JSONConfigs["JSON Configs"]:::config
        Fonts["Fonts"]:::config
        SVGPresets["SVG Presets"]:::config
        ImagePresets["Image Presets"]:::config
        AdditionalTools["Additional Tools"]:::config
    end

    %% Relationships from UI Layer
    JSUIDir -->|"initiates"| CanvasManager
    JSUIDir -->|"triggers"| ComfyUIJSON
    JSUIDir -->|"triggers"| WebUIIntegration
    JSUIDir -->|"triggers"| SharedAIManagement
    JSUIDir -->|"loads"| JSONConfigs

    %% Internal Canvas & Image Management relationships
    CanvasManager -->|"manages"| LayerManager
    CanvasManager -->|"utilizes"| FabricIntegration
    FabricIntegration -->|"invokes"| PythonSVGBuilder
    FabricIntegration -->|"invokes"| JSSVGTools

    %% API Integration returns data to Canvas Manager
    ComfyUIJSON -->|"returns"| CanvasManager
    ComfyUIJS -->|"returns"| CanvasManager
    WebUIIntegration -->|"returns"| CanvasManager
    SharedAIManagement -->|"returns"| CanvasManager

    %% Configuration influences API Management
    JSONConfigs -->|"configures"| SharedAIManagement

    %% Additional resource relationships
    AdditionalTools -->|"assists"| Fonts
    SVGPresets -->|"provides"| CanvasManager
    ImagePresets -->|"provides"| CanvasManager

    %% Styling Classes
    class IndexHTML,HTMLDir,CSSDir,JSUIDir,JSUIImagePrompt ui
    class CanvasManager,LayerManager,FabricIntegration,PythonSVGBuilder,JSSVGTools canvas
    class ComfyUIJSON,ComfyUIJS,WebUIIntegration,SharedAIManagement api
    class JSONConfigs,Fonts,SVGPresets,ImagePresets,AdditionalTools config

click IndexHTML "https://github.com/new-sankaku/sp-mangaediter/blob/main/index.html"
click HTMLDir "https://github.com/new-sankaku/sp-mangaediter/tree/main/html/"
click CSSDir "https://github.com/new-sankaku/sp-mangaediter/tree/main/css/"
click JSUIDir "https://github.com/new-sankaku/sp-mangaediter/tree/main/js/ui/"
click JSUIImagePrompt "https://github.com/new-sankaku/sp-mangaediter/tree/main/js/ui/imagePromptHelper"

click CanvasManager "https://github.com/new-sankaku/sp-mangaediter/blob/main/js/canvas-manager.js"
click LayerManager "https://github.com/new-sankaku/sp-mangaediter/tree/main/js/layer/"
click FabricIntegration "https://github.com/new-sankaku/sp-mangaediter/blob/main/js/fabric/fabric-management.js"
click PythonSVGBuilder "https://github.com/new-sankaku/sp-mangaediter/blob/main/01_build/SvgBuilder.py"
click JSSVGTools "https://github.com/new-sankaku/sp-mangaediter/blob/main/js/svg/manga-panels-image-landscape.js"

click ComfyUIJSON "https://github.com/new-sankaku/sp-mangaediter/tree/main/comufyUI/"
click ComfyUIJS "https://github.com/new-sankaku/sp-mangaediter/tree/main/js/ai/ComfyUI/"
click WebUIIntegration "https://github.com/new-sankaku/sp-mangaediter/tree/main/js/ai/SDWebUI/"
click SharedAIManagement "https://github.com/new-sankaku/sp-mangaediter/blob/main/js/ai/ai-management.js"

click JSONConfigs "https://github.com/new-sankaku/sp-mangaediter/blob/main/json_js/00_base.js"
click Fonts "https://github.com/new-sankaku/sp-mangaediter/tree/main/font/"
click SVGPresets "https://github.com/new-sankaku/sp-mangaediter/tree/main/02_images_svg/"
click ImagePresets "https://github.com/new-sankaku/sp-mangaediter/tree/main/03_images/"
click AdditionalTools "https://github.com/new-sankaku/sp-mangaediter/tree/main/html/Minual/"

classDef ui fill:#AEDFF7,stroke:#000,stroke-width:1px;
classDef canvas fill:#C8E6C9,stroke:#000,stroke-width:1px;
classDef api fill:#FFE082,stroke:#000,stroke-width:1px;
classDef config fill:#D1C4E9,stroke:#000,stroke-width:1px;
```
