How comfy-org/desktop works
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: desktopApp.ts Desktop app · AppHandlers.ts Handlers · installationManager.ts Install manager · comfyServer.ts Comfy server
Components 20
Runtime
Electron app lifecycle, IPC, and windowing
- Main · Process entrypoint and app bootstrap
src/main.ts - Desktop app · Top-level startup coordination
src/desktopApp.ts - Window · Creates and manages the Electron window
src/main-process/appWindow.ts - IPC channels · Message contract between renderer and main
src/infrastructure/ipcChannels.ts - Preload · Controlled renderer bridge
src/preload.ts - Handlers · Main-process API surface for the UI
src/handlers/AppHandlers.ts
Install
First-run setup and runtime preparation
- Install wizard · First-run installation UX and orchestration
src/install/installWizard.ts - Install manager · Coordinates setup tasks and install state
src/install/installationManager.ts
ComfyUI Backend
Managed Python environment and ComfyUI server
- Comfy install · Installs and restores the bundled ComfyUI runtime
src/main-process/comfyInstallation.ts - Comfy server · Launches and monitors the ComfyUI server
src/main-process/comfyServer.ts - Virtual env · Managed Python environment for ComfyUI
src/virtualEnvironment.ts - uv / cmCli · Runtime dependency installation and CLI integration
src/services/cmCli.ts - Python verify · Validates Python imports and dependencies
src/services/pythonImportVerifier.ts
Support
Config, storage, services, and diagnostics
- App state · Persists window, install, and server state
src/main-process/appState.ts - Config · ComfyUI and desktop configuration management
src/config/comfyConfigManager.ts - Store · Persistent app settings and desktop config
src/store/desktopConfig.ts - Logging · Structured logging and error modeling
src/infrastructure/structuredLogging.ts - Telemetry · Crash reporting and usage telemetry
src/services/telemetry.ts - Sentry · Optional error reporting integration
src/services/sentry.ts
Packaging
Build and release automation
- Build & release · Scripts and CI for packaging and publishing
.github/workflows/publish_all.yml
Connections 23
- 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