- Create HVAC_Shortcodes class to centralize shortcode management - Create HVAC_Scripts_Styles class for all script/style enqueuing - Create HVAC_Route_Manager class for URL routing and redirects - Update HVAC_Plugin to use new architecture components - Remove duplicate functionality from HVAC_Community_Events - Add comprehensive refactoring plan documentation This refactoring resolves duplicate initialization issues and creates a cleaner, more maintainable architecture with clear separation of concerns. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
4.7 KiB
4.7 KiB
HVAC Plugin Architecture Refactoring Plan
Current Issues
- Duplicate Functionality: HVAC_Plugin and HVAC_Community_Events have overlapping responsibilities
- Multiple Initialization: Components are initialized in multiple places causing duplication
- Mixed Concerns: Classes handle multiple unrelated responsibilities
- Inconsistent Patterns: Some classes use singleton, others don't
- Legacy Code: Backward compatibility code mixed with new features
Proposed Architecture
Phase 1: Create Dedicated Single-Responsibility Classes
1.1 HVAC_Shortcodes Class
- Purpose: Register and manage all plugin shortcodes
- Location:
/includes/class-hvac-shortcodes.php - Responsibilities:
- Register all shortcodes in one place
- Handle shortcode callbacks
- Manage shortcode attributes and defaults
1.2 HVAC_Scripts_Styles Class
- Purpose: Manage all script and style enqueuing
- Location:
/includes/class-hvac-scripts-styles.php - Responsibilities:
- Frontend script/style registration and enqueuing
- Admin script/style registration and enqueuing
- Script localization
- Version management for cache busting
1.3 HVAC_Route_Manager Class
- Purpose: Handle all URL routing and redirects
- Location:
/includes/class-hvac-route-manager.php - Responsibilities:
- Legacy URL redirects
- Parent page redirects
- Custom rewrite rules
- Query var registration
Phase 2: Consolidate Authentication and Access Control
2.1 Enhance HVAC_Access_Control
- Move all authentication checks from HVAC_Community_Events
- Centralize page access rules
- Implement filter/action based access control
Phase 3: Refactor Main Plugin Classes
3.1 HVAC_Plugin (Main Plugin Controller)
- Keep:
- Plugin activation/deactivation
- Dependency loading
- Component initialization (single point)
- Hook registration
- Remove:
- Direct script/style enqueuing (move to HVAC_Scripts_Styles)
- Redirect handling (move to HVAC_Route_Manager)
- AJAX handlers (move to respective feature classes)
3.2 HVAC_Community_Events (Deprecate)
- Phase 1: Remove all duplicate functionality
- Phase 2: Convert to compatibility layer
- Phase 3: Add deprecation notices
- Phase 4: Remove entirely in future version
Phase 4: Implement Consistent Patterns
4.1 Singleton Pattern
Apply to classes that should have single instances:
- HVAC_Plugin
- HVAC_Shortcodes
- HVAC_Scripts_Styles
- HVAC_Route_Manager
- HVAC_Access_Control
4.2 Interface-Based Design
Create interfaces for common patterns:
HVAC_Component_Interfacefor initializable componentsHVAC_Ajax_Handler_Interfacefor AJAX handling classesHVAC_Admin_Page_Interfacefor admin page classes
Phase 5: Create Service Container
5.1 HVAC_Container Class
- Purpose: Manage dependency injection
- Features:
- Lazy loading of components
- Dependency resolution
- Service registration
Implementation Order
-
Create new classes (non-breaking additions):
- HVAC_Shortcodes
- HVAC_Scripts_Styles
- HVAC_Route_Manager
-
Move functionality (careful migration):
- Migrate shortcodes from HVAC_Community_Events to HVAC_Shortcodes
- Migrate scripts/styles to HVAC_Scripts_Styles
- Migrate routing logic to HVAC_Route_Manager
-
Update initialization:
- Update HVAC_Plugin to use new classes
- Remove duplicate initializations
-
Deprecate legacy code:
- Add deprecation notices to HVAC_Community_Events methods
- Maintain backward compatibility temporarily
-
Clean up:
- Remove deprecated code in future version
- Update documentation
- Update tests
Benefits
- Clear Separation of Concerns: Each class has a single, well-defined purpose
- Easier Maintenance: Changes to one feature won't affect others
- Better Testing: Isolated components are easier to test
- Reduced Duplication: Single source of truth for each functionality
- Improved Performance: No duplicate initializations or hook registrations
- Easier Onboarding: New developers can understand the architecture quickly
Backward Compatibility Strategy
- Maintain existing hooks: Keep action/filter names unchanged
- Proxy methods: Create proxy methods in deprecated classes
- Gradual migration: Move functionality piece by piece
- Version checks: Add version-based compatibility layers
- Clear deprecation timeline: Document when features will be removed
Success Metrics
- No duplicate component initialization
- All functionality maintained
- No breaking changes for existing users
- Improved code organization
- Reduced file size and complexity
- Better performance metrics