How yt-koike/dify-pillow works
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