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.
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
| 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 |
- Massive Complexity: Nearly 2,000 lines across 6 files for routing
- Function Duplication: URL parsing logic duplicated between 404.html and routeUtils.js
- Deployment Detection Duplication: Multiple files have similar deployment detection logic
- Configuration Scatter: Route information spread across multiple files
- Maintenance Burden: Changes require updates to multiple files
- Testing Complexity: Each service needs separate testing
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)
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)
}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": {...}
}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>Keep existing App.js structure but use unified service:
import { SGEXRoutingService } from './services/routingService';
const routingService = new SGEXRoutingService();
const routes = routingService.generateRoutes();- 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
- 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
- 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
- Create Unified Service: Build
src/services/routingService.jswith all consolidated logic - Enhance Configuration: Expand
routes-config.jsonwith routing rules - Create Test Suite: Comprehensive tests for all routing scenarios
- Documentation: Complete API documentation for the new service
- Update App.js: Integrate with new routing service
- Replace 404.html: Deploy minimal redirect version
- Remove Legacy Files: Clean up old routing utilities
- Migration Testing: Ensure all existing routes continue working
- Performance Tuning: Optimize service for minimal bundle impact
- Advanced Features: Add monitoring and analytics
- Error Handling: Comprehensive error handling and fallbacks
- Final Testing: Full deployment testing across all scenarios
| 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 |
| 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 |
| File | Reason |
|---|---|
src/App.js |
Already minimal and well-structured |
| Component files | No routing logic, only consume routes |
- Component Registration: Components are already defined in configuration
- React Router Integration: Uses standard React Router patterns
- Development Environment: No impact on local development workflow
- 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
- 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
- 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
- JavaScript bundle size β€ current size
- Initial page load time β€ current performance
- Route generation time < 100ms
- Memory usage β€ current usage
- 90%+ test coverage for routing service
- Zero linting errors
- Complete TypeScript typing
- Comprehensive documentation
- Maintain support for all existing URL patterns
- Provide migration notices for any deprecated features
- Keep legacy functions available during transition period
- Feature flag system to enable/disable new routing service
- Ability to quickly revert to original file structure
- Monitoring and alerting for routing failures
- 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
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.