# kijai/comfyui-promptrelay architecture

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

- Interactive diagram: https://gitdiagram.com/kijai/comfyui-promptrelay
- Repository: https://github.com/kijai/comfyui-promptrelay

## Overview

#### Purpose
ComfyUI Prompt-Relay is a work-in-progress custom-node extension for creating time-segmented text-conditioning prompts for video workflows. It converts a multi-segment prompt into conditioning distributed over a video’s latent-frame timeline, with an automatic “Smart” authoring mode. Primary extension modules are `nodes.py`, `prompt_relay.py`, and `smart_nodes.py`.

#### ComfyUI Entry and Node Surface
ComfyUI discovers the extension through its Python package root and node registration layer:
- `__init__.py`
- `nodes.py`

The node implementation is split between conventional Prompt Relay behavior in `prompt_relay.py` and automatic segment/frame allocation in `smart_nodes.py`. `advanced_options.py` likely supplies the additional node options exposed alongside the main encode behavior.

#### Smart Prompt Parsing Stage
The Smart node accepts one `smart_prompt` input and supports two mutually exclusive source formats:
- Inline segments separated by `|`
- Block segments introduced by numbered/ranged headers

`parser.py` is the architectural boundary that should turn raw author text into ordered segment text plus optional relative weights. Range annotations represent proportional spans rather than literal output-frame counts; ordinal block headers result in equal weighting. Optional word-number parsing is enabled by the `word2number` dependency declared in `requirements.txt`.

#### Allocation and Conditioning Flow
The core flow is: user prompt → parsed segments and weights → allocation across the workflow’s latent frames → encoded segment conditioning. `smart_nodes.py` owns the automatic allocation concept described by the Smart node, while `prompt_relay.py` represents the lower-level relay/conditioning mechanism.

A `global_prompt` provides persistent visual context across every segment. If empty, the first segment becomes the global anchor. The `normalize_by_tokens` option changes allocation by multiplying segment weights by CLIP token counts, making tokenization an important boundary between parsed prompt text and frame assignment.

#### Timeline and Frontend Integration
The extension includes a browser-side timeline component:
- `web/js/prompt_relay_timeline.js`

This is the UI boundary for visualizing or editing the relay timeline within ComfyUI, complementing the Python node execution path. Timeline-oriented example workflows are provided in:
- `example_workflows/prompt_relay_test.json`
- `example_workflows/prompt_relay_ltx23_test_02.json`

#### Patches and Compatibility Boundary
`patches.py` is a distinct integration point, indicating behavior may be adapted or patched around host/runtime functionality rather than being entirely self-contained. Changes affecting prompt encoding, latent-frame handling, or node interoperability should be traced through:
- `patches.py`
- `prompt_relay.py`
- `nodes.py`

#### Runtime Dependencies and Assets
The runtime is Python inside ComfyUI, with JavaScript executed in ComfyUI’s web frontend. Package dependencies are defined in `requirements.txt`; `word2number` is optional but extends block-header parsing. UI/documentation assets reside under `assets`, including images for the Smart nodes and timeline.

