Comfy-Org / Comfy-Org/ComfyUI_frontend

[RFC] Fix cross-layer import violations

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

Description

## Problem

The codebase declares a layering rule: `base → platform → workbench → renderer`. Several files violate this by importing upward:

### base → platform
- `base/common/downloadUtil.ts` imports `platform/distribution/types` and `platform/updates/common/toastStore`

### platform → renderer
- `platform/settings/composables/useLitegraphSettings.ts` imports `renderer/core/canvas/canvasStore`
- `platform/workflow/core/services/workflowService.ts` imports `renderer/core/thumbnail/useWorkflowThumbnail`
- `platform/workflow/management/stores/workflowStore.ts` imports `renderer/core/thumbnail/useWorkflowThumbnail`
- `platform/workflow/templates/composables/useTemplateUrlLoader.ts` imports `renderer/core/canvas/canvasStore`
- `platform/missingModel/missingModelStore.ts` imports `renderer/core/canvas/canvasStore`

### platform → workbench
- `platform/missingModel/missingModelScan.ts` imports `workbench/utils/modelMetadataUtil`

## Proposed Fix

For each violation, apply one of:
1. **Move the imported code down** to the lower layer (if it belongs there)
2. **Define an interface** in the lower layer, with the implementation provided by the higher layer via dependency injection or registration at startup
3. **Extract shared types** into `base/` or a shared types module

## Migration Plan

1. Fix violations one cluster at a time (e.g., all `platform → renderer` violations together)
2. Each PR fixes one direction of violation
3. Add ESLint `import-x/no-restricted-paths` rule to enforce going forward

## Testing Strategy

- `pnpm typecheck` passes after each change
- ESLint rule catches future violations in CI

┆Issue is synchronized with this [Notion page](https://www.notion.so/Issue-11018-RFC-Fix-cross-layer-import-violations-33e6d73d3650811c862cc244303cbff4) 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.