# Legacy Code Cleanup & Modernization Plan ## Overview This document identifies outdated code, redundant systems, and performance bottlenecks in EasyStream that should be removed or refactored to create a modern, efficient streaming platform. ## Table of Contents 1. [Critical Removals](#critical-removals) 2. [Authentication System Cleanup](#authentication-system-cleanup) 3. [Database Query Optimization](#database-query-optimization) 4. [Frontend JavaScript Modernization](#frontend-javascript-modernization) 5. [File Structure Reorganization](#file-structure-reorganization) 6. [Performance Optimizations](#performance-optimizations) 7. [Migration Checklist](#migration-checklist) --- ## Critical Removals ### 1. Duplicate Authentication Systems **Problem:** Multiple authentication systems exist, causing confusion and security risks. **Files to Remove/Consolidate:** ``` REMOVE: - f_core/f_classes/class.login.php (Old VLogin class) - f_core/f_classes/class.session.php (Redundant with VAuth) - Any references to VLogin in other files KEEP: - f_core/f_classes/class.auth.php (VAuth - Modern system) ``` **Action Plan:** 1. Search codebase for `VLogin` references 2. Replace with `VAuth::getInstance()` 3. Update all login forms to use VAuth 4. Remove class.login.php entirely **Command to find VLogin usage:** ```bash grep -r "VLogin" f_core/ f_modules/ *.php ``` ### 2. Legacy Database Classes **Problem:** Multiple database wrapper classes causing overhead. **Files to Audit:** ``` f_core/f_classes/class.database.php - Keep (ADOdb wrapper) f_core/f_classes/db*.php - Review for redundancy ``` **Action:** Ensure all code uses `VDatabase::getInstance()` and remove any custom DB wrappers. ### 3. Obsolete jQuery Plugins **Problem:** Old jQuery plugins add bloat and security vulnerabilities. **Files to Remove:** ``` f_scripts/be/js/init1.min.js - Contains jquery.form plugin (outdated) f_scripts/*/jquery.*.min.js - Review each for necessity ``` **Replace With:** - Native FormData API - Fetch API - Modern ES6+ code ### 4. Inline JavaScript in PHP Files **Problem:** JavaScript mixed with PHP makes maintenance difficult. **Action:** 1. Extract all ` ``` Or use `async` for independent scripts: ```html ``` --- ## Migration Checklist ### Phase 1: Remove Duplicate Auth Systems - [ ] Find all VLogin references - [ ] Replace with VAuth - [ ] Test authentication flows - [ ] Remove class.login.php - [ ] Remove class.session.php (if redundant) - [ ] Update documentation ### Phase 2: Database Optimization - [ ] Add missing indexes - [ ] Audit for N+1 queries - [ ] Implement query caching - [ ] Use JOINs instead of separate queries - [ ] Enable prepared statement caching - [ ] Monitor slow query log ### Phase 3: Frontend Modernization - [ ] Create native JS utility library - [ ] Migrate browse.init.js to modern JS - [ ] Migrate login.init.js to modern JS - [ ] Migrate jquery.init.js to modern JS - [ ] Remove jQuery dependency - [ ] Test all user interactions - [ ] Update build process ### Phase 4: File Cleanup - [ ] Remove obsolete files (.old, .backup) - [ ] Reorganize file structure - [ ] Remove unused libraries - [ ] Clean up inline JavaScript - [ ] Move JS to external files ### Phase 5: Performance Optimization - [ ] Implement lazy loading for images - [ ] Add Redis caching for queries - [ ] Enable browser caching headers - [ ] Minify and bundle assets - [ ] Implement code splitting - [ ] Add service worker for offline support (optional) ### Phase 6: Testing & Validation - [ ] Load test with Apache Bench - [ ] Profile with Chrome DevTools - [ ] Check for memory leaks - [ ] Verify all features work - [ ] Test on slow connections (throttling) - [ ] Mobile device testing --- ## Performance Metrics to Track ### Before Cleanup Measure these metrics before starting: ```bash # Page load time curl -o /dev/null -s -w 'Total: %{time_total}s\n' http://localhost/ # Time to first byte curl -o /dev/null -s -w 'TTFB: %{time_starttransfer}s\n' http://localhost/ # Database query count (add logging) grep "SELECT" /var/log/mysql/query.log | wc -l ``` ### After Cleanup - Target Metrics - Page load time: < 2 seconds - Time to first byte: < 500ms - Total JavaScript size: < 200KB - Database queries per page: < 10 - Memory usage: < 128MB per request --- ## Resource Savings Estimate ### Expected Improvements | Metric | Before | After | Improvement | |--------|--------|-------|-------------| | Page Load Time | 4-6s | 1-2s | 70% faster | | JavaScript Size | 500KB | 150KB | 70% smaller | | Database Queries | 30-50 | 5-10 | 80% fewer | | Memory per Request | 256MB | 64MB | 75% less | | Server Requests | 40+ | 15-20 | 60% fewer | ### Cost Savings For a platform with 10,000 daily active users: - **Server costs**: 50% reduction (fewer resources needed) - **Bandwidth**: 60% reduction (smaller assets) - **Database load**: 75% reduction (fewer queries, better caching) --- ## Next Steps 1. **Backup everything** before making changes 2. **Start with authentication** cleanup (lowest risk) 3. **Test thoroughly** after each phase 4. **Monitor performance** metrics 5. **Document changes** as you go --- **Created:** January 2025 **Status:** Planning Phase