Comfy-Org / Comfy-Org/ComfyUI_frontend

[RFC] Extract systems from `ComfyApp` god object

Open
#11,015 0 comments 0 reactions 0 assignees View on GitHub
refactor
Dominant language
TypeScript
Stars
2k
Forks
699
Avg merge
1d 7h
Merged PRs (30d)
490

Description

## Problem

`src/scripts/app.ts` is a 2,181-line god object with 113 methods and 13 `@deprecated` accessors. It is imported by 130+ files across every architectural layer. Understanding any single concept (file drop, API events, node registration) requires reading through the entire file. The interface surface is nearly as large as the implementation — a quintessential shallow module.

This violates ADR 0003 and ADR 0008's constraint: "Do not add methods to `LGraphNode`, `LGraphCanvas`, `LGraph`, or `Subgraph`. Extract to systems, stores, or composables."

## Proposed Deepening

Extract 4-5 cohesive systems from `ComfyApp` into standalone composables/services:

- **`useApiEventHandlers`** (lines 711-789): API websocket subscription logic → `platform/` or `workbench/`
- **`useGraphSetup`** (lines 840-957): Canvas/graph initialization → `workbench/`
- **`useClipspace`** (static methods, lines 393-574): Clipspace operations → `workbench/`
- **`useFileDropHandler`** (lines 579-671): File drag/drop handling → `workbench/`
- **`useNodeRegistration`** (lines 1042-1065): Node def registration → `platform/`

`ComfyApp` would remain as a thin orchestrator calling these systems during `setup()`, with a drastically reduced interface.

## Migration Plan

1. Extract one system at a time, starting with the most self-contained (e.g., `useClipspace`)
2. Each extraction is a single PR that leaves the codebase working
3. `ComfyApp` delegates to the new system — existing callers of `app.xxx` get deprecated wrappers initially
4. Remove deprecated wrappers once all callers migrate

## Testing Strategy

- Existing tests for `app.ts` continue to pass after each extraction
- New systems get their own unit tests at the boundary
- Browser tests validate end-to-end behavior (drag/drop, clipboard, node registration)

┆Issue is synchronized with this [Notion page](https://www.notion.so/Issue-11015-RFC-Extract-systems-from-ComfyApp-god-object-33e6d73d365081dbae2dd426ad84d5fd) by [Unito](https://www.unito.io)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.