The Service Configuration System provides centralized management of cloud storage service configurations, capabilities, and health monitoring for Stratofusion.
Overview
This system addresses the need for:
Centralized Configuration: All service settings in one place.
Dynamic Service Registration: Services are registered based on configuration.
Health Monitoring: Real-time service health tracking.
Capability Management: Define what each service can do.
Configuration Validation: Ensure services are properly configured.
Central registry for accessing all service configurations:
import{ getServiceConfigRegistry }from"~/config/services";const registry =getServiceConfigRegistry();// Get service configurationconst config = registry.getServiceConfig("google");// Get service capabilitiesconst capabilities = registry.getServiceCapabilities("google");// Validate configurationconst validation = registry.validateServiceConfig("google");// Get services by capabilityconst searchServices = registry.getServicesByCapability("supportsSearch");
3a. Declarative Service Implementation Registration
Service implementations are registered via a central, declarative loader map that the ServiceRegistry consumes during initialization (server-side only):
This keeps registration consistent and avoids hardcoded switch statements.
Only configured services are registered.
Client bundles remain lean since dynamic requires are server-only.
Example: How the registry uses the loader map
import{ getServiceConfigRegistry }from"~/config/services";import{ getImplementationLoader }from"~/config/services/registration";import{CloudStorageServiceFactory}from"~/services/ServiceRegistry";const factory =newCloudStorageServiceFactory();const config =getServiceConfigRegistry();for(const s of config.getAvailableServices().filter((t)=> config.isServiceConfigured(t))){const loader =getImplementationLoader(s);if(loader) factory.registerServiceConstructor(s, loader);}
Config-driven Capability Lookup
Both the ServiceRegistry and the ServiceFactory resolve capabilities exclusively from the centralized configuration. To change what a service supports, edit its capabilities in the corresponding *.config.ts file; no code changes are required.
4. Health Monitoring
Real-time health monitoring for all services:
import{ getServiceHealthMonitor }from"~/services/health/ServiceHealthMonitor";const monitor =getServiceHealthMonitor();// Check service healthconst healthResult =await monitor.checkServiceHealth("google");// Get health reportconst report = monitor.getServiceHealthReport("google");// Start monitoring all configured servicesmonitor.startMonitoringAll();
import{ getServiceConfigRegistry }from"~/config/services";const registry =getServiceConfigRegistry();// Check if service is configuredif(registry.isServiceConfigured("google")){console.log("Google Drive is ready to use");}else{console.log("Google Drive needs configuration");}
Health Monitoring
import{ getServiceHealthMonitor }from"~/services/health/ServiceHealthMonitor";const monitor =getServiceHealthMonitor();// Start monitoringmonitor.startMonitoringAll();// Get health statusconst reports = monitor.getAllServiceHealthReports();reports.forEach(report =>{console.log(`${report.serviceType}: ${report.status} (${report.uptime}% uptime)`);});
Using Status Components
import{ServiceStatusDashboard,ServiceHealthIndicator}from"~/components/service-status";// Full dashboardfunctionAdminPage(){return<ServiceStatusDashboard/>;}// Individual service indicatorfunctionHeader(){return(<divclassName="flex gap-2"><ServiceHealthIndicatorserviceType="google"variant="badge"/><ServiceHealthIndicatorserviceType="onedrive"variant="badge"/></div>);}
Environment Variables
Each service requires specific environment variables:
Define Capabilities: Specify what the service supports
Add Validation: Include configuration validation function
Register in Index: Add to the central registry (src/config/services/index.ts)
Add Implementation Loader: Add a loader entry in src/config/services/registration.ts that returns an instance of your service class
Update Types: Add service type to ServiceType union (src/types/services.ts)
Create Service Implementation: Implement the actual service class (e.g., src/services/NewService.ts)
Add Environment Variables: Update .env.example.template and any relevant service templates
Testing
The system includes comprehensive tests:
# Run configuration testspnpmtest src/config/services
# Run health monitoring testspnpmtest src/services/health
# Run utility testspnpmtest src/lib/service-config
# Run all service-related testspnpmtest --grep "service"
Benefits
Centralized Management: All service configurations in one place
Dynamic Registration: Services are only registered if properly configured
Health Monitoring: Real-time status tracking with historical data
Capability Detection: Runtime discovery of service features
Configuration Validation: Automatic validation of service setup
Type Safety: Full TypeScript support with proper type definitions
Testing: Comprehensive test coverage for reliability
Extensibility: Easy to add new services following established patterns
Integration with Service Registry
The configuration system integrates seamlessly with the existing Service Registry:
import{ getServiceRegistry, initializeServiceRegistry }from"~/services/ServiceRegistry";// Initialize with configuration-aware registrationconst registry =initializeServiceRegistry();// Only configured services are registeredconst configuredServices = registry.getConfiguredServices();// Get comprehensive service statusconst serviceStatus = registry.getServiceStatus();
This ensures that only properly configured services are available for use, improving reliability and user experience.