This document describes the modular architecture of ThreadPilot, designed for maintainability, testability, and future extensibility.
- Core Services: Direct OS interaction (Process, Power Plan, CPU Topology)
- Process Management: Business logic for process monitoring and management
- Application Services: UI and application-level functionality
- Presentation Layer: ViewModels and Views with MVVM pattern
- Centralized service configuration in
ServiceConfiguration.cs - Service factory pattern for advanced service management
- Proper lifecycle management for all services
- Services communicate through well-defined events
- Loose coupling between components
- Reactive UI updates through observable patterns
ThreadPilot/
βββ Services/
β βββ Core/ # Base interfaces and implementations
β β βββ ISystemService.cs # Base interface for system services
β β βββ BaseSystemService.cs # Base implementation with common functionality
β βββ ProcessManagement/ # Process-related services
β β βββ IProcessManagementService.cs
β βββ ServiceConfiguration.cs # Centralized DI configuration
β βββ ServiceFactory.cs # Service factory for advanced management
βββ Models/
β βββ Core/ # Base model interfaces and implementations
β β βββ IModel.cs # Base model interface and validation
β βββ Process/ # Process-related models
β βββ PowerPlan/ # Power plan models
β βββ Configuration/ # Configuration models
βββ ViewModels/
β βββ BaseViewModel.cs # Enhanced base ViewModel with error handling
β βββ ViewModelFactory.cs # Factory for ViewModel creation and management
βββ Views/ # XAML views and code-behind
βββ Converters/ # Value converters for data binding
βββ Helpers/ # Utility classes and extension methods
βββ Tests/ # Unit and integration tests
Base interfaces and implementations for all services:
- ISystemService: Base interface with availability tracking and lifecycle management
- BaseSystemService: Common functionality for initialization, disposal, and error handling
Direct interaction with the operating system:
IProcessService: Process enumeration and manipulationIPowerPlanService: Windows power plan managementICpuTopologyService: CPU topology detection and affinity management
Business logic for process monitoring:
IProcessMonitorService: WMI-based process event monitoringIProcessPowerPlanAssociationService: Process-to-power plan associationsIProcessMonitorManagerService: Orchestrates process monitoringIGameBoostService: Game detection and performance optimization
Application-level functionality:
IApplicationSettingsService: Configuration persistenceINotificationService: User notifications and system trayIAutostartService: Windows startup integrationIEnhancedLoggingService: Structured logging with file persistence
The ServiceFactory class provides:
- Centralized service creation with dependency resolution
- Lifecycle management for
ISystemServiceimplementations - Automatic initialization and disposal of managed services
- Error handling and logging for service operations
The BaseViewModel class provides:
- Error Handling: Centralized error management with logging
- Status Management: Busy states and status messages
- Async Operations: Helper methods for async operations with error handling
- Logging Integration: Automatic user action logging
- Lifecycle Management: Proper initialization and disposal
The ViewModelFactory class provides:
- Dependency injection for ViewModels
- Automatic initialization of ViewModels
- Lifecycle management and disposal
- Error handling during creation and initialization
The IModel interface provides:
- Identity: Unique ID and timestamps
- Validation: Built-in validation framework
- Change Tracking: Property change notifications
- Cloning: Deep copy support
Models are organized by domain:
- Process Models: Process information and metadata
- Power Plan Models: Power plan configurations
- Configuration Models: Application settings and associations
Centralized configuration with methods for each service category:
ConfigureServiceInfrastructure(): Logging and factoriesConfigureCoreSystemServices(): OS interaction servicesConfigureProcessManagementServices(): Business logic servicesConfigureApplicationLevelServices(): UI and application servicesConfigurePresentationLayer(): ViewModels and Views
Automatic validation of service configuration at startup:
- Ensures all required services can be resolved
- Validates service dependencies
- Provides clear error messages for configuration issues
- Enhanced Logging Service: File-based logging with rotation
- Structured Events: Predefined event types for different operations
- User Action Logging: Audit trail for user interactions
- Error Correlation: Consistent error tracking across services
- Service Level: Try-catch with logging and graceful degradation
- ViewModel Level: User-friendly error messages with technical logging
- Application Level: Global exception handling with recovery
- Service interfaces enable easy mocking
- BaseViewModel provides testable error handling
- Model validation can be tested independently
- Service factory enables testing of service interactions
- Event-driven architecture allows testing of component communication
- Configuration validation ensures proper setup
- Implement appropriate base interface (
ISystemServicefor system services) - Add to relevant service category in
ServiceConfiguration - Follow established patterns for error handling and logging
- Create domain-specific models with validation
- Implement services following the established patterns
- Create ViewModels inheriting from
BaseViewModel - Use dependency injection for all dependencies
- Service factory enables lazy loading of services
- Event-driven architecture allows for efficient updates
- Structured logging provides performance monitoring data
- Always implement proper disposal for resources
- Use structured logging for all operations
- Implement graceful degradation for optional features
- Follow async/await patterns consistently
- Inherit from
BaseViewModelfor consistent functionality - Use
ExecuteAsyncmethods for error handling - Implement proper disposal for event subscriptions
- Log user actions for audit purposes
- Implement validation for all business rules
- Use property change notifications for UI binding
- Provide meaningful error messages
- Support cloning for undo/redo functionality
This architecture provides a solid foundation for maintainable, testable, and extensible code while following established patterns and best practices.