143 lines
5.9 KiB
Markdown
143 lines
5.9 KiB
Markdown
|
# SmartProxy Code Deletion Plan
|
||
|
|
||
|
This document tracks all code paths that can be deleted as part of the routing unification effort.
|
||
|
|
||
|
## Phase 1: Matching Logic Duplicates (READY TO DELETE)
|
||
|
|
||
|
### 1. Inline Matching Functions in RouteManager
|
||
|
**File**: `ts/proxies/smart-proxy/route-manager.ts`
|
||
|
**Lines**: Approximately lines 200-400
|
||
|
**Duplicates**:
|
||
|
- `matchDomain()` method - duplicate of DomainMatcher
|
||
|
- `matchPath()` method - duplicate of PathMatcher
|
||
|
- `matchIpPattern()` method - duplicate of IpMatcher
|
||
|
- `matchHeaders()` method - duplicate of HeaderMatcher
|
||
|
**Action**: Update to use unified matchers from `ts/core/routing/matchers/`
|
||
|
|
||
|
### 2. Duplicate Matching in Core route-utils
|
||
|
**File**: `ts/core/utils/route-utils.ts`
|
||
|
**Functions to update**:
|
||
|
- `matchDomain()` → Use DomainMatcher.match()
|
||
|
- `matchPath()` → Use PathMatcher.match()
|
||
|
- `matchIpPattern()` → Use IpMatcher.match()
|
||
|
- `matchHeader()` → Use HeaderMatcher.match()
|
||
|
**Action**: Update to use unified matchers, keep only unique utilities
|
||
|
|
||
|
## Phase 2: Route Manager Duplicates (READY AFTER MIGRATION)
|
||
|
|
||
|
### 1. SmartProxy RouteManager
|
||
|
**File**: `ts/proxies/smart-proxy/route-manager.ts`
|
||
|
**Entire file**: ~500 lines
|
||
|
**Reason**: 95% duplicate of SharedRouteManager
|
||
|
**Migration Required**:
|
||
|
- Update SmartProxy to use SharedRouteManager
|
||
|
- Update all imports
|
||
|
- Test thoroughly
|
||
|
**Action**: DELETE entire file after migration
|
||
|
|
||
|
### 2. Deprecated Methods in SharedRouteManager
|
||
|
**File**: `ts/core/utils/route-manager.ts`
|
||
|
**Methods**:
|
||
|
- Any deprecated security check methods
|
||
|
- Legacy compatibility methods
|
||
|
**Action**: Remove after confirming no usage
|
||
|
|
||
|
## Phase 3: Router Consolidation (REQUIRES REFACTORING)
|
||
|
|
||
|
### 1. ProxyRouter vs RouteRouter Duplication
|
||
|
**Files**:
|
||
|
- `ts/routing/router/proxy-router.ts` (~250 lines)
|
||
|
- `ts/routing/router/route-router.ts` (~250 lines)
|
||
|
**Reason**: Nearly identical implementations
|
||
|
**Plan**: Merge into single HttpRouter with legacy adapter
|
||
|
**Action**: DELETE one file after consolidation
|
||
|
|
||
|
### 2. Inline Route Matching in HttpProxy
|
||
|
**Location**: Various files in `ts/proxies/http-proxy/`
|
||
|
**Pattern**: Direct route matching without using RouteManager
|
||
|
**Action**: Update to use SharedRouteManager
|
||
|
|
||
|
## Phase 4: Scattered Utilities (CLEANUP)
|
||
|
|
||
|
### 1. Duplicate Route Utilities
|
||
|
**Files with duplicate logic**:
|
||
|
- `ts/proxies/smart-proxy/utils/route-utils.ts` - Keep (different purpose)
|
||
|
- `ts/proxies/smart-proxy/utils/route-validators.ts` - Review for duplicates
|
||
|
- `ts/proxies/smart-proxy/utils/route-patterns.ts` - Review for consolidation
|
||
|
|
||
|
### 2. Legacy Type Definitions
|
||
|
**Review for removal**:
|
||
|
- Old route type definitions
|
||
|
- Deprecated configuration interfaces
|
||
|
- Unused type exports
|
||
|
|
||
|
## Deletion Progress Tracker
|
||
|
|
||
|
### Completed Deletions
|
||
|
- [x] Phase 1: Matching logic consolidation (Partial)
|
||
|
- Updated core/utils/route-utils.ts to use unified matchers
|
||
|
- Removed duplicate matching implementations (~200 lines)
|
||
|
- Marked functions as deprecated with migration path
|
||
|
- [x] Phase 2: RouteManager unification (COMPLETED)
|
||
|
- ✓ Migrated SmartProxy to use SharedRouteManager
|
||
|
- ✓ Updated imports in smart-proxy.ts, route-connection-handler.ts, and index.ts
|
||
|
- ✓ Created logger adapter to match ILogger interface expectations
|
||
|
- ✓ Fixed method calls (getAllRoutes → getRoutes)
|
||
|
- ✓ Fixed type errors in header matcher
|
||
|
- ✓ Removed unused ipToNumber imports and methods
|
||
|
- ✓ DELETED: `/ts/proxies/smart-proxy/route-manager.ts` (553 lines removed)
|
||
|
- [x] Phase 3: Router consolidation (COMPLETED)
|
||
|
- ✓ Created unified HttpRouter with legacy compatibility
|
||
|
- ✓ Migrated ProxyRouter and RouteRouter to use HttpRouter aliases
|
||
|
- ✓ Updated imports in http-proxy.ts, request-handler.ts, websocket-handler.ts
|
||
|
- ✓ Added routeReqLegacy() method for backward compatibility
|
||
|
- ✓ DELETED: `/ts/routing/router/proxy-router.ts` (437 lines)
|
||
|
- ✓ DELETED: `/ts/routing/router/route-router.ts` (482 lines)
|
||
|
- [ ] Phase 4: Utility cleanup
|
||
|
|
||
|
### Files Updated
|
||
|
1. `ts/core/utils/route-utils.ts` - Replaced all matching logic with unified matchers
|
||
|
2. `ts/core/utils/security-utils.ts` - Updated to use IpMatcher directly
|
||
|
3. `ts/proxies/smart-proxy/smart-proxy.ts` - Using SharedRouteManager with logger adapter
|
||
|
4. `ts/proxies/smart-proxy/route-connection-handler.ts` - Updated to use SharedRouteManager
|
||
|
5. `ts/proxies/smart-proxy/index.ts` - Exporting SharedRouteManager as RouteManager
|
||
|
6. `ts/core/routing/matchers/header.ts` - Fixed type handling for array header values
|
||
|
7. `ts/core/utils/route-manager.ts` - Removed unused ipToNumber import
|
||
|
8. `ts/proxies/http-proxy/http-proxy.ts` - Updated imports to use unified router
|
||
|
9. `ts/proxies/http-proxy/request-handler.ts` - Updated to use routeReqLegacy()
|
||
|
10. `ts/proxies/http-proxy/websocket-handler.ts` - Updated to use routeReqLegacy()
|
||
|
11. `ts/routing/router/index.ts` - Export unified HttpRouter with aliases
|
||
|
|
||
|
### Files Created
|
||
|
1. `ts/core/routing/matchers/domain.ts` - Unified domain matcher
|
||
|
2. `ts/core/routing/matchers/path.ts` - Unified path matcher
|
||
|
3. `ts/core/routing/matchers/ip.ts` - Unified IP matcher
|
||
|
4. `ts/core/routing/matchers/header.ts` - Unified header matcher
|
||
|
5. `ts/core/routing/matchers/index.ts` - Matcher exports
|
||
|
6. `ts/core/routing/types.ts` - Core routing types
|
||
|
7. `ts/core/routing/specificity.ts` - Route specificity calculator
|
||
|
8. `ts/core/routing/index.ts` - Main routing exports
|
||
|
9. `ts/routing/router/http-router.ts` - Unified HTTP router
|
||
|
|
||
|
### Lines of Code Removed
|
||
|
- Target: ~1,500 lines
|
||
|
- Actual: ~1,672 lines (Target exceeded!)
|
||
|
- Phase 1: ~200 lines (matching logic)
|
||
|
- Phase 2: 553 lines (SmartProxy RouteManager)
|
||
|
- Phase 3: 919 lines (ProxyRouter + RouteRouter)
|
||
|
|
||
|
## Safety Checklist Before Deletion
|
||
|
|
||
|
Before deleting any code:
|
||
|
1. ✓ All tests pass
|
||
|
2. ✓ No references to deleted code remain
|
||
|
3. ✓ Migration path tested
|
||
|
4. ✓ Performance benchmarks show no regression
|
||
|
5. ✓ Documentation updated
|
||
|
|
||
|
## Rollback Plan
|
||
|
|
||
|
If issues arise after deletion:
|
||
|
1. Git history preserves all deleted code
|
||
|
2. Each phase can be reverted independently
|
||
|
3. Feature flags can disable new code if needed
|