# comfy-org/desktop architecture

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

- Interactive diagram: https://gitdiagram.com/comfy-org/desktop
- Repository: https://github.com/comfy-org/desktop

## Overview

1. **What this repo is**
   - This is an **Electron desktop wrapper around ComfyUI**.
   - It packages the ComfyUI backend, the ComfyUI frontend, ComfyUI-Manager, and `uv`, then installs Python dependencies and starts the ComfyUI server on launch.

2. **Top-level runtime split**
   - The app is centered on the **Electron main process** (`src/main.ts`, `src/main-process/*`).
   - A **preload bridge** (`src/preload.ts`) exposes a controlled IPC surface to the UI.
   - The **renderer/UI layer** is built with Vite and wired through the Electron/Vite plugin infrastructure, but the key architecture point is that UI actions flow through IPC rather than direct filesystem/process access.

3. **Startup and orchestration**
   - App startup is coordinated by `src/desktopApp.ts` and the main-process modules.
   - The startup path decides whether to show the install flow, restore the existing install, or start the ComfyUI server.
   - The main process owns lifecycle, window creation, server launch, and error handling.

4. **ComfyUI backend lifecycle**
   - The bundled ComfyUI source lives under `assets/`.
   - `src/main-process/comfyInstallation.ts`, `src/main-process/comfyServer.ts`, and `src/virtualEnvironment.ts` suggest the backend is managed as an installed runtime plus Python environment, not as an in-process library.
   - The server is launched as an external process, and the desktop app monitors its state and logs.

5. **Python dependency and environment management**
   - `uv` is a first-class dependency and is used to install or refresh Python packages at runtime.
   - `src/services/cmCli.ts`, `src/services/pythonImportVerifier.ts`, and the `assets/requirements/*` files indicate a managed Python dependency layer with platform-specific compiled requirements.
   - This is the main boundary between the Electron app and the Python/ComfyUI world.

6. **Install flow and first-run wizard**
   - `src/install/*` contains the first-run/setup experience: choosing locations, creating required directories, downloading resources, and preparing the runtime.
   - `src/install/installationManager.ts` and `src/install/installWizard.ts` are the core install orchestration pieces.
   - The install wizard is a distinct user journey from the steady-state “already installed” app.

7. **State, config, and persisted paths**
   - User and app configuration are persisted in OS-specific app data locations, as described in the README.
   - `src/config/*`, `src/store/*`, and `src/main-process/appState.ts` manage settings such as ComfyUI base path, window state, desktop config, and server settings.
   - These settings are central to the architecture because they determine where ComfyUI files live and how the server boots.

8. **IPC and feature handlers**
   - `src/handlers/*` exposes main-process capabilities to the UI: app info, GPU info, install state, networking, and filesystem/path concerns.
   - `src/infrastructure/ipcChannels.ts` defines the message boundary between renderer and main process.
   - This is the primary integration seam for UI-driven actions.

9. **Troubleshooting and diagnostics**
   - The app includes explicit troubleshooting paths for server start failures, virtual environment problems, and installation issues.
   - `src/install/troubleshooting.ts`, `src/infrastructure/*Error.ts`, and `src/infrastructure/structuredLogging.ts` show that failure states are modeled as first-class architecture concerns.
   - Electron logging is used for both main-process logs and ComfyUI server logs.

10. **Telemetry and external services**
   - `src/services/telemetry.ts` and `src/services/sentry.ts` indicate optional usage metrics and crash reporting.
   - The README states that no workflows/logs/personal data are sent, but the architecture still includes an outbound observability boundary.
   - Updates and releases are tied to GitHub Releases and GitHub Actions.

11. **Platform-specific packaging**
   - The repo has platform build scripts and actions for **Windows NSIS**, **macOS DMG**, and ToDesktop distribution.
   - `scripts/*`, `.github/actions/*`, and `.github/workflows/*` handle code signing, installer creation, release publishing, and compiled requirement updates.
   - Packaging is not just build automation here; it materially shapes the deployed filesystem layout and update mechanism.

12. **Test architecture**
   - Unit tests cover config, install, main-process orchestration, services, and utilities.
   - Playwright-based integration tests simulate install and post-install behavior, including troubleshooting flows.
   - The test suite mirrors the app’s real boundaries: installation, server startup, and UI-to-main-process interactions.

