# lrzjason/comfyui-qweneditutils architecture

> Architecture diagram of the GitHub repository lrzjason/comfyui-qweneditutils, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lrzjason/comfyui-qweneditutils
- Repository: https://github.com/lrzjason/comfyui-qweneditutils

## Overview

1. **Repository role**
   - This is a **ComfyUI custom node extension** for Qwen-based image editing.
   - The repo is intentionally small: the core runtime logic appears to live in `nodes.py`, with `README.md` documenting the node contract and several ComfyUI workflow JSONs serving as usage examples.

2. **Primary execution boundary**
   - The package boundary is a **single Python node module** exposed to ComfyUI.
   - Inputs are standard ComfyUI data types such as `clip`, `vae`, `image`, `mask`, `conditioning`, and latent outputs; outputs are designed to plug directly into downstream ComfyUI nodes.

3. **Main subsystem: image-edit encoding nodes**
   - The central subsystem is a family of text-encoding nodes named `TextEncodeQwenImageEditPlus*`.
   - These nodes combine a text prompt with one or more reference images and convert them into:
     - **conditioning tensors** for the model
     - **latents** from reference images via VAE
     - processed images for further workflow use
   - They differ mainly in how much control they expose over resizing, cropping, image selection, and per-image configuration.

4. **Workflow shape and data flow**
   - The core flow is:
     - prompt + reference images + CLIP/VAE models
     - image preprocessing
     - optional VAE encoding to latent space
     - construction of conditioning payloads
     - downstream sampling / generation in ComfyUI
   - The custom node variants are mainly about shaping the reference images before they reach Qwen’s image-edit pipeline.

5. **Reference-image preprocessing layer**
   - A major architectural concern in this repo is **normalizing reference images** before encoding.
   - The nodes support:
     - resizing to target edges or fixed sizes
     - different upscale methods
     - center/pad/disabled cropping behaviors
     - separate handling for VAE-sized images and vision-language-sized images
   - This preprocessing layer is what makes the nodes useful for controlled editing rather than plain text prompting.

6. **Configuration-building subsystem**
   - The repo includes helper nodes that generate reusable config objects for the custom encoder:
     - `QwenEditConfigPreparer`
     - `QwenEditConfigJsonParser`
   - These act as a configuration assembly layer, letting a workflow build a list of per-image settings before passing them into the custom encoder node.
   - This is an explicit architectural boundary between **configuration definition** and **encoding execution**.

7. **Custom-output and extraction layer**
   - `TextEncodeQwenImageEditPlusCustom_lrzjason` returns a rich dictionary-like `custom_output` object containing intermediate artifacts.
   - `QwenEditOutputExtractor` exists to split that composite output back into individual streams such as:
     - pad metadata
     - full vs. main-reference conditioning
     - processed images
     - reference latents
     - prompt/template information
     - mask output
   - This keeps the main encoder flexible while still making the outputs usable in smaller ComfyUI graph segments.

8. **Utility nodes for workflow composition**
   - `QwenEditListExtractor` is a simple composition helper for selecting one item from a list output.
   - `QwenEditAdaptiveLongestEdge` computes a safe longest-edge value from an image, which helps avoid oversizing during preprocessing.
   - `CropWithPadInfo` uses stored padding metadata to restore the original content region after padded processing.
   - These utilities indicate the repo is optimized for **graph wiring and post-processing**, not just encoding.

9. **Mask support and region focus**
   - Newer workflows support **mask-aware editing**.
   - Masks can be attached at the config level and propagated through the custom output.
   - This introduces a region-of-interest boundary into the preprocessing pipeline, enabling localized edits rather than full-image guidance.

10. **Example workflows as architecture documentation**
   - The JSON files in the root are not runtime code, but they are important architectural artifacts:
     - `qwen edit custom.json`
     - `qwen edit custom mask.json`
     - `qwen edit custom face ref.json`
     - `qe2511 consis lora comparer.json`
   - They show how the nodes are meant to be connected in ComfyUI and reveal the intended data flow between configuration builders, encoders, and downstream image-edit nodes.

