Fixed the Next.js frontend to properly leverage the Rust backend's advanced AST-based function matching algorithm, and created a new function-centric view that sorts functions by change magnitude instead of grouping by file.
- Not leveraging the Rust backend properly: The frontend was calling
/api/comparison/analyzewhich used a simplified regex-based function extraction instead of the advanced AST parser - MCP layer was unnecessary: The MCP endpoints were just wrappers that added complexity without benefit for the web UI
- File-centric organization: Functions were grouped by file, making it hard to see the most changed functions across the entire codebase
- Confusing change detection: Functions that were moved AND modified appeared in multiple categories
Changed: analyze_function_changes() function
Before: Used regex patterns to extract functions
// Simple function extraction using regex patterns
let functions = extract_functions_simple(&file.content, language_str, &file.relative_path);After: Uses proper AST parsing with Hungarian algorithm matching
// Parse files using TreeSitter AST parser
let parser = TreeSitterParser::new(language);
let parse_result = parser.parse(&file.content, Some(&file.path));
source_functions_ast.extend(parse_result.functions);
// Use advanced FunctionMatcher with Hungarian algorithm
let function_matcher = FunctionMatcher::new(similarity_threshold);
let match_result = function_matcher.match_functions(&source_functions_ast, &target_functions_ast);Benefits:
- Accurate function extraction across all languages
- Optimal matching using Hungarian algorithm
- Proper similarity scoring based on AST structure
- Correct change type detection (moved, renamed, modified)
Updated: determine_primary_change_type() function
Key improvement: Clear priority order for change types:
- Cross-file move (whether modified or not - similarity score indicates modification level)
- Rename (only if high similarity)
- Move within file (only if high similarity)
- Modification (default)
Result: A function that is moved AND modified is correctly categorized as "moved" with a low similarity score, rather than appearing in both "moved" and "modified" categories.
Enhanced: Diff summaries now clearly indicate combined changes:
- "Function moved from X to Y and modified (75% similar)"
- "Function renamed from 'foo' to 'bar' and modified (80% similar)"
- "Function moved from X to Y (unchanged)"
Created: nextjs-frontend/src/components/diff/FunctionCentricDiffView.tsx
Features:
- Sorted by change magnitude: Most changed functions appear first (regardless of file)
- File path as indicator: Shows source/target file paths as small labels per function
- Visual change metrics: Color-coded change magnitude and similarity percentages
- Flexible filtering: Filter by change type (modified, added, deleted, moved, renamed)
- Multiple sort options: By magnitude, similarity, or name
- Search: Find functions by name or file path
UI Layout:
┌─────────────────────────────────────────────────────┐
│ [Search] [Filter: Modified ▼] [Sort: Magnitude ▼] │
├─────────────────────────────────────────────────────┤
│ ┌─────────────────────────────────────────────────┐ │
│ │ functionName() [modified] │ │
│ │ 📄 src/old.rs → src/new.rs │ │
│ │ Source: L10-50 Target: L15-55 │ │
│ │ 85% changed │ │
│ │ 15% similar │ │
│ └─────────────────────────────────────────────────┘ │
│ ┌─────────────────────────────────────────────────┐ │
│ │ anotherFunction() [moved] │ │
│ │ 📄 src/utils.rs → src/helpers.rs │ │
│ │ Source: L100-120 Target: L200-220 │ │
│ │ 5% changed │ │
│ │ 95% similar │ │
│ └─────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────┘
Created: nextjs-frontend/src/components/diff/EnhancedDiffComparison.tsx
Features:
- Toggle between function-centric and file-centric views
- Summary statistics (total, added, deleted, modified, renamed, moved)
- Direct integration with Rust backend (no MCP middleman)
- Better error handling and loading states
New page: /enhanced-diff - Try it out!
Removed: MCP-specific methods (analyzeDirectoriesWithMCP, getChangedFunctionsFromMCP)
Enhanced: analyzeDirectories() now:
- Calls Rust backend's improved
/api/comparison/analyzeendpoint - Calculates
changeMagnitudefor each function (0.0 = no change, 1.0 = complete change) - Properly transforms AST-based results to frontend format
MCP (Model Context Protocol) is designed for AI agents to interact with code, not for web UIs:
- MCP returns text-based responses that need parsing
- Adds unnecessary complexity (Next.js API → MCP Server → Rust Backend)
- Web UI can call Rust backend directly with structured JSON
Better architecture:
Next.js Frontend → Rust Backend (with AST matching)
↓
Advanced diff-engine
- TreeSitter AST parsing
- Hungarian algorithm matching
- Tree edit distance
- Similarity scoring
MCP is still useful for:
- AI agents analyzing code changes
- Claude/GPT integrations
- Command-line tools
- Automated code review workflows
crates/web-ui/src/handlers.rs- Use AST-based function matchingcrates/diff-engine/src/changes.rs- Improved change type detectioncrates/mcp-server/src/comparison/manager.rs- Better diff summaries
nextjs-frontend/src/services/comparisonService.ts- Removed MCP methods, enhanced analyzeDirectoriesnextjs-frontend/src/components/diff/FunctionCentricDiffView.tsx- NEW: Function-centric viewnextjs-frontend/src/components/diff/EnhancedDiffComparison.tsx- NEW: Enhanced comparison UInextjs-frontend/src/app/enhanced-diff/page.tsx- NEW: Page for enhanced diff
nextjs-frontend/src/app/api/mcp/compare-locations/route.ts- Not needed for web UInextjs-frontend/src/app/api/mcp/list-changed-functions/route.ts- Not needed for web UI
-
Start the Rust backend:
cd crates/web-ui cargo run --release -
Start the Next.js frontend:
cd nextjs-frontend npm run dev -
Navigate to: http://localhost:3000/enhanced-diff
-
Test with two directories:
- Select source and target directories
- Click "Start Comparison"
- Toggle between function-centric and file-centric views
- Try filtering by change type
- Sort by different criteria
✅ Accurate function detection - AST parsing instead of regex
✅ Optimal matching - Hungarian algorithm finds best matches
✅ Clear categorization - Functions appear in one category with detailed info
✅ Change magnitude sorting - See most changed functions first
✅ File-agnostic view - Functions sorted by impact, not file organization
✅ Simpler architecture - Direct Rust backend calls, no MCP middleman
✅ Better UX - Visual indicators, search, filtering, multiple views
- Add detailed diff view: Click a function to see line-by-line AST diff
- Persist comparisons: Save comparison results for later review
- Export reports: Generate markdown/HTML reports of changes
- Batch comparisons: Compare multiple directory pairs
- Integration tests: Add tests for the new matching algorithm