# heisenshark/blender-krita-link-plugin architecture

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

- Interactive diagram: https://gitdiagram.com/heisenshark/blender-krita-link-plugin
- Repository: https://github.com/heisenshark/blender-krita-link-plugin

## Overview

##### Project Type and Purpose
- This project is a plugin that bridges functionality between Blender and Krita – primarily to allow seamless texture editing by linking Blender’s textures with Krita files.
- The README explains that it is split into two main parts: the Blender add-on and the Krita plugin (with an optional C++ component for advanced UV selection). Its purpose is to synchronize image data and UV maps between the two applications.

##### Analyzing the File Structure
- Notice two main top-level “components”: the Blender side (directories named “BlenderKritaLink”) and the Krita side (directories and files under “KritaBlenderLink” and “KritaBlenderLink.desktop”).
- There are separate Python modules for connection handling, image management, UI definitions, and specific actions. For example:
- The Python modules (e.g., connection.py, image_manager.py, uv_extractor.py, watch.py) in the BlenderKritaLink directory represent the backend logic for the Blender part.
- In the KritaBlenderLink directory, there are UI components (e.g., .ui files, ImageItem.py, ImageList.py) and additional settings and action scripts.
- A separate directory “cppPart” includes a subdirectory “uv-select” with C++ source files and associated build files that extend functionality – particularly for selecting UV faces.

##### README Insight
- The README clarifies the deployment separation: one part goes to Blender’s addons directory and the other to Krita’s plugin directory.

a. Main Components:
- BLENDER PLUGIN:
- Components: Core Python modules (e.g., connection.py, image_manager.py, uv_extractor.py, watch.py) that handle communication and image/UV data management.
- KRITA PLUGIN:
- Components: Python UI components (e.g., ImageList, ImageItem), settings, actions, and connection logic.
- OPTIONAL C++ UVSelection Module:
- Components: The “uv-select” module (UvSelect.cpp, UvSelect.h) that integrates with Krita for UV face selection.
- CONNECTIVITY LAYER:
- Component: The connection module (present in both BlenderKritaLink and KritaBlenderLink directories) forming the link between Blender and Krita.

b. Relationships and Interactions:
- That when a user triggers an action in Krita (e.g., “Send Data” or “Select” for UV maps), it communicates with Blender via the connection module.
- If the optional C++ module is installed, highlight that the Krita plugin calls into this module to enhance UV selection capabilities.

c. Architectural Patterns and Design Principles:
- The system exhibits a plugin-based architecture with clear separation of concerns:
- The Blender and Krita sides operate as independent plugins integrated into their respective hosts.
- Use of a dedicated connection module in both environments hints at a loosely coupled design.
- The design favors modularity: UI, connection logic, and business logic (image management and UV extraction) are segmented into their own modules.
- Use of platform APIs (Blender’s Add-ons, Krita’s Python Plugin Manager) and native extensions in C++.

d. Relevant Technologies, Frameworks, or Libraries:
- Python as the main language for both parts of the plugin.
- Qt (implied by the .ui files used for Krita interfaces).
- C++ for the Optional UV selection module.
- Build system for C++ (CMake via the CMakeLists.txt in cppPart/uv-select).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Blender Plugin Subgraph
    subgraph "Blender Plugin"
        B_UI["Blender UI Components"]:::blender
        B_Conn["Blender Connection Module"]:::blender
        B_Image["Blender Image Management Module"]:::blender
        B_UV["Blender UV Extraction Module"]:::blender
        B_Watch["Blender Watch Module"]:::blender
    end

    %% Krita Plugin Subgraph
    subgraph "Krita Plugin"
        K_UI["Krita UI Components"]:::krita
        K_Conn["Krita Connection Module"]:::krita
        K_Main["Krita Main Logic"]:::krita
        K_Actions["Krita Actions"]:::krita
        K_Settings["Krita Settings"]:::krita
    end

    %% Optional C++ UVSelection Module Subgraph
    subgraph "Optional C++ UVSelection Module"
        UV_Select["C++ UVSelect Module"]:::cpp
    end

    %% Connections within Blender Plugin
    B_UI -->|"triggers"| B_Conn
    B_Conn -->|"updates"| B_Image
    B_Conn -->|"extracts"| B_UV
    B_Conn -->|"monitors"| B_Watch

    %% Connections within Krita Plugin
    K_UI -->|"sendsData"| K_Conn
    K_UI -->|"triggers"| K_Actions
    K_Conn -->|"processes"| K_Main
    K_Actions -->|"executes"| K_Conn

    %% Bidirectional Communication between Blender and Krita
    B_Conn -->|"connectsTo"| K_Conn
    K_Conn -->|"connectsBack"| B_Conn

    %% Connection from Krita Main to Optional C++ Module
    K_Main -->|"callsUV"| UV_Select

    %% Click Events
    click B_Conn "https://github.com/heisenshark/blender-krita-link-plugin/blob/master/BlenderKritaLink/connection.py"
    click B_Image "https://github.com/heisenshark/blender-krita-link-plugin/blob/master/BlenderKritaLink/image_manager.py"
    click B_UV "https://github.com/heisenshark/blender-krita-link-plugin/blob/master/BlenderKritaLink/uv_extractor.py"
    click B_Watch "https://github.com/heisenshark/blender-krita-link-plugin/blob/master/BlenderKritaLink/watch.py"
    click B_UI "https://github.com/heisenshark/blender-krita-link-plugin/tree/master/BlenderKritaLink/ui/"

    click K_UI "https://github.com/heisenshark/blender-krita-link-plugin/tree/master/KritaBlenderLink/ui/"
    click K_Conn "https://github.com/heisenshark/blender-krita-link-plugin/blob/master/KritaBlenderLink/connection.py"
    click K_Main "https://github.com/heisenshark/blender-krita-link-plugin/blob/master/KritaBlenderLink/blender_krita_link.py"
    click K_Actions "https://github.com/heisenshark/blender-krita-link-plugin/blob/master/KritaBlenderLink/actions/KritaBlenderLink.action"
    click K_Settings "https://github.com/heisenshark/blender-krita-link-plugin/blob/master/KritaBlenderLink/settings.py"

    click UV_Select "https://github.com/heisenshark/blender-krita-link-plugin/tree/master/cppPart/uv-select/"

    %% Styles
    classDef blender fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef krita fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef cpp fill:#FFB6C1,stroke:#000,stroke-width:2px;
```
