Created docs/P2.1-NATIVE-REFACTORING-ANALYSIS.md with: - Current state analysis (Android: 2,782 lines, iOS: 2,047 lines) - Inventory of existing services (many already extracted!) - Refactoring strategy: Focus on making plugin a thin adapter - Next steps: Analyze remaining methods, create extraction plan Key Finding: Many services already exist on both platforms. Refactoring should focus on delegation to existing services rather than creating new ones. Verification: - Analysis document created ✅ - Existing services inventoried ✅ - Strategy defined ✅
4.1 KiB
4.1 KiB
Priority 2.1: Native Plugin Refactoring - Analysis
Purpose: Analyze current native plugin structure and create refactoring plan to extract services from god classes.
Owner: Development Team
Last Updated: 2025-12-23
Status: analysis
Current State
Android: DailyNotificationPlugin.kt
- Location:
android/src/main/java/com/timesafari/dailynotification/DailyNotificationPlugin.kt - Size: ~2,782 lines (per ChatGPT feedback)
- Type: Capacitor Plugin class (extends
Plugin)
iOS: DailyNotificationPlugin.swift
- Location:
ios/Plugin/DailyNotificationPlugin.swift - Size: ~2,047 lines (per ChatGPT feedback)
- Type: Capacitor Plugin class (extends
CAPPlugin)
Refactoring Goals
Target Services (from ChatGPT feedback)
- SchedulerService - Schedule management logic
- PermissionService - Permission handling
- Power/ExactAlarmService - Power management and exact alarm handling
- ReactivationService - Cold start recovery and reactivation
- RollingWindowService - Rolling window and rate limiting
- Storage/StateRepository - Database and state management
- FetcherBridge - Native fetcher registration and calling
Principles
- Thin Plugin Adapter: Plugin class should only:
- Parse/validate input
- Call platform service
- Map exceptions to plugin errors
- Service-Oriented: Real logic lives in services
- Testability: Services should be independently testable
- No Breaking Changes: Maintain existing API surface
Analysis Steps
- Inventory Current Methods - List all methods in both plugin classes
- Identify Service Boundaries - Group methods by logical service
- Check Existing Services - See what's already extracted
- Create Extraction Plan - Define safe, incremental extraction order
- Define Service Interfaces - Establish contracts for each service
Analysis Results
Good News: Many Services Already Extracted!
Both platforms have already extracted significant functionality into services:
Android Services Already Exist:
- ✅
PermissionManager.java- Permission handling - ✅
DailyNotificationScheduler.java- Scheduling logic - ✅
ReactivationManager.kt- Cold start recovery - ✅
DailyNotificationRollingWindow.java- Rolling window logic - ✅
DailyNotificationStorage.java- Storage abstraction - ✅
DailyNotificationExactAlarmManager.java- Exact alarm handling - ✅
NativeNotificationContentFetcher.java- Fetcher interface - ✅
DailyNotificationPerformanceOptimizer.java- Performance optimization - ✅
TimeSafariIntegrationManager.java- Integration orchestration
iOS Services Already Exist:
- ✅
DailyNotificationScheduler.swift- Scheduling logic - ✅
DailyNotificationReactivationManager.swift- Recovery - ✅
DailyNotificationRollingWindow.swift- Rolling window - ✅
DailyNotificationStorage.swift- Storage abstraction - ✅
DailyNotificationPowerManager.swift- Power management - ✅
DailyNotificationStateActor.swift- Thread-safe state - ✅
DailyNotificationBackgroundTaskManager.swift- Background tasks
Remaining Work
The plugin classes still contain:
- Direct database access - Should use Storage service
- Business logic - Should delegate to services
- Error handling - Should use ErrorHandler service
- Validation logic - Should be in service layer
- Orchestration - Should use IntegrationManager (Android) or similar (iOS)
Refactoring Strategy
Since many services already exist, the refactoring should focus on:
- Removing direct service instantiation from plugin methods
- Delegating all business logic to existing services
- Making plugin class a thin adapter that only:
- Parses/validates input
- Calls service methods
- Maps exceptions to plugin errors
- Consolidating duplicate logic into services
Next Steps
- ✅ Inventory existing services (DONE)
- ⏭️ Analyze plugin methods to identify what still needs extraction
- ⏭️ Create extraction plan focusing on delegation, not new services
- ⏭️ Implement refactoring in small batches