Skip to content

Latest commit

Β 

History

History
266 lines (205 loc) Β· 10.6 KB

File metadata and controls

266 lines (205 loc) Β· 10.6 KB

SGEX Routing Services Consolidation Proposal

Executive Summary

The current SGEX routing architecture is distributed across multiple files with significant complexity and duplication. This proposal outlines a comprehensive consolidation strategy to simplify and unify all routing services while maintaining functionality.

Current Routing Architecture Analysis

File Distribution and Complexity

public/404.html                   627 lines  - GitHub Pages routing logic
public/routeConfig.js             373 lines  - Route configuration service  
src/utils/lazyRouteUtils.js       622 lines  - Lazy loading utilities
src/utils/routeUtils.js           144 lines  - Route parsing utilities
public/routes-config.json         159 lines  - Route definitions
src/App.js                         45 lines  - React Router setup
                                ============
Total:                          1,970 lines

Current Services Overview

File Purpose Key Functions Issues
404.html GitHub Pages fallback routing URL parsing, deployment detection, redirects 627 lines of complex logic, multiple functions
routeConfig.js Configuration service Component loading, path resolution Deployment detection duplication
lazyRouteUtils.js Component lazy loading Route generation, Suspense boundaries Massive 622-line file
routeUtils.js Route utilities Component validation, URL parsing Functionality overlap with 404.html
routes-config.json Route definitions Component configurations Static configuration
App.js React Router setup Route rendering Minimal, good as-is

Problems with Current Architecture

  1. Massive Complexity: Nearly 2,000 lines across 6 files for routing
  2. Function Duplication: URL parsing logic duplicated between 404.html and routeUtils.js
  3. Deployment Detection Duplication: Multiple files have similar deployment detection logic
  4. Configuration Scatter: Route information spread across multiple files
  5. Maintenance Burden: Changes require updates to multiple files
  6. Testing Complexity: Each service needs separate testing

Proposed Consolidated Architecture

🎯 Target: Single Unified Routing Service

Consolidate all routing logic into a single, cohesive service with clear separation of concerns:

src/services/routingService.js    ~400 lines  - Unified routing service
public/routes-config.json         ~200 lines  - Enhanced route definitions  
public/404.html                   ~50 lines   - Minimal GitHub Pages redirect
src/App.js                        ~45 lines   - React Router setup (unchanged)
                                 ============
Total:                           ~695 lines   (65% reduction)

Core Consolidation Strategy

1. Unified Routing Service (src/services/routingService.js)

Combine all routing logic into a single, well-structured service:

// Unified routing service structure
export class SGEXRoutingService {
  // Configuration management
  loadConfiguration()
  getDeploymentType()
  getComponentConfiguration()
  
  // URL processing (consolidated from 404.html and routeUtils.js)
  parseURL(url)
  validateDAKComponent(component)
  extractRouteContext(pathname)
  
  // Route generation (consolidated from lazyRouteUtils.js)
  generateRoutes()
  createLazyComponent(componentName)
  
  // Deployment handling (consolidated from 404.html and routeConfig.js)
  detectDeploymentContext()
  handleGitHubPagesRouting()
  
  // Navigation and redirects
  navigateToRoute(path, context)
  generateRedirectURL(targetPath, context)
}

2. Enhanced Configuration (public/routes-config.json)

Expand the configuration to include all routing logic currently hardcoded:

{
  "routing": {
    "deploymentTypes": ["main", "deploy", "feature"],
    "githubPages": {
      "basePaths": ["/sgex/", "/sgex/main/", "/sgex/{branch}/"],
      "redirectPatterns": {...}
    },
    "urlPatterns": {
      "dakComponent": "/{component}/{user}/{repo}/{branch?}/*",
      "documentation": "/docs/{docId?}",
      "standard": "/component-name"
    }
  },
  "components": {...},
  "deploymentRules": {...}
}

3. Minimal 404.html (~50 lines)

Reduce to essential GitHub Pages redirect only:

<script>
  // Simple redirect to main SPA with full URL preservation
  const fullURL = window.location.href;
  const redirectURL = fullURL.replace(window.location.pathname, '/sgex/');
  window.location.replace(redirectURL + '?route=' + encodeURIComponent(window.location.pathname + window.location.search + window.location.hash));
</script>

4. React Integration (App.js unchanged)

Keep existing App.js structure but use unified service:

import { SGEXRoutingService } from './services/routingService';

const routingService = new SGEXRoutingService();
const routes = routingService.generateRoutes();

Consolidation Benefits

πŸ“Š Quantitative Improvements

  • 65% Code Reduction: From 1,970 to ~695 lines
  • 83% File Reduction: From 6 to 1 main routing file
  • Single Source of Truth: All routing logic in one place
  • Unified Testing: One comprehensive test suite instead of multiple