13. **Overall data flow**
   - User launches Electron app → main process loads settings and checks install state → install wizard runs if needed → Python environment and dependencies are prepared with `uv` → ComfyUI server is started as a child process → renderer UI talks to main process over IPC → main process proxies state, files, and server lifecycle events back to the UI.

14. **Diagramming takeaway**
   - The cleanest architecture diagram is a **desktop shell** around a **managed Python backend** with a **main-process orchestrator** in between.
   - The important boundaries are: UI ↔ IPC ↔ Electron main process ↔ external ComfyUI/Python processes ↔ filesystem/config/logs ↔ optional telemetry/update services.

Main entry points: [`src/desktopApp.ts`](https://github.com/comfy-org/desktop/blob/main/src/desktopApp.ts) (Desktop app), [`src/handlers/AppHandlers.ts`](https://github.com/comfy-org/desktop/blob/main/src/handlers/AppHandlers.ts) (Handlers), [`src/install/installationManager.ts`](https://github.com/comfy-org/desktop/blob/main/src/install/installationManager.ts) (Install manager), [`src/main-process/comfyServer.ts`](https://github.com/comfy-org/desktop/blob/main/src/main-process/comfyServer.ts) (Comfy server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_runtime["Runtime"]
  node_n_main["Main<br/>electron entry<br/>[main.ts]"]
  node_n_desktop_app["Desktop app<br/>orchestrator<br/>[desktopApp.ts]"]
  node_n_app_window["Window<br/>[appWindow.ts]"]
  node_n_ipc["IPC channels<br/>boundary<br/>[ipcChannels.ts]"]
  node_n_preload["Preload<br/>bridge<br/>[preload.ts]"]
  node_n_handlers["Handlers<br/>[AppHandlers.ts]"]
end

subgraph group_grp_install["Install"]
  node_n_install_wizard["Install wizard<br/>setup flow<br/>[installWizard.ts]"]
  node_n_install_mgr["Install manager<br/>installer"]
end

subgraph group_grp_backend["ComfyUI Backend"]
  node_n_comfy_install["Comfy install<br/>runtime install"]
  node_n_comfy_server["Comfy server<br/>child process<br/>[comfyServer.ts]"]
  node_n_venv["Virtual env<br/>python env"]
  node_n_cmcli["uv / cmCli<br/>python tooling<br/>[cmCli.ts]"]
  node_n_pyverify["Python verify<br/>env check"]
end

subgraph group_grp_support["Support"]
  node_n_app_state["App state<br/>[appState.ts]"]
  node_n_config["Config<br/>settings"]
  node_n_store["Store<br/>persistence<br/>[desktopConfig.ts]"]
  node_n_logging["Logging<br/>diagnostics"]
  node_n_telemetry["Telemetry<br/>external service<br/>[telemetry.ts]"]
  node_n_sentry["Sentry<br/>crash reporting<br/>[sentry.ts]"]
end

subgraph group_grp_packaging["Packaging"]
  node_n_build["Build & release<br/>packaging<br/>[publish_all.yml]"]
end

node_n_main -->|"boots"| node_n_desktop_app
node_n_desktop_app -->|"creates"| node_n_app_window
node_n_desktop_app -->|"loads state"| node_n_app_state
node_n_desktop_app -->|"reads config"| node_n_config
node_n_desktop_app -->|"first run"| node_n_install_wizard
node_n_install_wizard -->|"orchestrates"| node_n_install_mgr
node_n_install_mgr -->|"prepares"| node_n_comfy_install
node_n_install_mgr -->|"creates env"| node_n_venv
node_n_venv -->|"uses"| node_n_cmcli
node_n_cmcli -->|"verifies"| node_n_pyverify
node_n_install_mgr -->|"reports"| node_n_logging
node_n_desktop_app -->|"starts"| node_n_comfy_server
node_n_comfy_server -->|"runs in"| node_n_venv
node_n_comfy_server -->|"streams logs"| node_n_logging
node_n_preload -->|"exposes"| node_n_ipc
node_n_ipc -->|"routes to"| node_n_handlers
node_n_handlers -->|"reads/writes"| node_n_app_state
node_n_handlers -->|"mutates"| node_n_config
node_n_handlers -->|"controls"| node_n_comfy_server
node_n_handlers -->|"queries"| node_n_comfy_install
node_n_telemetry -->|"reports to"| node_n_sentry
node_n_build -.->|"packages"| node_n_comfy_install
node_n_build -.->|"refreshes deps"| node_n_cmcli

click node_n_main "https://github.com/comfy-org/desktop/blob/main/src/main.ts"
click node_n_desktop_app "https://github.com/comfy-org/desktop/blob/main/src/desktopApp.ts"
click node_n_app_window "https://github.com/comfy-org/desktop/blob/main/src/main-process/appWindow.ts"
click node_n_ipc "https://github.com/comfy-org/desktop/blob/main/src/infrastructure/ipcChannels.ts"
click node_n_preload "https://github.com/comfy-org/desktop/blob/main/src/preload.ts"
click node_n_handlers "https://github.com/comfy-org/desktop/blob/main/src/handlers/AppHandlers.ts"
click node_n_install_wizard "https://github.com/comfy-org/desktop/blob/main/src/install/installWizard.ts"
click node_n_install_mgr "https://github.com/comfy-org/desktop/blob/main/src/install/installationManager.ts"
click node_n_comfy_install "https://github.com/comfy-org/desktop/blob/main/src/main-process/comfyInstallation.ts"
click node_n_comfy_server "https://github.com/comfy-org/desktop/blob/main/src/main-process/comfyServer.ts"
click node_n_venv "https://github.com/comfy-org/desktop/blob/main/src/virtualEnvironment.ts"
click node_n_cmcli "https://github.com/comfy-org/desktop/blob/main/src/services/cmCli.ts"
click node_n_pyverify "https://github.com/comfy-org/desktop/blob/main/src/services/pythonImportVerifier.ts"
click node_n_app_state "https://github.com/comfy-org/desktop/blob/main/src/main-process/appState.ts"
click node_n_config "https://github.com/comfy-org/desktop/blob/main/src/config/comfyConfigManager.ts"
click node_n_store "https://github.com/comfy-org/desktop/blob/main/src/store/desktopConfig.ts"
click node_n_logging "https://github.com/comfy-org/desktop/blob/main/src/infrastructure/structuredLogging.ts"
click node_n_telemetry "https://github.com/comfy-org/desktop/blob/main/src/services/telemetry.ts"
click node_n_sentry "https://github.com/comfy-org/desktop/blob/main/src/services/sentry.ts"
click node_n_build "https://github.com/comfy-org/desktop/blob/main/.github/workflows/publish_all.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_n_main,node_n_desktop_app,node_n_app_window,node_n_ipc,node_n_preload,node_n_handlers toneBlue
class node_n_install_wizard,node_n_install_mgr toneAmber
class node_n_comfy_install,node_n_comfy_server,node_n_venv,node_n_cmcli,node_n_pyverify toneMint
class node_n_app_state,node_n_config,node_n_store,node_n_logging,node_n_telemetry,node_n_sentry toneRose
class node_n_build toneIndigo
```

## Components

### Runtime

Electron app lifecycle, IPC, and windowing

- [Main](https://github.com/comfy-org/desktop/blob/main/src/main.ts): electron entry · Process entrypoint and app bootstrap · `src/main.ts`
- [Desktop app](https://github.com/comfy-org/desktop/blob/main/src/desktopApp.ts): orchestrator · Top-level startup coordination · `src/desktopApp.ts`
- [Window](https://github.com/comfy-org/desktop/blob/main/src/main-process/appWindow.ts): window mgmt · Creates and manages the Electron window · `src/main-process/appWindow.ts`
- [IPC channels](https://github.com/comfy-org/desktop/blob/main/src/infrastructure/ipcChannels.ts): boundary · Message contract between renderer and main · `src/infrastructure/ipcChannels.ts`
- [Preload](https://github.com/comfy-org/desktop/blob/main/src/preload.ts): bridge · Controlled renderer bridge · `src/preload.ts`
- [Handlers](https://github.com/comfy-org/desktop/blob/main/src/handlers/AppHandlers.ts): ipc handlers · Main-process API surface for the UI · `src/handlers/AppHandlers.ts`

### Install

First-run setup and runtime preparation

- [Install wizard](https://github.com/comfy-org/desktop/blob/main/src/install/installWizard.ts): setup flow · First-run installation UX and orchestration · `src/install/installWizard.ts`
- [Install manager](https://github.com/comfy-org/desktop/blob/main/src/install/installationManager.ts): installer · Coordinates setup tasks and install state · `src/install/installationManager.ts`

### ComfyUI Backend

Managed Python environment and ComfyUI server

- [Comfy install](https://github.com/comfy-org/desktop/blob/main/src/main-process/comfyInstallation.ts): runtime install · Installs and restores the bundled ComfyUI runtime · `src/main-process/comfyInstallation.ts`
- [Comfy server](https://github.com/comfy-org/desktop/blob/main/src/main-process/comfyServer.ts): child process · Launches and monitors the ComfyUI server · `src/main-process/comfyServer.ts`
- [Virtual env](https://github.com/comfy-org/desktop/blob/main/src/virtualEnvironment.ts): python env · Managed Python environment for ComfyUI · `src/virtualEnvironment.ts`
- [uv / cmCli](https://github.com/comfy-org/desktop/blob/main/src/services/cmCli.ts): python tooling · Runtime dependency installation and CLI integration · `src/services/cmCli.ts`
- [Python verify](https://github.com/comfy-org/desktop/blob/main/src/services/pythonImportVerifier.ts): env check · Validates Python imports and dependencies · `src/services/pythonImportVerifier.ts`

### Support

Config, storage, services, and diagnostics

- [App state](https://github.com/comfy-org/desktop/blob/main/src/main-process/appState.ts): state · Persists window, install, and server state · `src/main-process/appState.ts`
- [Config](https://github.com/comfy-org/desktop/blob/main/src/config/comfyConfigManager.ts): settings · ComfyUI and desktop configuration management · `src/config/comfyConfigManager.ts`
- [Store](https://github.com/comfy-org/desktop/blob/main/src/store/desktopConfig.ts): persistence · Persistent app settings and desktop config · `src/store/desktopConfig.ts`
- [Logging](https://github.com/comfy-org/desktop/blob/main/src/infrastructure/structuredLogging.ts): diagnostics · Structured logging and error modeling · `src/infrastructure/structuredLogging.ts`
- [Telemetry](https://github.com/comfy-org/desktop/blob/main/src/services/telemetry.ts): external service · Crash reporting and usage telemetry · `src/services/telemetry.ts`
- [Sentry](https://github.com/comfy-org/desktop/blob/main/src/services/sentry.ts): crash reporting · Optional error reporting integration · `src/services/sentry.ts`

### Packaging

Build and release automation

- [Build & release](https://github.com/comfy-org/desktop/blob/main/.github/workflows/publish_all.yml): packaging · Scripts and CI for packaging and publishing · `.github/workflows/publish_all.yml`

## Connections

- Main → Desktop app: boots · Main entry starts the desktop orchestrator
- Desktop app → Window: creates · Startup creates the Electron window
- Desktop app → App state: loads state · Restores persisted application state
- Desktop app → Config: reads config · Uses desktop and ComfyUI configuration
- Desktop app → Install wizard: first run · Routes new users into the install flow
- Install wizard → Install manager: orchestrates · Wizard delegates setup work to the install manager
- Install manager → Comfy install: prepares · Ensures the bundled ComfyUI runtime is installed
- Install manager → Virtual env: creates env · Builds or restores the Python environment
- Virtual env → uv / cmCli: uses · Environment setup relies on uv/cmCli tooling
- uv / cmCli → Python verify: verifies · Dependency state is checked through import verification
- Install manager → Logging: reports · Install failures are captured in structured logs
- Desktop app → Comfy server: starts · Steady-state launch starts the server process
- Comfy server → Virtual env: runs in · Server is launched from the managed Python environment
- Comfy server → Logging: streams logs · Server output is surfaced through logging
- Preload → IPC channels: exposes · Preload exposes the renderer boundary
- IPC channels → Handlers: routes to · IPC messages are handled in the main process
- Handlers → App state: reads/writes · Handlers access persisted app state
- Handlers → Config: mutates · Handlers expose config and path operations
- Handlers → Comfy server: controls · UI actions can influence server lifecycle
- Handlers → Comfy install: queries · Install state is exposed to the renderer
- Telemetry → Sentry: reports to · Telemetry and crash reporting share an outbound boundary
- Build & release → Comfy install: packages · Release tooling shapes the bundled runtime layout
- Build & release → uv / cmCli: refreshes deps · Build and release workflows update compiled requirements
