- Keep only index, getting-started, invariants, performance, troubleshooting, and file-organization-summary in docs/ root - Add docs/architecture/ (storage, database interfaces, native fetcher) - Add docs/deployment/ (deployment-guide, DEPLOYMENT_CHECKLIST) - Add docs/compliance/ (accessibility, legal, observability) - Move integration guides and host-app docs to docs/integration/ - Move design/planning and prefetch docs to docs/design/ - Move Android consuming-app and comparison docs to docs/platform/android/ - Move DEPLOYMENT_SUMMARY and TODO-CLASSIFICATION to docs/progress/ - Archive deprecated platform-capability-reference to docs/_archive/ - Point platform-capability links to alarms/01-platform-capability-reference.md - Update docs/00-INDEX.md with new sections and paths - Fix cross-references in README, deployment, progress, design, testing, and test-app docs - Remove one-off COMMIT_MESSAGE.txt
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