Main entry points: [`nodes.py`](https://github.com/kijai/comfyui-promptrelay/blob/main/nodes.py) (Node registration), [`prompt_relay.py`](https://github.com/kijai/comfyui-promptrelay/blob/main/prompt_relay.py) (Prompt relay), [`smart_nodes.py`](https://github.com/kijai/comfyui-promptrelay/blob/main/smart_nodes.py) (Smart node), [`__init__.py`](https://github.com/kijai/comfyui-promptrelay/blob/main/__init__.py) (Package entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Python extension"]
  node_package["Package entry<br/>Python package<br/>[__init__.py]"]
  node_registration["Node registration<br/>node surface<br/>[nodes.py]"]
  node_smart_node["Smart node<br/>automatic allocation<br/>[smart_nodes.py]"]
  node_parser["Prompt parser<br/>parsing boundary<br/>[parser.py]"]
  node_word_numbers["Word-number support<br/>optional dependency<br/>[requirements.txt]"]
  node_relay["Prompt relay<br/>conditioning engine<br/>[prompt_relay.py]"]
  node_options["Advanced options<br/>node options"]
  node_patches["Compatibility patches<br/>host integration<br/>[patches.py]"]
end

subgraph group_frontend["ComfyUI frontend"]
  node_timeline["Relay timeline UI<br/>browser component"]
end

subgraph group_examples["Examples and assets"]
  node_workflow_a["Prompt Relay workflow<br/>example workflow"]
  node_workflow_b["LTX23 workflow<br/>example workflow"]
  node_assets["UI assets<br/>images and docs"]
end

node_comfyui{{"ComfyUI host<br/>host runtime"}}

node_comfyui -->|"discovers"| node_package
node_package -->|"loads"| node_registration
node_registration -->|"registers"| node_smart_node
node_registration -->|"registers"| node_relay
node_registration -->|"exposes"| node_options
node_smart_node -->|"parses smart_prompt"| node_parser
node_parser -.->|"optionally uses"| node_word_numbers
node_smart_node -->|"allocates segments and frames"| node_relay
node_options -->|"configures encoding"| node_relay
node_relay -.->|"uses host adaptations"| node_patches
node_patches -->|"integrates with"| node_comfyui
node_timeline -->|"complements node UI"| node_registration
node_workflow_a -.->|"exercises"| node_registration
node_workflow_b -.->|"exercises"| node_registration
node_assets -.->|"supports"| node_timeline

click node_package "https://github.com/kijai/comfyui-promptrelay/blob/main/__init__.py"
click node_registration "https://github.com/kijai/comfyui-promptrelay/blob/main/nodes.py"
click node_smart_node "https://github.com/kijai/comfyui-promptrelay/blob/main/smart_nodes.py"
click node_parser "https://github.com/kijai/comfyui-promptrelay/blob/main/parser.py"
click node_word_numbers "https://github.com/kijai/comfyui-promptrelay/blob/main/requirements.txt"
click node_relay "https://github.com/kijai/comfyui-promptrelay/blob/main/prompt_relay.py"
click node_options "https://github.com/kijai/comfyui-promptrelay/blob/main/advanced_options.py"
click node_patches "https://github.com/kijai/comfyui-promptrelay/blob/main/patches.py"
click node_timeline "https://github.com/kijai/comfyui-promptrelay/blob/main/web/js/prompt_relay_timeline.js"
click node_workflow_a "https://github.com/kijai/comfyui-promptrelay/blob/main/example_workflows/prompt_relay_test.json"
click node_workflow_b "https://github.com/kijai/comfyui-promptrelay/blob/main/example_workflows/prompt_relay_ltx23_test_02.json"
click node_assets "https://github.com/kijai/comfyui-promptrelay/tree/main/assets"

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_package,node_registration,node_smart_node,node_parser,node_word_numbers,node_relay,node_options,node_patches toneBlue
class node_timeline toneAmber
class node_workflow_a,node_workflow_b,node_assets toneMint
class node_comfyui toneNeutral
```

## Components

### Python extension

Custom nodes and prompt-processing runtime.

- [Package entry](https://github.com/kijai/comfyui-promptrelay/blob/main/__init__.py): Python package · `__init__.py`
- [Node registration](https://github.com/kijai/comfyui-promptrelay/blob/main/nodes.py): node surface · Exposes Prompt Relay nodes to ComfyUI. · `nodes.py`
- [Smart node](https://github.com/kijai/comfyui-promptrelay/blob/main/smart_nodes.py): automatic allocation · Builds segment timing from a single smart prompt. · `smart_nodes.py`
- [Prompt parser](https://github.com/kijai/comfyui-promptrelay/blob/main/parser.py): parsing boundary · Parses inline or headed blocks into ordered weighted segments. · `parser.py`
- [Word-number support](https://github.com/kijai/comfyui-promptrelay/blob/main/requirements.txt): optional dependency · Extends block-header parsing. · `requirements.txt`
- [Prompt relay](https://github.com/kijai/comfyui-promptrelay/blob/main/prompt_relay.py): conditioning engine · Distributes encoded conditioning over latent-frame spans. · `prompt_relay.py`
- [Advanced options](https://github.com/kijai/comfyui-promptrelay/blob/main/advanced_options.py): node options · `advanced_options.py`
- [Compatibility patches](https://github.com/kijai/comfyui-promptrelay/blob/main/patches.py): host integration · Adapts behavior at ComfyUI runtime boundaries. · `patches.py`

### ComfyUI frontend

Timeline UI integration.

- [Relay timeline UI](https://github.com/kijai/comfyui-promptrelay/blob/main/web/js/prompt_relay_timeline.js): browser component · Visualizes or edits the relay timeline. · `web/js/prompt_relay_timeline.js`

### Examples and assets

- [Prompt Relay workflow](https://github.com/kijai/comfyui-promptrelay/blob/main/example_workflows/prompt_relay_test.json): example workflow · `example_workflows/prompt_relay_test.json`
- [LTX23 workflow](https://github.com/kijai/comfyui-promptrelay/blob/main/example_workflows/prompt_relay_ltx23_test_02.json): example workflow · `example_workflows/prompt_relay_ltx23_test_02.json`
- [UI assets](https://github.com/kijai/comfyui-promptrelay/tree/main/assets): images and docs · Smart-node and timeline assets. · `assets`

### Other components

- **ComfyUI host**: host runtime · Discovers nodes and runs workflow execution.

## Connections

- ComfyUI host → Package entry: discovers
- Package entry → Node registration: loads
- Node registration → Smart node: registers
- Node registration → Prompt relay: registers
- Node registration → Advanced options: exposes
- Smart node → Prompt parser: parses smart_prompt
- Prompt parser → Word-number support: optionally uses
- Smart node → Prompt relay: allocates segments and frames
- Advanced options → Prompt relay: configures encoding
- Prompt relay → Compatibility patches: uses host adaptations
- Compatibility patches → ComfyUI host: integrates with
- Relay timeline UI → Node registration: complements node UI
- Prompt Relay workflow → Node registration: exercises
- LTX23 workflow → Node registration: exercises
- UI assets → Relay timeline UI: supports