11. **Packaging and release mechanics**
   - `pyproject.toml` suggests the repo is packaged as a Python project for installation into ComfyUI’s `custom_nodes` directory.
   - `.github/workflows/publish.yml` indicates release automation, likely for publishing packaged updates.
   - Operationally, this means the repo is meant to be dropped into a ComfyUI environment rather than run as a standalone service.

12. **External dependency boundary**
   - The repo depends on the **ComfyUI runtime** and its model abstractions, especially CLIP and VAE interfaces.
   - The node logic is specialized for **Qwen image-editing workflows** and is explicitly documented as superseded by `ComfyUI-EditUtils`, which expands the same architectural pattern to additional models.

Main entry points: [`nodes.py`](https://github.com/lrzjason/comfyui-qweneditutils/blob/master/nodes.py) (Node module), [`__init__.py`](https://github.com/lrzjason/comfyui-qweneditutils/blob/master/__init__.py) (Entry point), [`pyproject.toml`](https://github.com/lrzjason/comfyui-qweneditutils/blob/master/pyproject.toml) (Pyproject), [`qwen edit custom.json`](https://github.com/lrzjason/comfyui-qweneditutils/blob/HEAD/qwen%20edit%20custom.json) (Custom workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_runtime["Runtime"]
  node_comfyui["ComfyUI<br/>host runtime"]
  node_init["Entry point<br/>[__init__.py]"]
  node_nodes_mod["Node module<br/>python module<br/>[nodes.py]"]
  node_enc_basic["Edit encode<br/>node family"]
  node_enc_custom["Custom encode<br/>node variant"]
  node_preprocess{{"Preprocess<br/>image pipeline"}}
  node_vae_encode(("VAE encode<br/>latent step"))
  node_conditioning(("Conditioning<br/>payload step"))
  node_mask_flow(("Mask flow<br/>region support"))
end

subgraph group_grp_config["Config"]
  node_cfg_preparer["Config preparer<br/>config node"]
  node_cfg_parser["JSON parser<br/>config node"]
  node_out_extract["Output extractor<br/>helper node"]
  node_item_pick["List picker<br/>helper node"]
  node_edge_calc(("Edge calc<br/>helper node"))
  node_pad_restore["Pad restore<br/>helper node"]
end

subgraph group_grp_examples["Examples"]
  node_wf_custom["Custom workflow<br/>example workflow"]
  node_wf_mask["Mask workflow<br/>example workflow"]
  node_wf_face["Face ref<br/>example workflow"]
  node_wf_compare["Comparer workflow<br/>example workflow"]
end

subgraph group_grp_packaging["Packaging"]
  node_readme["README<br/>docs<br/>[README.md]"]
  node_pyproject["Pyproject<br/>package config<br/>[pyproject.toml]"]
  node_publish["Publish CI<br/>workflow<br/>[publish.yml]"]
end

node_comfyui -->|"loads"| node_init
node_init -->|"registers"| node_nodes_mod
node_nodes_mod -->|"defines"| node_enc_basic
node_nodes_mod -->|"defines"| node_enc_custom
node_nodes_mod -->|"defines"| node_cfg_preparer
node_nodes_mod -->|"defines"| node_cfg_parser
node_nodes_mod -->|"defines"| node_out_extract
node_nodes_mod -->|"defines"| node_item_pick
node_nodes_mod -->|"defines"| node_edge_calc
node_nodes_mod -->|"defines"| node_pad_restore
node_cfg_preparer -->|"feeds"| node_preprocess
node_cfg_parser -->|"assembles"| node_cfg_preparer
node_enc_basic -->|"uses"| node_preprocess
node_preprocess -->|"prepares"| node_vae_encode
node_enc_basic -->|"builds"| node_conditioning
node_enc_custom -->|"builds"| node_conditioning
node_enc_custom -->|"includes"| node_vae_encode
node_mask_flow -->|"extends"| node_cfg_preparer
node_mask_flow -->|"propagates"| node_enc_custom
node_out_extract -->|"reads"| node_enc_custom
node_out_extract -->|"exposes"| node_pad_restore
node_out_extract -->|"exposes"| node_conditioning
node_out_extract -->|"exposes"| node_vae_encode
node_item_pick -->|"selects"| node_out_extract
node_edge_calc -->|"bounds"| node_preprocess
node_pad_restore -->|"reverses"| node_preprocess
node_readme -->|"documents"| node_nodes_mod
node_wf_custom -->|"demonstrates"| node_enc_basic
node_wf_mask -->|"demonstrates"| node_mask_flow
node_wf_face -->|"demonstrates"| node_cfg_preparer
node_wf_compare -->|"demonstrates"| node_enc_custom
node_pyproject -->|"packages"| node_nodes_mod
node_publish -->|"releases"| node_pyproject

click node_init "https://github.com/lrzjason/comfyui-qweneditutils/blob/master/__init__.py"
click node_nodes_mod "https://github.com/lrzjason/comfyui-qweneditutils/blob/master/nodes.py"
click node_wf_custom "https://github.com/lrzjason/comfyui-qweneditutils/blob/master/qwen edit custom.json"
click node_wf_mask "https://github.com/lrzjason/comfyui-qweneditutils/blob/master/qwen edit custom mask.json"
click node_wf_face "https://github.com/lrzjason/comfyui-qweneditutils/blob/master/qe2511 edit face ref.json"
click node_wf_compare "https://github.com/lrzjason/comfyui-qweneditutils/blob/master/qe2511 consis lora comparer.json"
click node_readme "https://github.com/lrzjason/comfyui-qweneditutils/blob/master/README.md"
click node_pyproject "https://github.com/lrzjason/comfyui-qweneditutils/blob/master/pyproject.toml"
click node_publish "https://github.com/lrzjason/comfyui-qweneditutils/blob/master/.github/workflows/publish.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_comfyui,node_init,node_nodes_mod,node_enc_basic,node_enc_custom,node_preprocess,node_vae_encode,node_conditioning,node_mask_flow toneBlue
class node_cfg_preparer,node_cfg_parser,node_out_extract,node_item_pick,node_edge_calc,node_pad_restore toneAmber
class node_wf_custom,node_wf_mask,node_wf_face,node_wf_compare toneMint
class node_readme,node_pyproject,node_publish toneRose
```

## Components

### Runtime

ComfyUI-facing extension code and node logic

- **ComfyUI**: host runtime · External ComfyUI environment that loads the custom nodes
- [Entry point](https://github.com/lrzjason/comfyui-qweneditutils/blob/master/__init__.py): module · Package registration and export surface · `__init__.py`
- [Node module](https://github.com/lrzjason/comfyui-qweneditutils/blob/master/nodes.py): python module · Core implementation for Qwen edit nodes and helpers · `nodes.py`
- **Edit encode**: node family · Prompt-plus-reference-image encoding nodes with preprocessing and latent construction
- **Custom encode**: node variant · Rich encoder variant that emits a composite custom output payload
- **Preprocess**: image pipeline · Resizing, cropping, upscaling, and normalization of reference images
- **VAE encode**: latent step · Encodes prepared reference images into latent space
- **Conditioning**: payload step · Builds text and image conditioning for downstream sampling
- **Mask flow**: region support · Carries mask-aware region focus through config and output

### Config

Config assembly and output decomposition helpers

- **Config preparer**: config node · Builds reusable per-image configuration objects for the encoder
- **JSON parser**: config node · Parses config JSON into structured edit settings
- **Output extractor**: helper node · Splits composite custom output into smaller streams
- **List picker**: helper node · Selects one item from a list output
- **Edge calc**: helper node · Derives a safe longest-edge value from an image
- **Pad restore**: helper node · Restores original content region using stored pad metadata

### Examples

Workflow JSONs showing intended ComfyUI wiring

- [Custom workflow](https://github.com/lrzjason/comfyui-qweneditutils/blob/HEAD/qwen%20edit%20custom.json): example workflow · Baseline example of the custom Qwen edit graph · `qwen edit custom.json`
- [Mask workflow](https://github.com/lrzjason/comfyui-qweneditutils/blob/HEAD/qwen%20edit%20custom%20mask.json): example workflow · Example showing mask-aware editing · `qwen edit custom mask.json`
- [Face ref](https://github.com/lrzjason/comfyui-qweneditutils/blob/HEAD/qe2511%20edit%20face%20ref.json): example workflow · Example workflow centered on a face reference image · `qe2511 edit face ref.json`
- [Comparer workflow](https://github.com/lrzjason/comfyui-qweneditutils/blob/HEAD/qe2511%20consis%20lora%20comparer.json): example workflow · Comparison workflow for consistency LoRA setups · `qe2511 consis lora comparer.json`

### Packaging

Project metadata and release automation

- [README](https://github.com/lrzjason/comfyui-qweneditutils/blob/master/README.md): docs · Documents node contracts, usage, and architecture · `README.md`
- [Pyproject](https://github.com/lrzjason/comfyui-qweneditutils/blob/master/pyproject.toml): package config · Python packaging metadata for ComfyUI installation · `pyproject.toml`
- [Publish CI](https://github.com/lrzjason/comfyui-qweneditutils/blob/master/.github/workflows/publish.yml): workflow · GitHub Actions release automation · `.github/workflows/publish.yml`

## Connections

- ComfyUI → Entry point: loads · ComfyUI imports the package entry point
- Entry point → Node module: registers · Entry point exposes the node implementations
- Node module → Edit encode: defines · Core module contains the Qwen edit encoder family
- Node module → Custom encode: defines · Core module contains the composite-output encoder variant
- Node module → Config preparer: defines · Core module provides config assembly helpers
- Node module → JSON parser: defines · Core module provides JSON-to-config parsing
- Node module → Output extractor: defines · Core module provides output splitting helpers
- Node module → List picker: defines · Core module provides list selection helper
- Node module → Edge calc: defines · Core module provides adaptive edge calculation
- Node module → Pad restore: defines · Core module provides pad-aware restoration helper
- Config preparer → Preprocess: feeds · Prepared config drives image normalization settings
- JSON parser → Config preparer: assembles · Parsed JSON becomes reusable edit config objects
- Edit encode → Preprocess: uses · Reference images are resized and cropped before encoding
- Preprocess → VAE encode: prepares · Normalized images are sent to VAE latent encoding
- Edit encode → Conditioning: builds · Encoder turns prompt plus references into conditioning payloads
- Custom encode → Conditioning: builds · Custom encoder emits conditioning in a composite output
- Custom encode → VAE encode: includes · Custom output carries reference latents from the VAE path
- Mask flow → Config preparer: extends · Mask metadata can be attached during config assembly
- Mask flow → Custom encode: propagates · Mask-aware data survives through the custom output boundary
- Output extractor → Custom encode: reads · Extractor splits the rich custom output object
- Output extractor → Pad restore: exposes · Extractor can surface pad metadata for later restoration
- Output extractor → Conditioning: exposes · Extractor can surface conditioning streams separately
- Output extractor → VAE encode: exposes · Extractor can surface reference latents separately
- List picker → Output extractor: selects · List helper supports composing extracted streams
- Edge calc → Preprocess: bounds · Adaptive edge sizing helps avoid oversized preprocessing
- Pad restore → Preprocess: reverses · Pad metadata is used to restore the original content region
- README → Node module: documents · README describes the node contract and workflow patterns
- Custom workflow → Edit encode: demonstrates · Example graph shows the standard custom encoding flow
- Mask workflow → Mask flow: demonstrates · Example graph shows mask-aware workflow wiring
- Face ref → Config preparer: demonstrates · Face-reference example demonstrates configuration-driven editing
- Comparer workflow → Custom encode: demonstrates · Comparison workflow exercises the custom output variant
- Pyproject → Node module: packages · Packaging metadata targets the custom node module
- Publish CI → Pyproject: releases · GitHub Actions workflow automates publishing the package
