Comfy-Org / Comfy-Org/ComfyUI_frontend
[RFC] Split `ComfyApi` into domain-specific API clients
- Dominant language
- TypeScript
- Stars
- 2k
- Forks
- 699
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 490
Description
## Problem
`src/scripts/api.ts` is a 1,422-line monolith with 62 methods, imported by 100+ files. It combines HTTP client, WebSocket management, event dispatch, authentication, and every API endpoint (queue, history, settings, models, templates, user data, feature flags) in a single class. Adding a new endpoint means modifying this god class, and consumers import the entire API surface when they only need one domain.
## Proposed Deepening
Split into domain-specific API modules behind the existing `api` singleton facade:
| Module | Responsibility |
|--------|---------------|
| `WorkflowApi` | queue, prompt, history, interrupt |
| `ModelApi` | models, embeddings, folder paths |
| `UserApi` | settings, user data |
| `TemplateApi` | templates |
| `SystemApi` | stats, extensions, logs |
| Core `ComfyApi` | WebSocket, event dispatch, auth, `fetchApi` base |
The existing `api` import continues to work — domain modules are accessed via `api.workflow.queuePrompt()` or imported directly.
## Migration Plan
1. Extract one domain at a time (e.g., `ModelApi` first — fewest cross-dependencies)
2. New domain module lives alongside `api.ts` initially, then moves to `platform/api/`
3. `api.xxx()` methods get deprecated wrappers that delegate to the domain module
4. Callers migrate incrementally
## Testing Strategy
- Existing API mocks in tests (`vi.mock('@/scripts/api')`) continue to work
- Each domain module gets focused unit tests
- Integration tests verify WebSocket event flow end-to-end
┆Issue is synchronized with this [Notion page](https://www.notion.so/Issue-11016-RFC-Split-ComfyApi-into-domain-specific-API-clients-33e6d73d36508155b7ccf1a92067ec5d) by [Unito](https://www.unito.io)
Contributor guide
Assessment
This issue has not been assessed yet.