panicdevs/modulite
Composer 安装命令:
composer require panicdevs/modulite
包简介
Automatic Filament Panel Provider discovery for modular Laravel applications with multi-layer caching and performance optimization
关键字:
README 文档
README
Automatic Filament Panel Provider discovery for modular Laravel applications with intelligent caching and performance optimization.
Modulite automatically discovers and registers Filament panels and components across your modular application structure, eliminating the need for manual registration while providing production-ready performance optimizations.
Features
- 🔍 Automatic Discovery: Finds Filament panels, resources, pages, and widgets across modules
- ⚡ Production Optimized: File-based caching system similar to Laravel's bootstrap cache
- 🏗️ Modular Support: Works with both
nwidart/laravel-modulesandpanicdevs/modules - 🎯 Flexible Patterns: Configurable naming patterns and discovery locations
- 📊 Performance Insights: Built-in commands for monitoring and optimization
- 🛡️ Robust Error Handling: Graceful failure modes for production environments
Installation
Install via Composer:
composer require panicdevs/modulite
Publish the configuration file:
php artisan vendor:publish --tag=modulite-config
Quick Start
- Install the package (configuration publishes automatically)
- Register the plugin in your Filament panel providers
- Structure your modules following the expected patterns
- Run optimization for production:
php artisan modulite:cache
Panel Registration
Add the ModulitePlugin to each panel where you want component discovery:
// In your Panel Provider (e.g., AdminPanelProvider.php) use PanicDevs\Modulite\Plugins\ModulitePlugin; public function panel(Panel $panel): Panel { return $panel ->default() ->id('admin') ->path('/admin') ->plugins([ ModulitePlugin::make(), // Add this to discover components // ... other plugins ]) // ... other panel configuration }
That's it! Modulite will automatically discover and register components for this panel.
How It Works
Discovery Process
Modulite works on two levels:
- Panel Providers: Automatically discovered and registered by the service provider
- Components: Discovered by the plugin for specific panels
- Resources: Filament resource classes for CRUD operations
- Pages: Custom Filament pages
- Widgets: Dashboard widgets and components
Module Structure
For a module named User, Modulite expects this structure:
modules/
├── User/
│ ├── Providers/
│ │ └── Filament/
│ │ └── Panels/
│ │ └── UserPanelProvider.php # Panel definition
│ └── Filament/
│ ├── Admin/ # For 'admin' panel
│ │ ├── Resources/
│ │ │ └── UserResource.php
│ │ ├── Pages/
│ │ │ └── UserDashboard.php
│ │ └── Widgets/
│ │ └── UserStatsWidget.php
│ └── Manager/ # For 'manager' panel
│ └── Resources/
│ └── ProfileResource.php
Registration Flow
- Bootstrap: Service provider registers core services during Laravel boot
- Panel Discovery: Panel providers are automatically discovered and registered
- Plugin Registration:
ModulitePluginis registered with specific panels for component discovery - Component Discovery: When panel loads, plugin discovers components (resources, pages, widgets)
- Cache Check: Fast path checks cache file first (per panel)
- Scan & Cache: On cache miss, scans filesystem and caches results
- Component Registration: Discovered components auto-register to the specific panel
Configuration
Cache Settings
Configure caching behavior for optimal performance:
'cache' => [ 'enabled' => env('MODULITE_CACHE_ENABLED', !app()->hasDebugModeEnabled()), 'file' => base_path('bootstrap/cache/modulite.php'), 'ttl' => env('MODULITE_CACHE_TTL', app()->hasDebugModeEnabled() ? 300 : 0), 'auto_invalidate' => app()->hasDebugModeEnabled(), ],
Key Settings:
enabled: Master cache toggle (auto: off in development, on in production)ttl: Cache lifetime in seconds (0 = never expires, recommended for production)auto_invalidate: Automatically clear cache when files change (development only)
Discovery Locations
Define where to scan for components:
'panels' => [ 'locations' => [ 'modules/*/Providers/Filament/Panels', 'foundation/*/Providers/Filament/Panels', ], ], 'components' => [ 'locations' => [ 'modules/*/Filament/{panel}/Resources', 'modules/*/Filament/{panel}/Pages', 'modules/*/Filament/{panel}/Widgets', ], ],
Placeholders:
*: Module wildcard (e.g.,User,Blog){panel}: Panel ID placeholder (e.g.,Admin,Manager)
Validation Rules
Control how strict discovery validation should be:
'panels' => [ 'validation' => [ 'strict_inheritance' => env('MODULITE_STRICT_INHERITANCE', false), 'must_extend' => 'Filament\PanelProvider', 'must_be_instantiable' => true, 'allow_custom_base_classes' => env('MODULITE_ALLOW_CUSTOM_BASE_CLASSES', true), ], ],
When to Use:
strict_inheritance => true: Enforces exact class inheritanceallow_custom_base_classes => false: Only allows direct Filament class inheritance- Use strict settings for large teams to enforce conventions
Module Integration
Choose your module management approach:
'modules' => [ 'approach' => env('MODULITE_APPROACH', 'panicdevs'), // or 'nwidart' 'scan_only_enabled' => true, 'respect_module_priority' => true, ],
Performance Optimization
Configure for production performance:
'performance' => [ 'lazy_discovery' => env('MODULITE_LAZY_DISCOVERY', true), 'memory_optimization' => [ 'batch_size' => 100, 'clear_stat_cache' => true, 'gc_after_scan' => true, ], ],
Environment Variables
Set these in your .env for easy configuration:
# Cache Control MODULITE_CACHE_ENABLED=true MODULITE_CACHE_TTL=0 # Performance MODULITE_LAZY_DISCOVERY=true MODULITE_STATIC_CACHING=true # Validation MODULITE_STRICT_INHERITANCE=false MODULITE_ALLOW_CUSTOM_BASE_CLASSES=true # Debugging MODULITE_LOGGING_ENABLED=false
Production Setup
Optimization Commands
# Cache all discoveries for production php artisan modulite:cache # Clear caches when needed php artisan modulite:cache --force # Check status and performance php artisan modulite:status # Detailed diagnostics php artisan modulite:status --vvv
Deployment Workflow
- Build Assets: Run your normal build process
- Cache Application:
php artisan optimize - Cache Modulite:
php artisan modulite:cache - Deploy: Your cached discoveries are ready
Cache Management
The cache system works like Laravel's bootstrap cache:
# Cache file location bootstrap/cache/modulite.php # Clear with Laravel caches php artisan optimize:clear # Or clear specifically php artisan modulite:cache --force
Troubleshooting
Check Discovery Status
php artisan modulite:status
This shows:
- Configuration summary
- Module status
- Discovered panels and components
- Cache statistics
Common Issues
No panels discovered:
- Check module structure matches expected patterns
- Verify panel classes extend
PanelProvider - Check if modules are enabled
Performance issues:
- Enable caching:
MODULITE_CACHE_ENABLED=true - Set TTL to 0 for production:
MODULITE_CACHE_TTL=0 - Run
php artisan modulite:cache
Components not showing:
- Verify directory structure matches panel patterns
- Check component naming (must end with
Resource,Page,Widget) - Ensure components extend proper Filament base classes
Debug Mode
Enable detailed logging in development:
MODULITE_LOGGING_ENABLED=true MODULITE_LOG_LEVEL=debug
Cache Issues
Clear all caches if you encounter stale data:
php artisan modulite:cache --force php artisan optimize:clear
Performance
Benchmarks
- Cold start (no cache): ~1-20ms depending on module count
- Warm cache: ~1-2ms (file include time)
- Laravel response overhead: <1ms when optimized
Production Optimizations
Modulite automatically optimizes for production:
- Static caching eliminates repeated file reads
- Lazy discovery defers scanning until needed
- Single cache file minimizes I/O operations
- TTL of 0 prevents unnecessary expiration checks
Advanced Usage
Custom Base Classes
You can use custom base classes for components:
'components' => [ 'types' => [ 'resources' => [ 'allow_custom_base_classes' => true, 'strict_inheritance' => false, ], ], ],
Manual Component Registration
For edge cases, disable auto-discovery and register manually:
'components' => [ 'registration' => [ 'auto_register' => false, ], ],
Multiple Panel Support
Modulite automatically handles multiple panels per module. Each panel needs the plugin registered for component discovery:
// AdminPanelProvider.php public function panel(Panel $panel): Panel { return $panel ->id('admin') ->plugins([ ModulitePlugin::make(), ]); } // ManagerPanelProvider.php public function panel(Panel $panel): Panel { return $panel ->id('manager') ->plugins([ ModulitePlugin::make(), ]); }
Components are discovered based on directory structure:
modules/User/Filament/
├── Admin/Resources/UserResource.php # Registers to 'admin' panel
├── Manager/Resources/ProfileResource.php # Registers to 'manager' panel
└── Public/Pages/LoginPage.php # Registers to 'public' panel
Requirements
- PHP 8.2+
- Filament 4.0+
Support
- 📖 Documentation
- 🐛 Issues
Made with ❤️ by PanicDevs
panicdevs/modulite 适用场景与选型建议
panicdevs/modulite 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 349 次下载、GitHub Stars 达 20, 最近一次更新时间为 2025 年 08 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「performance」 「modules」 「caching」 「laravel」 「modular」 「discovery」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 panicdevs/modulite 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 panicdevs/modulite 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 panicdevs/modulite 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This is Paymorrow module for OXID eShop.
g4 application profiler package
CSS/Javascript Minificator, Compressor and Concatenator for TYPO3 - highly configurable frontend asset optimization for CSS/JS merging, minification and compression with optional body parsing, async/defer loading, inline output, data-ignore exclusions, SRI integrity validation/calculation, external
Query caching for Laravel 5
WordPress mu-plugin to remove jQuery Migrate from the list of jQuery dependencies and to allow jQuery to enqueue before </body> instead of in the <head>.
Create link to static resources with cache-breaking segment based on md5 of the file
统计信息
- 总下载量: 349
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 20
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-15