quarto-review-extension

Quarto Review Extension - Refactoring Roadmap

Executive Summary

The Quarto Review Extension is a well-structured, feature-rich application with good test coverage (71%) and solid architecture. However, it shows signs of monolithic growth, particularly in the UIModule (2,554 lines) and TranslationModule (1,558 lines).

Total Estimated Refactoring Cost: ~150-200 hours


Project Overview


1. Critical Refactoring - Priority 1

1.1 UIModule Decomposition (HIGHEST PRIORITY)

Current State:

Target State:

UIModule → Five focused classes:
├── ElementRenderer (rendering/DOM updates)
├── EditorController (editor lifecycle)
├── HeadingManager (heading reference tracking)
├── SegmentationService (content splitting)
└── CommentUICoordinator (comment interaction)

Benefits:

Estimated Effort: 40-60 hours

Implementation Steps:

  1. Analyze all 30+ methods and group by responsibility
  2. Create new classes with focused interfaces
  3. Extract shared utilities
  4. Update all callers
  5. Add comprehensive tests for each class
  6. Document the new structure

1.2 TranslationModule Refactoring

Current State:

Target State:

TranslationModule → Four focused classes:
├── Core TranslationEngine (sentence/alignment logic)
├── TranslationState (immutable state management)
├── TranslationPersistence (storage only)
└── TranslationUIBridge (UI integration)

Benefits:

Estimated Effort: 20-30 hours


1.3 Eliminate MainSidebar Legacy ✅ COMPLETE

Status: COMPLETED

Completed Work:

Effort Spent: 4-6 hours (QUICK WIN ACHIEVED)


2. Code Duplication Elimination - Priority 2

2.1 HTML Template Utilities

Current Problem:

Solution: Create src/utils/template.ts:

export function createModal(config: ModalConfig): HTMLElement;
export function createButton(label: string, options?: ButtonOptions): HTMLElement;
export function createForm(fields: FormField[]): HTMLElement;
export function createAction(icon: string, label: string, callback: Fn): HTMLElement;

Files Affected:

Estimated Effort: 8-12 hours


2.2 Unify Event Registration Pattern

Current Problem:

Solution: Create src/utils/event-binder.ts:

export class EventBinder {
  bind(target: Element, event: string, handler: Fn, options?: AddEventListenerOptions): void;
  unbind(target: Element, event: string, handler: Fn): void;
  cleanup(): void;  // Unbind all registered listeners
}

Benefits:

Estimated Effort: 10-15 hours


2.3 Consolidate Git Provider Base Logic

Current Problem:

Solution: Implement Template Method Pattern:

abstract class GitProvider {
  async call(method: string, endpoint: string, data?: any): Promise<any>;
  async authenticate(): Promise<void>;
  protected abstract request(): Promise<any>;
}

Consolidated Methods:

Estimated Effort: 15-20 hours


2.4 Extract Content Normalization

Current Problem:

Solution: Create src/utils/content-normalizer.ts:

export class ContentNormalizer {
  removeNestedDivs(html: string): string;
  cleanCriticMarkup(text: string): string;
  normalizeLineEndings(text: string): string;
  trimWhitespace(text: string): string;
  normalize(text: string, options?: NormalizeOptions): string;
}

Estimated Effort: 6-10 hours


3. Architectural Improvements - Priority 2

3.1 Unify State Management

Current Problem:

Target: Single reactive state tree with event propagation

Implementation Steps:

  1. Audit all state locations (StateStore, modules, DOM)
  2. Design single state schema
  3. Implement state tree with watchers
  4. Update all modules to use single source
  5. Add state inspection/debugging tools

Estimated Effort: 25-35 hours


3.2 Expand Plugin System

Current State:

Target: Make all major features optional plugins:

Benefits:

Estimated Effort: 30-40 hours


3.3 Central Service Registry

Current Pattern:

Target: Service locator pattern:

export class ServiceRegistry {
  register(name: string, service: any): void;
  get<T>(name: string): T;
  has(name: string): boolean;
}

Estimated Effort: 10-15 hours


3.4 Standardize Error Handling

Current Problem:

Solution: ErrorBoundary pattern with recovery strategies:

export class ErrorBoundary {
  catch(error: Error, context: string): void;
  recover(strategy: RecoveryStrategy): Promise<void>;
}

