The ServiceExample_Settings plugin is a comprehensive educational example that demonstrates how to use BrainDrive's Settings Service Bridge for persistent configuration management. This plugin serves as a practical reference for developers learning to build BrainDrive plugins with production-ready error handling and best practices.
- Theme Selector Module: Switch between light and dark themes with real-time feedback
- Persistent Storage: Settings automatically saved to database and retrieved on reload
- User-Scoped Settings: Proper context management for user-specific configurations
- Visual Status Indicators: Real-time service status, retry counts, and operation feedback
- Service Validation: Comprehensive checks for service availability before operations
- Error Categorization: Network, service, permission, and validation error types
- Retry Logic: Exponential backoff (1s, 2s, 4s) for transient failures
- Graceful Degradation: Fallback to defaults when services fail
- Transactional Operations: Rollback support on failed operations
- Comprehensive Documentation: 717-line developer guide with production patterns
- Educational Logging: Detailed console output explaining each step of settings operations
- Best Practices Demonstration: Error handling, retry logic, and service validation
- Type Safety: Full TypeScript implementation with proper interfaces
- Module Federation: Optimized webpack configuration for efficient loading
- Class-Based Components: React components designed for Module Federation compatibility
- Settings Service Bridge Pattern: Proper abstraction over BrainDrive's Settings Service
- Production Ready: Minified bundles and optimized performance
Theme Selector (theme-selector)
- Interactive light/dark theme switching with immediate visual feedback
- Persistent theme storage using Settings Service Bridge with user scope
- Comprehensive error handling with retry logic and rollback capabilities
- Real-time status monitoring with service availability indicators
- Educational logging for debugging and learning purposes
The plugin includes sophisticated Settings Service Bridge integration that provides:
- User-Scoped Settings with proper context management (
{ userId: 'current' }) - Automatic Error Recovery with categorized error handling and retry logic
- Service Validation ensuring Settings Service availability before operations
- Transactional Operations with rollback support on failures
- Educational Logging for debugging and learning with detailed console output
src/components/ThemeSelector.tsx- Main demo component with comprehensive error handlingsrc/styles/theme-settings.css- Theme-aware CSS with light/dark theme variableslifecycle_manager.py- Python lifecycle management for the pluginsrc/services/index.ts- Service bridge integration patterns
README.md- Quick start guide and overview (154 lines)DEVELOPER_GUIDE.md- Comprehensive 717-line developer guide with best practicesRELEASE.md- This release documentation
plugin.json- Plugin metadata and module definitionspackage.json- Dependencies and build scriptswebpack.config.js- Optimized Module Federation configurationtsconfig.json- TypeScript configuration
- Copy the plugin to your BrainDrive
PluginBuilddirectory - Run
npm installto install dependencies - Run
npm run buildto build the plugin - Load the plugin in BrainDrive
- Add the Theme Selector module to your BrainDrive workspace
- Test theme switching by clicking Light/Dark theme buttons
- Watch real-time feedback with status indicators and loading states
- Monitor error handling by testing with network issues or service unavailability
- Check console logs for educational insights and debugging information
- Refresh the page to verify settings persistence
This plugin demonstrates Settings Service Bridge usage only. Theme changes are saved to the database but don't affect the global BrainDrive theme since this is an isolated educational demo.
This plugin teaches developers:
- Settings Service Bridge Integration: How to properly integrate with BrainDrive's Settings Service
- User-Scoped Configuration: Best practices for user-specific settings management
- Production Error Handling: Comprehensive error categorization, retry logic, and recovery
- Service Validation: Ensuring service availability and graceful degradation
- Transactional Operations: Rollback patterns for failed operations
- TypeScript Usage: Proper typing for BrainDrive plugin development
- Module Federation: Webpack configuration for plugin architecture
- React Version: 18.3.1
- TypeScript: 5.7.3
- Webpack: 5.98.0
- Module Federation: Enabled for remote loading
- Bundle Size: Optimized for production (minified)
- Browser Compatibility: Modern browsers with ES2020 support
- Error Handling: Production-ready with retry logic and categorization
- Network Errors: Connection issues, timeouts (retryable with exponential backoff)
- Service Errors: Settings service unavailable (retryable)
- Permission Errors: Authorization failures (not retryable, graceful fallback)
- Validation Errors: Invalid data provided (not retryable, user feedback)
- Generic Errors: Unknown errors (potentially retryable with fallback)
- Exponential Backoff: 1s, 2s, 4s retry delays for transient failures
- Graceful Degradation: Fallback to default values when services fail
- Rollback Support: Automatic rollback to previous state on operation failures
- User Feedback: Clear, categorized error messages for different failure types
- See
README.mdfor basic usage and setup - See
DEVELOPER_GUIDE.mdfor comprehensive development guide with 717 lines of best practices - Check component files for inline documentation and production patterns
All code examples in the documentation are synchronized with the actual implementation, ensuring consistency and accuracy for learning production-ready patterns.
- Scope Resolution: Fixed backend to resolve
'current'user_id before duplicate checking - Duplicate Records: Prevented multiple database entries for same setting
- Context Usage: Corrected from
{ scope: 'user' }to{ userId: 'current' } - UI Styling: Improved light theme colors and text visibility
- Text Spacing: Fixed missing text and spacing issues in status displays
- Error Handling: Added comprehensive error categorization and retry logic
- Service Validation: Implemented service availability checking
- Status Indicators: Added real-time service status and retry count displays
- Educational Content: Added demo limitation notes and best practices documentation
This plugin serves as a reference implementation. When contributing:
- Maintain educational value and comprehensive documentation
- Ensure all examples match actual implementation
- Include educational logging for debugging
- Follow TypeScript best practices
- Test error scenarios as thoroughly as success scenarios
- Maintain production-ready error handling patterns
Part of the BrainDrive platform - see main project license.
Built with ❤️ by the BrainDrive Team
This plugin demonstrates the power and reliability of BrainDrive's Settings Service Bridge with production-ready error handling and best practices.