# yt-koike/dify-pillow architecture

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

- Interactive diagram: https://gitdiagram.com/yt-koike/dify-pillow
- Repository: https://github.com/yt-koike/dify-pillow

## Overview

##### Project Type and Purpose
- This is a standalone “plugin” for the Dify platform, written in Python, that exposes a set of image-editing nodes (Image Info, Get/Set Pixel, Resize, Crop, Rotate, Simple OPs) by wrapping the Pillow library.

##### High-Level Architecture
- The system consists of two major participants:
a. The Dify Host (external service)
b. The dify-pillow Plugin (this codebase)

##### Main Components
1. Dify Host
- Discovers and loads plugins via their manifest.yaml
- Presents the nodes in its UI/workflow editor
- Invokes plugin entrypoints at runtime
2. Plugin Entrypoint (main.py)
- Registers all node handlers with the Dify runtime
- Reads manifest.yaml to advertise plugin metadata and node list
3. Manifest Definitions (manifest.yaml)
- Lists plugin name, version, node identifiers, paths to YAML descriptors
4. Provider Metadata (provider/dify-pillow.*)
- Configuration for publishing on Dify Marketplace
5. Tool Definitions (tools/*.yaml)
- One YAML per node, describing inputs, outputs, parameters, handler function name
6. Tool Implementations (tools/*.py)
- Python functions that implement each node’s logic
- Common helper routines in tools/common.py
- Under the hood these import and call Pillow APIs
7. External Library (Pillow)
- Performs all actual image processing

##### Component Interactions and Data Flow
1. Startup
- Dify Host loads manifest.yaml → spins up plugin process pointing at main.py
2. Node Discovery
- main.py reads each tools/*.yaml → registers each node ID and handler
3. Execution (per node invocation)
- Dify Host sends a JSON/RPC request to plugin: “Run node X with params Y”
- main.py dispatches to the corresponding Python function in tools/
- Python code imports Pillow → modifies or inspects image → writes PNG bytes
- Plugin returns result payload (including image file or metadata) back to host
4. UI Presentation
- Dify Host receives output → renders image or displays info in workflow

##### Architectural Patterns and Principles
- Plugin-host boundary: strict separation of concerns
- Descriptor-driven: node metadata is declared in YAML, decoupled from implementation
- Modular tool implementations: each operation in its own file, common helpers shared
- Minimal external dependencies (only Pillow + Dify plugin SDK)

##### Technologies and Frameworks
- Python 3.x (main.py + tools/*.py)
- YAML (tools/*.yaml, provider/*.yaml, manifest.yaml)
- Pillow (image processing)
- Dify plugin SDK (implicit via main.py entrypoint conventions)

##### Elements
- Clear component labels (“Dify Host,” “Plugin: main.py,” “tools/crop.py,” etc.)
- Host vs Plugin vs External dependencies
- Code vs Config

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Dify Host Zone
    subgraph "Dify Host" 
        style DIFY fill:#cce5ff,stroke:#333,stroke-width:1px
        DIFY["Dify Host"]:::host
        LOAD["Load manifest.yaml"]:::host
        INVOKE["Invoke node X"]:::host
        RENDER["Render result"]:::host
    end

    DIFY -->|loads manifest| LOAD
    DIFY -->|requests execution| INVOKE
    RENDER -->|displays output| DIFY

    %% Plugin Zone
    subgraph "dify-pillow Plugin"
        style PLUG fill:#d4edda,stroke:#333,stroke-width:1px
        %% Manifest & Provider Config
        subgraph "Manifest & Provider Config"
            MANIFEST["manifest.yaml"]:::config
            PROVIDER_PY["dify-pillow.py"]:::config
            PROVIDER_YAML["dify-pillow.yaml"]:::config
        end

        %% Node Descriptors
        subgraph "Tool Definitions (YAML)"
            TI_YAML["tools/image_info.yaml"]:::config
            GP_YAML["tools/get_pixel.yaml"]:::config
            PP_YAML["tools/put_pixel.yaml"]:::config
            NI_YAML["tools/new_image.yaml"]:::config
            RS_YAML["tools/resize.yaml"]:::config
            CR_YAML["tools/crop.yaml"]:::config
            RT_YAML["tools/rotate.yaml"]:::config
            SO_YAML["tools/simple_ops.yaml"]:::config
        end

        %% Code Modules
        subgraph "Code Modules"
            MAIN["main.py"]:::code
            COMMON["tools/common.py"]:::code
            TI_PY["tools/image_info.py"]:::code
            GP_PY["tools/get_pixel.py"]:::code
            PP_PY["tools/put_pixel.py"]:::code
            NI_PY["tools/new_image.py"]:::code
            RS_PY["tools/resize.py"]:::code
            CR_PY["tools/crop.py"]:::code
            RT_PY["tools/rotate.py"]:::code
            SO_PY["tools/simple_ops.py"]:::code
        end

        %% External Library
        PILLOW["Pillow Library"]:::external
    end

    %% Host to Plugin interactions
    LOAD -->|reads| MANIFEST
    INVOKE -->|calls| MAIN

    %% Descriptor registration
    MAIN -->|reads| TI_YAML
    MAIN -->|reads| GP_YAML
    MAIN -->|reads| PP_YAML
    MAIN -->|reads| NI_YAML
    MAIN -->|reads| RS_YAML
    MAIN -->|reads| CR_YAML
    MAIN -->|reads| RT_YAML
    MAIN -->|reads| SO_YAML

    %% Descriptor to implementation
    TI_YAML -->|handler| TI_PY
    GP_YAML -->|handler| GP_PY
    PP_YAML -->|handler| PP_PY
    NI_YAML -->|handler| NI_PY
    RS_YAML -->|handler| RS_PY
    CR_YAML -->|handler| CR_PY
    RT_YAML -->|handler| RT_PY
    SO_YAML -->|handler| SO_PY

    %% Helpers
    TI_PY --> COMMON
    GP_PY --> COMMON
    PP_PY --> COMMON
    NI_PY --> COMMON
    RS_PY --> COMMON
    CR_PY --> COMMON
    RT_PY --> COMMON
    SO_PY --> COMMON

    %% Processing flow
    MAIN -->|invokes function| TI_PY
    MAIN -->|invokes function| GP_PY
    MAIN -->|invokes function| PP_PY
    MAIN -->|invokes function| NI_PY
    MAIN -->|invokes function| RS_PY
    MAIN -->|invokes function| CR_PY
    MAIN -->|invokes function| RT_PY
    MAIN -->|invokes function| SO_PY

    TI_PY -->|calls| PILLOW
    GP_PY -->|calls| PILLOW
    PP_PY -->|calls| PILLOW
    NI_PY -->|calls| PILLOW
    RS_PY -->|calls| PILLOW
    CR_PY -->|calls| PILLOW
    RT_PY -->|calls| PILLOW
    SO_PY -->|calls| PILLOW

    %% Return to Host
    PILLOW -->|returns image/metadata| MAIN
    MAIN -->|returns result| RENDER

    %% Click Events
    click MANIFEST "https://github.com/yt-koike/dify-pillow/blob/main/manifest.yaml"
    click PROVIDER_PY "https://github.com/yt-koike/dify-pillow/blob/main/provider/dify-pillow.py"
    click PROVIDER_YAML "https://github.com/yt-koike/dify-pillow/blob/main/provider/dify-pillow.yaml"
    click TI_YAML "https://github.com/yt-koike/dify-pillow/blob/main/tools/image_info.yaml"
    click GP_YAML "https://github.com/yt-koike/dify-pillow/blob/main/tools/get_pixel.yaml"
    click PP_YAML "https://github.com/yt-koike/dify-pillow/blob/main/tools/put_pixel.yaml"
    click NI_YAML "https://github.com/yt-koike/dify-pillow/blob/main/tools/new_image.yaml"
    click RS_YAML "https://github.com/yt-koike/dify-pillow/blob/main/tools/resize.yaml"
    click CR_YAML "https://github.com/yt-koike/dify-pillow/blob/main/tools/crop.yaml"
    click RT_YAML "https://github.com/yt-koike/dify-pillow/blob/main/tools/rotate.yaml"
    click SO_YAML "https://github.com/yt-koike/dify-pillow/blob/main/tools/simple_ops.yaml"
    click MAIN "https://github.com/yt-koike/dify-pillow/blob/main/main.py"
    click TI_PY "https://github.com/yt-koike/dify-pillow/blob/main/tools/image_info.py"
    click GP_PY "https://github.com/yt-koike/dify-pillow/blob/main/tools/get_pixel.py"
    click PP_PY "https://github.com/yt-koike/dify-pillow/blob/main/tools/put_pixel.py"
    click NI_PY "https://github.com/yt-koike/dify-pillow/blob/main/tools/new_image.py"
    click RS_PY "https://github.com/yt-koike/dify-pillow/blob/main/tools/resize.py"
    click CR_PY "https://github.com/yt-koike/dify-pillow/blob/main/tools/crop.py"
    click RT_PY "https://github.com/yt-koike/dify-pillow/blob/main/tools/rotate.py"
    click SO_PY "https://github.com/yt-koike/dify-pillow/blob/main/tools/simple_ops.py"
    click COMMON "https://github.com/yt-koike/dify-pillow/blob/main/tools/common.py"

    %% Styles
    classDef host fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef plugin fill:#d4edda,stroke:#333,stroke-width:1px
    classDef external fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef config fill:#e2e3e5,stroke:#666,stroke-width:1px
    classDef code fill:#d4edda,stroke:#666,stroke-width:1px
```