Estimated Effort: 12-18 hours


4. Documentation Improvements - Priority 3

4.1 Algorithm Documentation

Missing Docs:

Documentation Template:

  1. Algorithm purpose and use case
  2. Input/output specifications
  3. Key steps and logic flow
  4. Time/space complexity
  5. Edge cases and limitations
  6. Code examples

Estimated Effort: 8-12 hours


4.2 Internal API Documentation

Missing Docs:

Estimated Effort: 10-15 hours


4.3 Troubleshooting Guide

Topics:

Estimated Effort: 6-10 hours


4.4 Code Examples & Guides

Content:

Estimated Effort: 8-12 hours


5. Test Improvements - Priority 3

5.1 Improve UIModule Coverage

Current: Hard to test due to monolithic structure Target: >90% coverage after decomposition Approach:

Estimated Effort: 15-20 hours


5.2 Add Missing Test Scenarios

Gaps:

Estimated Effort: 10-15 hours


6. Performance Optimization - Priority 4

6.1 DOM Rendering Optimization

Current Issue: Creates temporary DOM for every element render, no diffing

Solution Options:

  1. Virtual DOM library (Lit, Preact)
  2. Manual diffing with caching
  3. Incremental rendering

Potential Gain: 50-70% faster

Estimated Effort: 30-40 hours


6.2 Translation Processing Optimization

Current Issue: Re-processes all elements on any change

Solution: Incremental segmentation with caching

Potential Gain: 60-80% faster

Estimated Effort: 20-30 hours


6.3 Change Tracking Optimization

Current Issue: Applies all operations sequentially, no caching

Solution: Memo-ized state tree

Potential Gain: 40-50% faster

Estimated Effort: 15-20 hours


6.4 Comment Rendering Optimization

Current Issue: Re-renders all comments on any change, no virtualization

Solution: Virtualized list with memoization

Potential Gain: 80-90% faster

Estimated Effort: 10-15 hours


7. Security Hardening - Priority 4

Current Strengths

Gaps to Address

Estimated Effort: 8-12 hours


8. Implementation Timeline

Phase 1: Quick Wins (Weeks 1-2)

Phase 2: Core Refactoring (Weeks 3-8)

Phase 3: Architecture & Documentation (Weeks 9-14)

Phase 4: Polish & Performance (Weeks 15+)


9. Success Metrics

After refactoring completion:

Metric Current Target
Largest class size 2,554 lines <500 lines
Code duplication High (template, events, providers) Minimal
Test coverage 71% >85%
UIModule testability Low (monolithic) High (modular)
Documentation completeness 70% 95%
Performance (100+ elements) Slow 50-70% faster
Cyclomatic complexity avg High Medium
Maintainability Index Medium High

10. Risk Mitigation

Risk Mitigation
Breaking existing functionality Comprehensive test suite before/after, gradual rollout
Regression in performance Benchmark suite before/after refactoring
Loss of plugin compatibility Version the plugin API, provide migration guide
Team context loss Document decisions, record architecture decisions
Over-engineering Follow YAGNI principle, measure actual needs

For Quick Impact (1-2 weeks)

  1. Remove MainSidebar - Quick win, clear code
  2. Extract template utilities - Reduces duplication immediately
  3. Document algorithms - Improves maintainability

For Long-term Health (2-3 months)

  1. UIModule decomposition - Biggest architectural improvement
  2. Unify state management - Foundation for all other improvements
  3. Expand test coverage - Enables confident refactoring

For Complete Modernization (3-6 months)

  1. Follow Phase 1-4 timeline sequentially
  2. Focus on stabilizing Phase 1 before Phase 2
  3. Get team buy-in on architectural changes

Appendix: Complexity Hotspots

File Lines Issue Priority
UIModule/index.ts 2,554 Monolithic god class P1
TranslationModule/index.ts 1,558 Large feature with many responsibilities P1
UnifiedSidebar.ts 1,371 Complex UI coordinator P2
TranslationView.ts 1,624 Dual-pane UI implementation P2
MainSidebar.ts 1,299 Legacy sidebar (should be removed) P1
EditorToolbar.ts 757 Large toolbar management P3
AzureProvider.ts 942 Provider implementation duplication P2
GitLabProvider.ts 509 Provider implementation duplication P2

Notes for Implementation