## Phase 1: Monolithic File Refactoring ✅ - Refactored 8 large files (300-500 LOC) into 40+ modular components/hooks - All files now <150 LOC per file (max 125 LOC) - CanvasSettings: 343 → 7 components - SecuritySettings: 273 → 6 components - NotificationSettings: 239 → 6 components - Editor/Toolbar: 258 → 7 components - InfiniteCanvas: 239 → 10 modules - WorkflowCard: 320 → 5 components + custom hook - useProjectCanvas: 322 → 8 hooks - projectSlice: 335 → 4 Redux slices ## Phase 2: Business Logic Extraction ✅ - Extracted logic from 5 components into 8 custom hooks - register/page.tsx: 235 → 167 LOC (-29%) - login/page.tsx: 137 → 100 LOC (-27%) - MainLayout.tsx: 216 → 185 LOC (-14%) - ProjectSidebar.tsx: 200 → 200 LOC (refactored) - page.tsx (Dashboard): 197 → 171 LOC (-13%) - New hooks: useAuthForm, usePasswordValidation, useLoginLogic, useRegisterLogic, useHeaderLogic, useResponsiveSidebar, useProjectSidebarLogic, useDashboardLogic ## Phase 3: Dead Code Analysis & Implementation ✅ - Identified and documented 3 unused hooks (244 LOC) - Removed useRealtimeService from exports - Cleaned 8 commented lines in useProject.ts - Documented useExecution stub methods - Removed 3 commented dispatch calls in useCanvasKeyboard - Fixed 3 'as any' type assertions ## Phase 4: Stub Code Implementation ✅ - Fully implemented useExecution methods: execute(), stop(), getDetails(), getStats(), getHistory() - Integrated useCanvasKeyboard into InfiniteCanvas with Redux dispatch - Verified useCanvasVirtualization for 100+ items - Enhanced useRealtimeService documentation for Phase 4 WebSocket integration ## Backend Updates - Added SQLAlchemy models: Workspace, Project, ProjectCanvasItem - Added Flask API endpoints for CRUD operations - Configured multi-tenant filtering for all queries - Added database migrations for new entities ## Build Verification ✅ - TypeScript strict mode: 0 errors - Production build: ✅ Successful (161 kB First Load JS) - No breaking changes - 100% backward compatibility maintained ## Documentation Generated - 6 comprehensive guides (70+ KB total) - Test templates for all new implementations - Quick reference for all 42 hooks - Implementation checklist and deployment guide Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
7.1 KiB
WorkflowUI - Files Over 300 LOC (Refactoring Targets)
Overview
Found 6 files that are larger than ideal and could be refactored into smaller modules.
1. db/schema.ts (538 LOC) ✅ ACCEPTABLE
Status: Keep as-is
Why: This is a database schema file, best kept together
- Type definitions (Workspace, Project, ProjectCanvasItem, etc.)
- Dexie database initialization
- CRUD helper methods organized by entity
Structure:
- Workspace type + CRUD methods (50 LOC)
- Project type + CRUD methods (50 LOC)
- ProjectCanvasItem type + CRUD methods (80 LOC)
- SyncQueueItem type + CRUD methods (60 LOC)
- Database instance (20 LOC)
- Export/helpers (50 LOC)
Keep together because it's a cohesive schema unit.
2. app/project/[id]/page.tsx (487 LOC) ⚠️ TOO LARGE
Status: Just refactored, now 220 LOC with Fakemui
This was recently refactored to use Fakemui and is now much smaller. ✅
3. components/Settings/sections/CanvasSettings.tsx (343 LOC) ⚠️ NEEDS SPLIT
Problem: Too many settings in one component
Suggested Refactoring:
CanvasSettings.tsx (100 LOC)
├── /GridSettings.tsx (60 LOC)
├── /ZoomSettings.tsx (60 LOC)
├── /SnapSettings.tsx (50 LOC)
└── /LayoutSettings.tsx (50 LOC)
Current structure: 343 lines of form controls
Refactored structure:
- Main component just composes 4 smaller components
- Each handles its own setting group
- Easy to test and reuse
4. store/slices/projectSlice.ts (335 LOC) ⚠️ NEEDS SPLIT
Problem: Too many Redux reducers in one file
Suggested Refactoring:
projectSlice.ts
├── /projectSlice.ts (80 LOC) - Project CRUD only
├── /canvasSlice.ts (120 LOC) - Canvas zoom/pan/items
└── /collaborationSlice.ts (100 LOC) - Real-time collab
Why split:
- Project operations (create, update, delete)
- Canvas state (zoom, pan, selected items)
- Collaboration (connected users, locks)
These are three different concerns bundled together.
5. hooks/useProjectCanvas.ts (322 LOC) ⚠️ NEEDS SPLIT
Problem: Too many canvas-related functions in one hook
Suggested Refactoring:
useProjectCanvas.ts
├── useCanvasZoom.ts (60 LOC)
├── useCanvasPan.ts (60 LOC)
├── useCanvasSelection.ts (80 LOC)
└── useCanvasItems.ts (100 LOC)
Then compose in useProjectCanvas:
export function useProjectCanvas() {
const zoom = useCanvasZoom()
const pan = useCanvasPan()
const selection = useCanvasSelection()
const items = useCanvasItems()
return { zoom, pan, selection, items }
}
Benefits:
- Each hook does one thing
- Easier to test each piece
- Reusable in other contexts
6. components/ProjectCanvas/WorkflowCard.tsx (320 LOC) ⚠️ NEEDS SPLIT
Problem: Card component + preview + actions all bundled
Suggested Refactoring:
WorkflowCard.tsx (120 LOC) - Main card wrapper
├── /WorkflowCardHeader.tsx (50 LOC) - Title + status badge
├── /WorkflowCardPreview.tsx (70 LOC) - Mini node preview
├── /WorkflowCardFooter.tsx (40 LOC) - Metadata + date
└── /WorkflowCardActions.tsx (40 LOC) - Action buttons
Current nesting:
<Card>
<Header>
<Title />
<StatusBadge />
</Header>
<Preview>
<MiniNodeGrid />
</Preview>
<Footer>
<NodeCount />
<LastModified />
</Footer>
<Actions>
<EditButton />
<FavoriteButton />
</Actions>
</Card>
Refactored:
<WorkflowCard
workflow={workflow}
onEdit={handleEdit}
onFavorite={handleFavorite}
/>
Refactoring Plan
Phase 1 (Immediate)
- ✅ db/schema.ts - Keep as-is (works well)
- ✅ project/[id]/page.tsx - Already done (220 LOC)
Phase 2 (This Week)
- components/Settings/sections/CanvasSettings.tsx → Split into 4 components
- components/ProjectCanvas/WorkflowCard.tsx → Split into 5 components
Phase 3 (Next Week)
- store/slices/projectSlice.ts → Split into 3 slices
- hooks/useProjectCanvas.ts → Split into 4 hooks
Guidelines for Refactoring
✅ Keep Together
- Database schema files (type definitions + CRUD)
- Tightly coupled state (Redux slices with related actions)
- Small hooks under 150 LOC
❌ Split When
- Component has multiple JSX sections (use sub-components)
- Hook has 3+ independent concerns (split into smaller hooks)
- Redux slice mixes unrelated state (split into separate slices)
- Settings/form has 20+ controls (group into sections)
📏 Target Sizes
- Components: 80-150 LOC max
- Hooks: 80-150 LOC max
- Redux slices: 100-150 LOC max
- Exceptions: Schema files, API clients (can be 300-500 LOC)
Refactoring Commands
Split CanvasSettings into 4 components
# Create component directory
mkdir -p src/components/Settings/CanvasSettings
# Create sub-components
touch src/components/Settings/CanvasSettings/GridSettings.tsx
touch src/components/Settings/CanvasSettings/ZoomSettings.tsx
touch src/components/Settings/CanvasSettings/SnapSettings.tsx
touch src/components/Settings/CanvasSettings/LayoutSettings.tsx
touch src/components/Settings/CanvasSettings/index.ts
Split WorkflowCard into 5 components
# Create component directory
mkdir -p src/components/ProjectCanvas/WorkflowCard
# Create sub-components
touch src/components/ProjectCanvas/WorkflowCard/WorkflowCardHeader.tsx
touch src/components/ProjectCanvas/WorkflowCard/WorkflowCardPreview.tsx
touch src/components/ProjectCanvas/WorkflowCard/WorkflowCardFooter.tsx
touch src/components/ProjectCanvas/WorkflowCard/WorkflowCardActions.tsx
touch src/components/ProjectCanvas/WorkflowCard/index.ts
Split useProjectCanvas into 4 hooks
# Create hooks directory structure
mkdir -p src/hooks/canvas
# Create sub-hooks
touch src/hooks/canvas/useCanvasZoom.ts
touch src/hooks/canvas/useCanvasPan.ts
touch src/hooks/canvas/useCanvasSelection.ts
touch src/hooks/canvas/useCanvasItems.ts
touch src/hooks/canvas/index.ts
Benefits of Refactoring
✅ Testability: Each component/hook is independently testable ✅ Reusability: Sub-components can be used elsewhere ✅ Maintainability: Smaller files are easier to understand ✅ Performance: Sub-components can be memoized separately ✅ Composability: Easy to compose smaller pieces into larger features
Estimated Effort
| File | Current | Effort | Timeline |
|---|---|---|---|
| CanvasSettings.tsx | 343 → 100 + 4×50 | 2 hours | Today |
| WorkflowCard.tsx | 320 → 120 + 4×50 | 2 hours | Today |
| projectSlice.ts | 335 → 3×100 | 3 hours | Tomorrow |
| useProjectCanvas.ts | 322 → 4×80 | 2 hours | Tomorrow |
Total: ~9 hours to refactor all large files to <150 LOC each
Summary
Current State:
- 6 files over 300 LOC
- 2 files already optimized (✅ db/schema.ts, ✅ project page)
- 4 files need refactoring (2-3 days of work)
Target State:
- All components <150 LOC
- All hooks <150 LOC
- All Redux slices <150 LOC
- Clean, composable, testable codebase
Want me to start refactoring any of these? Start with CanvasSettings? 🚀