Skip to content

refactor(erd): decompose 2900-line ErdView into pure ErdLayoutEngine, ErdCanvas, ErdTableCard and ErdMinimap #1362

Closed

Description

@ZhuchkaTriplesix

Summary

lib/features/erd/erd_view.dart is currently the largest file in the codebase at 2,895 lines.
It violates the Single Responsibility Principle by combining multiple major subsystems:

  1. Algorithmic Graph Layout: Dagre/force-directed positioning, rank assignment, layer assignment, FK edge routing and collision resolution.
  2. Interactive Canvas: Pan/zoom gesture handling (InteractiveViewer / GestureDetector), scale clamping, drag selection.
  3. Table Node Rendering: Node cards, column rows, PK/FK badges, data type labels, table context menus.
  4. Minimap & Navigation: Miniature viewport representation and viewport jumping.
  5. Image Export: PNG/SVG rendering and file export flows.

This makes modifying ERD features risky and hinders testing graph layout algorithms in isolation without mounting heavy widget trees (related to Epic #1286 and Epic #1166).

Proposed Solution

Decompose erd_view.dart into dedicated single-responsibility modules:

  1. lib/core/erd/erd_layout_engine.dart: Pure non-widget algorithmic node placement and edge routing class, 100% unit-testable.
  2. lib/features/erd/widgets/erd_canvas.dart: Canvas gesture handling, zoom/pan transform matrix, and edge painter.
  3. lib/features/erd/widgets/erd_table_card.dart & erd_column_row.dart: Table card rendering, selection states, and badges.
  4. lib/features/erd/widgets/erd_minimap.dart: Isolated minimap widget.
  5. lib/features/erd/controllers/erd_view_controller.dart: State management for table selection, focus, and search filters.

Acceptance Criteria

  • erd_view.dart acts purely as a coordinator under 300 lines.
  • Graph layout logic is covered by pure Dart unit tests without Flutter widget tester.
  • Existing ERD behavior, interaction, and visual tests remain green.

Activity

  1. added
    frontendTheme parser epic label: frontend
    uiUser interface components and widgets
    P2Medium priority / Parity & Refactoring
    on Oct 10, 2026
  2. added 3 commits that reference this issue on Oct 10, 2026
  3. ZhuchkaTriplesix commented on Oct 17, 2026

    @ZhuchkaTriplesix
    MemberAuthor

    Closing as done for its main goals; the rest moved to #1690.

    Done (#1393, #1394, #1472 and earlier): the layout engine, router and geometry are in core/erd and ErdLayoutEngine is unit-tested without Flutter; ErdTableCard, ErdRelationPainter, ErdExporter and the note, group, search, views and export widgets are separate files. erd_view.dart went from 2,895 to 1,705 lines and the 52 widget tests under test/features/erd pass.

    Not done and not planned here: the < 300 lines target (what is left is the widget's state, see #1690 for the follow-up), and the minimap, which does not exist in the product.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium priority / Parity & RefactoringfrontendTheme parser epic label: frontenduiUser interface components and widgets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions