hryvinskyi / magento2-module-detector
Magento 2 Module Detector - Identifies potentially unused modules for security and performance optimization
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:magento2-module
Requires
- php: >=8.1
- magento/framework: >=103.0.0
- magento/module-backend: *
- magento/module-ui: *
This package is auto-updated.
Last update: 2025-07-11 16:35:48 UTC
README
A comprehensive Magento 2 module for detecting potentially unused modules in your Magento installation. This security-focused tool helps identify modules that may be safely removed to improve performance and reduce security surface area.
Features
Comprehensive Analysis
- Database Usage Detection: Analyzes declared tables, row counts, and EAV attributes
- Configuration Analysis: Checks for system configuration usage
- File System Inspection: Examines controllers, models, blocks, and other components
- Dependency Tracking: Identifies modules that depend on the analyzed module
- Risk Assessment: Provides risk levels (HIGH, MEDIUM, LOW, VERY_LOW) for safe removal
Dual Interface
- CLI Command: Perfect for automation and CI/CD pipelines
- Admin Panel: User-friendly web interface with real-time analysis
-
Install via Composer:
composer require hryvinskyi/magento2-module-detector
-
Enable the module:
ddev magento module:enable Hryvinskyi_ModuleDetector ddev magento setup:upgrade ddev magento setup:di:compile ddev magento cache:flush
-
Verify installation:
ddev magento module:status Hryvinskyi_ModuleDetector
Usage
CLI Command
Basic Analysis
ddev magento hryvinskyi:module:analyze-unused
Verbose Output
ddev magento hryvinskyi:module:analyze-unused --verbose
JSON Output (for automation)
ddev magento hryvinskyi:module:analyze-unused --json
Admin Panel
- Navigate to Admin Panel → System → Tools → Module Analysis
- Click "Run Analysis" to start the detection process
- Review results organized by risk level
- Use the detailed information to make informed decisions
Analysis Criteria
Module Status
- Enabled/disabled status in
app/etc/config.php
- Frontend output status in admin configuration
Database Usage
- Empty or missing database tables
- Unused EAV attributes
- Table row counts and data analysis
Configuration Usage
- System configuration entries
system.xml
declarations vs actual usage
File System Analysis
- Controllers, blocks, models, observers
- Last modification timestamps
- Code complexity indicators
Dependencies
- Modules that depend on the analyzed module
- Composer and
module.xml
dependencies
Risk Levels
Risk Level | Icon | Color | Description | Recommendation |
---|---|---|---|---|
🟢 Safe to Remove | 🟢 | Green | Module is disabled, has no data, and no dependencies | Can be safely deleted |
🟡 Probably Unused | 🟡 | Yellow | Module shows minimal usage but appears inactive | Review and likely safe to remove |
🟠 Review Needed | 🟠 | Orange | Module has mixed signals - some usage detected | Carefully analyze before making decisions |
🔴 Keep Module | 🔴 | Red | Module is actively used or has critical dependencies | Should NOT be removed |
Risk Assessment Criteria
The risk level is calculated based on multiple factors:
🟢 Safe to Remove (Score: 12+)
- Module is disabled in configuration
- No database records or empty tables
- No configuration entries
- No active files or components
🟡 Probably Unused (Score: 6-11)
- Minimal database usage
- Few or no configuration entries
- Limited file activity
- No recent modifications
🟠 Review Needed (Score: 0-5)
- Some database activity detected
- Has configuration or files present
- Mixed usage indicators
- Requires manual review
🔴 Keep Module (Score: <0)
- Other modules depend on this module
- Recently modified files
- Active EAV attributes in use
- Clear signs of being needed
Safety Recommendations
⚠️ Always test in development environment first
- Backup your system before removing any modules
- Run analysis regularly to track module usage over time
- Check dependencies - other modules may rely on the analyzed module
- Test thoroughly after module removal
- Monitor logs for any related errors
Output Examples
CLI Output
📊 UNUSED MODULES DETECTION REPORT
================================================================================
Found 3 potentially unused modules:
• Safe to Remove: 1 modules
• Probably Unused: 2 modules
🟢 SAFE TO REMOVE (1)
----------------------------------------
📦 Vendor_UnusedModule (v1.0.0)
❌ Module is disabled in app/etc/config.php
❌ All declared database tables are empty or missing
📊 Database: 2 tables, 0 rows total
💡 RECOMMENDATIONS:
• 🟢 SAFE TO REMOVE: These modules can be safely deleted
• 🟡 PROBABLY UNUSED: Review these modules - likely safe to remove
• 🟠 REVIEW NEEDED: Carefully analyze before making decisions
• 🔴 KEEP MODULE: These modules should NOT be removed
Admin Panel Features
- Real-time analysis progress
- Color-coded risk levels
- Expandable module details
- Export capabilities
- Responsive design
Technical Details
Requirements
- PHP: 8.1 or higher
- Magento: 2.4.6 or higher
- Extensions: Standard Magento requirements
Architecture
- Service Contracts: Proper API interfaces
- Dependency Injection: Full DI container support
- Type Safety: Strict typing throughout
- PSR Standards: Follows PSR-4 autoloading
Performance
- Optimized Queries: Efficient database analysis
- Memory Management: Handles large module sets
- Caching: Smart caching of repeated operations
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
Copyright (c) 2025. Volodymyr Hryvinskyi. All rights reserved.
This module is released under the MIT License. See LICENSE file for details.
Support
For issues, questions, or contributions:
- Email: volodymyr@hryvinskyi.com
- GitHub: Create an issue in the repository
Changelog
Version 1.0.0
- Initial release
- CLI command implementation
- Admin panel interface
- Comprehensive module analysis
- Risk assessment system
- Security features and ACL
⚠️ Disclaimer: This tool provides analysis to help identify potentially unused modules. Always test thoroughly in a development environment before making changes to production systems. The authors are not responsible for any issues that may arise from module removal.