# piyushk52/comfy_runner architecture

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

- Interactive diagram: https://gitdiagram.com/piyushk52/comfy_runner
- Repository: https://github.com/piyushk52/comfy_runner

## Overview

##### Main Components

a) Core Components:
- Workflow Manager (ComfyRunner class)
- Model Manager
- Node Manager
- Server Controller
- File Handler

b) External Components:
- ComfyUI Backend
- Model Sources (Civit, HuggingFace, Replicate, Extra Comfy)
- Custom Nodes Repository

**┌─ Client Layer ─────────────────────────────┐**

- User Code / API Interface                │

- Core Layer ──────────────────────────────┤

- ┌─ Workflow Manager ─┐  ┌─ File Handler ┐│
- (ComfyRunner)    │  │              ││
- ┬─┘  └──────────────┘│

- ┌─ Model Manager ──┤   ┌─ Node Manager ┐│

- ┘   └───────────────┘│

- ┌─ Server Controller ┐ ┌─ Utils ────────┤
- Logger       ││
- ┘ │ - Status      ││
- Tracker      ││
- ┘│
- External Layer ───────────────────────────┤

- ┌─ ComfyUI ─────┐  ┌─ Model Sources ───┐│
- Backend       │  │ - Civit           ││
- HuggingFace     ││
- ┘  │ - Replicate       ││
- Extra Comfy      ││
- ┬─┘│
- ┘

##### Important Relationships

- Data flow from workflow input to ComfyRunner
- Model Manager interactions with external model sources
- Node Manager interactions with custom node repositories
- Server Controller managing ComfyUI backend
- File Handler managing workflow files and outputs

##### Technical Details

- Supported file formats (API JSON)
- Model source endpoints
- Output handling paths
- Server management states

##### Notes for Implementation

- Use standardized UML notation where applicable
- Keep component relationships clear and uncluttered
- Version/commit hash handling
- Client ID tracking mechanism
- Where configuration files are used

Remember to include the key features:
- Automatic node installation
- Model downloading and management
- Server lifecycle management
- Workflow execution pipeline
- Status tracking and logging

This system design should help developers understand how the components interact and how the tool automates the ComfyUI workflow setup and execution process.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        API[User Code / API Interface]
    end

    subgraph Core
        WM[Workflow Manager]
        MM[Model Manager]
        NM[Node Manager]
        SC[Server Controller]
        FH[File Handler]
        
        subgraph Utils
            LOG[Logger]
            ST[Status Tracker]
            CF[Constants & Config]
            UF[Utility Functions]
        end
    end

    subgraph External
        CB[ComfyUI Backend]
        
        subgraph "Model Sources"
            CIV[Civit]
            HF[HuggingFace]
            REP[Replicate]
            EC[Extra Comfy]
        end
        
        CN[Custom Nodes Repository]
    end

    %% Relationships
    API --> WM
    WM --> MM
    WM --> NM
    WM --> SC
    WM --> FH
    MM --> CIV
    MM --> HF
    MM --> REP
    MM --> EC
    NM --> CN
    SC --> CB
    
    %% Utility Connections
    WM --> LOG
    WM --> ST
    WM --> CF
    WM --> UF
    
    %% Click Events
    click WM "https://github.com/piyushK52/comfy_runner/blob/main/main.py"
    click NM "https://github.com/piyushK52/comfy_runner/blob/main/utils/node_installer.py"
    click FH "https://github.com/piyushK52/comfy_runner/blob/main/utils/file_downloader.py"
    click SC "https://github.com/piyushK52/comfy_runner/blob/main/utils/comfy/api.py"
    click LOG "https://github.com/piyushK52/comfy_runner/blob/main/utils/logger.py"
    click ST "https://github.com/piyushK52/comfy_runner/blob/main/utils/gen_status_tracker.py"
    click CB "https://github.com/piyushK52/comfy_runner/tree/main/utils/comfy/"
    click UF "https://github.com/piyushK52/comfy_runner/blob/main/utils/common.py"
    click CF "https://github.com/piyushK52/comfy_runner/blob/main/constants.py"
    click CIV "https://github.com/piyushK52/comfy_runner/blob/main/data/civit_model_weights.json"
    click HF "https://github.com/piyushK52/comfy_runner/blob/main/data/huggingface_weights.json"
    click REP "https://github.com/piyushK52/comfy_runner/blob/main/data/replicate_model_weights.json"
    click EC "https://github.com/piyushK52/comfy_runner/blob/main/data/extra_comfy_weights.json"
    
    %% Styling
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:1px
    classDef core fill:#ddf1fd,stroke:#333
    classDef external fill:#e1f7d5,stroke:#333
    classDef utils fill:#fff2cc,stroke:#333
    
    class WM,MM,NM,SC,FH core
    class CB,CIV,HF,REP,EC,CN external
    class LOG,ST,CF,UF utils
    
    %% Legend
    subgraph Legend
        L1[Core Component]:::core
        L2[External Service]:::external
        L3[Utility Component]:::utils
    end
```
