# geekyghost/comfyui-geekyremb architecture

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

- Interactive diagram: https://gitdiagram.com/geekyghost/comfyui-geekyremb
- Repository: https://github.com/geekyghost/comfyui-geekyremb

## Overview

##### Project Type and Purpose
- Type: A ComfyUI plugin (node suite) for advanced image‐processing tasks
- Purpose: Provide four interconnected custom nodes (Geeky RemB, Animator, Light & Shadow, Keyframe Position) that extend ComfyUI’s graph-based workflow with AI-powered background removal, mask processing, composition, animation, lighting, and shadow effects.

##### Main Architectural Components
a. Host Application Layer
– ComfyUI Core (graph editor, node execution engine, UI)
– Plugin Loader (scans `custom_nodes` and registers Python node definitions)

b. Node Definition Layer (scripts/GeekyRembv2.py)
– GeekyRemB Core Node
– GeekyRemB Animator Node
– GeekyRemB Light & Shadow Node
– GeekyRemB Keyframe Position Node

c. Processing Modules (internal to the node suite)
– Background Removal Module (wraps `rembg` models, chroma keying)
– Mask Processing Module (expansion, contraction, edge detection, blur, small region removal)
– Composition Module (position, scale, aspect ratio, alpha channel management)
– Animation Module (parameter handling, easing, multi-frame orchestration)
– Lighting & Shadow Module (normal mapping, specular, directional light, shadow generation, perspective)
– Keyframe Manager (frame‐specific transforms, interpolation)

d. Shared Infrastructure
– Thread Pool (concurrent frame processing)
– LRU Cache (reuse processed masks/frames)
– Configuration & Metadata (`pyproject.toml`, `requirements.txt`, `.github` workflows)

e. External Dependencies & Models
– Python Packages: `rembg`, `Pillow` (PIL), `numpy`, ComfyUI API
– AI Models: `u2net`, `isnet-anime`, lighter variants
– OS-level: GPU acceleration (optional)

##### Relationships and Data Flows
- User Input (image source files) → ComfyUI UI → Node Graph Editor
- ComfyUI Execution Engine
→ Instantiates Node Definitions (GeekyRemB suite)
→ Passes data buffers (image, mask, parameters)
- Within a single workflow:
1. Input Image → GeekyRemB Core Node
↳ Calls Background Removal → Mask Processing → Composition
2. GeekyRemB Animator Node (optional)
↳ Supplies per‐frame transform & timing parameters
3. GeekyRemB Light & Shadow Node (optional)
↳ Applies lighting & generates shadows
4. GeekyRemB Keyframe Position Node(s) (optional)
↳ Overrides transform at specified frames
5. Frame outputs stored in LRU Cache and delivered to downstream nodes or final output

- Thread Pool manages concurrent execution of multi‐frame tasks.
- LRU Cache intercepts repeated requests for identical input/parameters.

##### Architectural Patterns & Principles
- Plugin Architecture: loose coupling between ComfyUI core and custom nodes
- Graph / Dataflow Pattern: nodes as composable functional units
- Modular Design: each feature set (background removal, animation, lighting) in its own module
- Concurrency & Caching: optimize performance for animations and batch processing
- Dependency Injection: parameter objects injected into processing modules

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Layer
    subgraph "User Interface & Core"
        UI["User Input & ComfyUI UI"]:::major
        Core["ComfyUI Core\n(Graph Editor & Execution Engine)"]:::major
        PluginLoader["Plugin Loader\n(scans custom_nodes)"]:::major
    end

    %% Plugin Node Suite
    subgraph "Plugin Node Suite"
        GeekyNodes["GeekyRemB Node Definitions\n(Core, Animator, Light & Shadow, Keyframe Position)"]:::major
    end

    %% Processing Modules Layer
    subgraph "Processing Modules"
        BgRemoval["Background Removal Module"]:::module
        MaskProc["Mask Processing Module"]:::module
        Composition["Composition Module"]:::module
        AnimationMod["Animation Module"]:::module
        LightingMod["Lighting & Shadow Module"]:::module
        KeyframeMgr["Keyframe Manager"]:::module
    end

    %% Shared Infrastructure
    subgraph "Shared Infrastructure"
        ThreadPool["Thread Pool"]:::infra
        LRUCache["LRU Cache"]:::infra
        subgraph "Configuration & Metadata"
            PyProject["pyproject.toml"]:::infra
            Requirements["requirements.txt"]:::infra
        end
        CI["CI/CD Workflow\n(publish & checks)"]:::infra
        DocsLicense["LICENSE"]:::infra
        DocsReadme["README.md"]:::infra
    end

    %% External Dependencies
    subgraph "External Dependencies & Models"
        PyPackages["Python Packages\n(rembg, Pillow, numpy, ComfyUI API)"]:::external
        AIModels["AI Models\n(u2net, isnet-anime)"]:::external
        GPU["GPU Acceleration"]:::external
    end

    %% Connections
    UI --> Core
    Core -->|"registers Node Definitions"| PluginLoader
    PluginLoader --> GeekyNodes
    Core --> GeekyNodes

    GeekyNodes --> BgRemoval
    BgRemoval --> MaskProc
    MaskProc --> Composition
    Composition --> AnimationMod
    AnimationMod --> LightingMod
    LightingMod --> KeyframeMgr

    %% Concurrency & Caching flows
    ThreadPool --> BgRemoval
    ThreadPool --> AnimationMod
    ThreadPool --> LightingMod
    ThreadPool --> KeyframeMgr

    MaskProc -->|checks cache| LRUCache
    Composition -->|stores/reads cache| LRUCache
    AnimationMod -->|caches frames| LRUCache

    %% External dependencies usage
    PyPackages --> BgRemoval
    AIModels --> BgRemoval
    GPU --> BgRemoval

    %% Infra metadata and workflows
    PluginLoader -.-> PyProject
    PluginLoader -.-> Requirements
    CI -.-> PyProject
    CI -.-> Requirements
    DocsLicense -.-> PyProject
    DocsReadme -.-> PyProject

    %% Click Events
    click GeekyNodes "https://github.com/geekyghost/comfyui-geekyremb/blob/main/scripts/GeekyRembv2.py"
    click PluginLoader "https://github.com/geekyghost/comfyui-geekyremb/blob/main/__init__.py"
    click PyProject "https://github.com/geekyghost/comfyui-geekyremb/blob/main/pyproject.toml"
    click Requirements "https://github.com/geekyghost/comfyui-geekyremb/blob/main/requirements.txt"
    click CI "https://github.com/geekyghost/comfyui-geekyremb/blob/main/.github/workflows/publish.yml"
    click DocsLicense "https://github.com/geekyghost/comfyui-geekyremb/tree/main/LICENSE"
    click DocsReadme "https://github.com/geekyghost/comfyui-geekyremb/blob/main/README.md"

    %% Styles
    classDef major fill:#D0E1FF,stroke:#0366d6,color:#0366d6,stroke-width:2px;
    classDef module fill:#E6F4EA,stroke:#2c662d,color:#2c662d,stroke-width:1px,stroke-dasharray: 5 5;
    classDef infra fill:#FFF4E5,stroke:#d97706,color:#92400e,stroke-width:1px;
    classDef external fill:#F2F2F2,stroke:#6c757d,color:#495057,stroke-width:1px,stroke-dasharray: 2 2;
```