πŸ”§ Qualitative Improvements

  • Simplified Maintenance: Changes only require updates to one service
  • Consistent Behavior: No more divergent routing logic across files
  • Better Error Handling: Centralized error handling and logging
  • Improved Performance: Reduced JavaScript bundle size
  • Enhanced Debugging: Single location for all routing issues

πŸš€ Development Experience

  • Easier Onboarding: Developers only need to understand one routing service
  • Faster Development: No need to navigate multiple files for routing changes
  • Better Testing: Comprehensive unit tests for all routing functionality
  • Clearer Documentation: Single source of truth for routing behavior

Implementation Plan

Phase 1: Foundation Setup (Week 1)

  1. Create Unified Service: Build src/services/routingService.js with all consolidated logic
  2. Enhance Configuration: Expand routes-config.json with routing rules
  3. Create Test Suite: Comprehensive tests for all routing scenarios
  4. Documentation: Complete API documentation for the new service

Phase 2: Integration (Week 2)

  1. Update App.js: Integrate with new routing service
  2. Replace 404.html: Deploy minimal redirect version
  3. Remove Legacy Files: Clean up old routing utilities
  4. Migration Testing: Ensure all existing routes continue working

Phase 3: Optimization (Week 3)

  1. Performance Tuning: Optimize service for minimal bundle impact
  2. Advanced Features: Add monitoring and analytics
  3. Error Handling: Comprehensive error handling and fallbacks
  4. Final Testing: Full deployment testing across all scenarios

Detailed File-by-File Changes

Files to Consolidate β†’ New Service

Current File Lines New Location Purpose
public/404.html 627 routingService.js β†’ handleGitHubPagesRouting() GitHub Pages logic
public/routeConfig.js 373 routingService.js β†’ loadConfiguration() Configuration loading
src/utils/lazyRouteUtils.js 622 routingService.js β†’ generateRoutes() Route generation
src/utils/routeUtils.js 144 routingService.js β†’ parseURL() URL parsing

Files to Enhance

File Current New Purpose
public/routes-config.json 159 lines 200 lines - Enhanced with routing rules
public/404.html 627 lines 50 lines - Minimal redirect only

Files to Keep Unchanged

File Reason
src/App.js Already minimal and well-structured
Component files No routing logic, only consume routes

Risk Assessment and Mitigation

Low Risk Items βœ…

  • Component Registration: Components are already defined in configuration
  • React Router Integration: Uses standard React Router patterns
  • Development Environment: No impact on local development workflow

Medium Risk Items ⚠️

  • GitHub Pages Deployment: Requires careful testing of 404.html changes
    • Mitigation: Deploy to feature branch first, comprehensive testing
  • URL Pattern Changes: Ensure all existing URLs continue working
    • Mitigation: Maintain backward compatibility mapping

High Risk Items 🚨

  • Bundle Size Impact: Large routing service could affect performance
    • Mitigation: Implement lazy loading within the service itself
  • Breaking Changes: Risk of disrupting existing deployments
    • Mitigation: Phased deployment with rollback plan

Success Criteria

Functional Requirements βœ…

  • All existing routes continue working
  • Direct URL entry works 100% of the time
  • Context preservation (user/repo/branch) maintained
  • GitHub Pages deployment functions correctly
  • All component lazy loading works

Performance Requirements ⚑

  • JavaScript bundle size ≀ current size
  • Initial page load time ≀ current performance
  • Route generation time < 100ms
  • Memory usage ≀ current usage

Quality Requirements πŸ”§

  • 90%+ test coverage for routing service
  • Zero linting errors
  • Complete TypeScript typing
  • Comprehensive documentation

Migration Strategy

Backward Compatibility

  • Maintain support for all existing URL patterns
  • Provide migration notices for any deprecated features
  • Keep legacy functions available during transition period

Rollback Plan

  • Feature flag system to enable/disable new routing service
  • Ability to quickly revert to original file structure
  • Monitoring and alerting for routing failures

Testing Strategy

  • Unit tests for all routing service methods
  • Integration tests for React Router integration
  • End-to-end tests for all deployment scenarios
  • Performance testing for bundle size and load times

Conclusion

This consolidation proposal offers significant improvements in maintainability, performance, and developer experience while reducing complexity by 65%. The unified routing service will serve as a single source of truth for all SGEX routing logic, making the codebase more maintainable and easier to understand.

The phased implementation approach ensures minimal risk while delivering immediate benefits. With proper testing and gradual deployment, this consolidation will establish a robust foundation for future SGEX routing needs.

Recommendation: Proceed with this consolidation as it addresses the core complexity issues while maintaining all existing functionality.