PHPackages                             panicdevs/modules - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. panicdevs/modules

ActiveLibrary[Framework](/categories/framework)

panicdevs/modules
=================

Super light-weight Modular approach with no over-head for laravel.

v1.1.1(6mo ago)9147↓84.4%2MITPHPPHP &gt;=8.2

Since Sep 4Pushed 6mo agoCompare

[ Source](https://github.com/panicdevs/modules)[ Packagist](https://packagist.org/packages/panicdevs/modules)[ Docs](https://github.com/panicdevs/modules)[ GitHub Sponsors](https://github.com/sponsors/panicdevs)[ RSS](/packages/panicdevs-modules/feed)WikiDiscussions develop Synced today

READMEChangelog (3)Dependencies (2)Versions (6)Used By (0)

PanicDevs Modules
=================

[](#panicdevs-modules)

[![PHP Version](https://camo.githubusercontent.com/c5e8da782b1a0673c08b4f474108036d2cc973470eed2d5d89d48e8c8475eee6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e322d626c75652e737667)](https://php.net/)[![Laravel Version](https://camo.githubusercontent.com/f19a1b2353544f16e7ce12c5e9a828edf83be13c0cd73e29bf343767172957cb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d25334525334431302d7265642e737667)](https://laravel.com/)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)

Super light-weight Modular approach with no overhead for Laravel. This package provides a clean, performant way to organize your Laravel application into modular components with intelligent discovery, caching, and management capabilities.

Features
--------

[](#features)

- ✨ **Zero Configuration** - Works out of the box with sensible defaults
- 🚀 **High Performance** - Intelligent caching with automatic invalidation
- 🔍 **Auto Discovery** - Automatically discovers modules from configured paths
- 📦 **Multiple Module Types** - Support for foundation, modules, plugins, themes, etc.
- 🎛️ **Enable/Disable** - Runtime enable/disable of modules
- 🌱 **Database Seeders** - Built-in seeder management for modules
- 🎨 **Beautiful CLI** - Interactive commands with Laravel Prompts
- 🔒 **Protected Modules** - Prevent critical modules from being disabled
- 📊 **Module Information** - Rich metadata and dependency management

Requirements
------------

[](#requirements)

- PHP &gt;= 8.2
- Laravel &gt;= 10.0

Installation
------------

[](#installation)

Install via Composer:

```
composer require panicdevs/modules
```

The package will automatically register its service provider via Laravel's auto-discovery.

Configuration
-------------

[](#configuration)

Publish the configuration file (optional):

```
php artisan vendor:publish --provider="PanicDevs\Modules\Providers\ModulesServiceProvider" --tag="modules-config"
```

### Module Paths Configuration

[](#module-paths-configuration)

Configure where your modules are located in `config/modules.php`:

```
'paths' => [
    'foundation' => [
        'path'      => 'foundation',        // Path relative to project root
        'namespace' => 'Foundation',        // PSR-4 namespace prefix
        'icon'      => '🏢',               // Icon for CLI display
        'protected' => true,               // Cannot be disabled
    ],
    'modules' => [
        'path'      => 'modules',
        'namespace' => 'Modules',
        'icon'      => '📦',
        'protected' => false,              // Can be disabled
    ],
    // Add more module types as needed...
],
```

### Caching Configuration

[](#caching-configuration)

Enable or disable module manifest caching:

```
'cache' => env('MODULES_CACHE_ENABLED', true),
```

Module Structure
----------------

[](#module-structure)

Each module must contain a `module.json` file in its root directory:

```
modules/
├── User/
│   ├── module.json              # Required: Module configuration
│   ├── Providers/
│   │   └── UserServiceProvider.php
│   ├── Database/
│   │   └── Seeders/
│   │       └── UserDatabaseSeeder.php
│   ├── Routes/
│   │   └── api.php
│   └── ...
└── Auth/
    ├── module.json
    └── ...

```

### Module Configuration (`module.json`)

[](#module-configuration-modulejson)

```
{
    "id": "User",
    "name": "User",
    "alias": "user",
    "title": "User Management Module",
    "description": "User authentication and management functionality",
    "version": "1.0.0",
    "priority": 10,
    "providers": [
        "Modules\\User\\Providers\\UserServiceProvider"
    ],
    "files": [
        "Helpers/repositories.php"
    ],
    "depends_on": ["auth", "shared"]
}
```

#### Configuration Fields

[](#configuration-fields)

- **id/name**: Unique module identifier
- **alias**: Short name for CLI commands (defaults to lowercase name)
- **title**: Human-readable module title
- **description**: Module description
- **version**: Module version
- **priority**: Loading priority (higher loads first, default: 0)
- **providers**: Array of service provider classes to register
- **files**: Array of files to include (relative to module root)
- **depends\_on**: Array of module dependencies

Module Status Management
------------------------

[](#module-status-management)

Module enable/disable status is stored in `modules_statuses.json` in your project root:

```
{
    "foundation": {
        "Core": true,
        "Base": true,
        "Support": true
    },
    "modules": {
        "User": true,
        "Auth": true,
        "Blog": false
    }
}
```

Artisan Commands
----------------

[](#artisan-commands)

The package provides several Artisan commands for module management:

### List Modules

[](#list-modules)

```
# List all modules
php artisan modules:list

# Show only enabled modules
php artisan modules:list --enabled

# Show only disabled modules
php artisan modules:list --disabled
```

### Enable Modules

[](#enable-modules)

```
# Interactive module selection
php artisan modules:enable

# Enable specific module
php artisan modules:enable User

# Enable all modules of a type
php artisan modules:enable --all --type=modules
```

### Disable Modules

[](#disable-modules)

```
# Interactive module selection
php artisan modules:disable

# Disable specific module
php artisan modules:disable User

# Disable all modules of a type
php artisan modules:disable --all --type=modules
```

### Database Seeders

[](#database-seeders)

```
# Interactive seeder selection
php artisan modules:seed

# Seed specific modules
php artisan modules:seed User Auth

# Seed all modules with seeders
php artisan modules:seed --all

# Force seeding without confirmation
php artisan modules:seed User --force
```

### Performance Commands

[](#performance-commands)

```
# Cache module manifest for better performance
php artisan modules:cache

# Clear module cache
php artisan modules:clear

# Test module loading performance
php artisan modules:test
```

Usage in Code
-------------

[](#usage-in-code)

### Module Service

[](#module-service)

Inject the `ModuleService` to interact with modules in your code:

```
use PanicDevs\Modules\Services\ModuleService;

class SomeController
{
    public function __construct(
        private ModuleService $moduleService
    ) {}

    public function index()
    {
        // Get all enabled modules
        $enabledModules = $this->moduleService->allEnabled();

        // Get specific module
        $userModule = $this->moduleService->find('User');

        // Check if module is enabled
        if ($this->moduleService->isEnabled('User')) {
            // Module is enabled
        }

        // Get module path
        $path = $this->moduleService->getPath('User');

        // Get module namespace
        $namespace = $this->moduleService->getNamespace('User');
    }
}
```

### Available Methods

[](#available-methods)

```
// Module retrieval
$moduleService->all();                    // Get all modules
$moduleService->allEnabled();             // Get enabled modules only
$moduleService->find('ModuleName');       // Get specific module
$moduleService->findByAlias('alias');     // Find by alias

// Module status
$moduleService->isEnabled('ModuleName');  // Check if enabled

// Module information
$moduleService->getPath('ModuleName');           // Get module path
$moduleService->getNamespace('ModuleName');     // Get PSR-4 namespace
$moduleService->getAlias('ModuleName');         // Get module alias
$moduleService->getTitle('ModuleName');         // Get module title
$moduleService->getDescription('ModuleName');   // Get description
$moduleService->getVersion('ModuleName');       // Get version
$moduleService->getDependencies('ModuleName');  // Get dependencies

// Module organization
$moduleService->getByType('modules');           // Get modules by type
$moduleService->getEnabledByType('modules');    // Get enabled modules by type
$moduleService->getEnabledByPriority();         // Get modules ordered by priority

// Statistics
$moduleService->getStats();                     // Get module statistics
```

Performance
-----------

[](#performance)

### Caching

[](#caching)

The package includes intelligent caching:

- **Automatic**: Module manifest is cached automatically when `modules.cache` is `true`
- **Cache Location**: `bootstrap/cache/modules.php`
- **Auto-Invalidation**: Cache is invalidated when `modules_statuses.json` changes
- **Production Ready**: Optimized for production environments

### Loading Optimization

[](#loading-optimization)

- **Lazy Loading**: Modules are only loaded when needed
- **Priority-Based**: Modules load in priority order (highest first)
- **PSR-4 Integration**: Seamless autoloading integration
- **Minimal Overhead**: Less than 1ms overhead in production

Database Seeders
----------------

[](#database-seeders-1)

### Module Seeder Structure

[](#module-seeder-structure)

Each module can have its own database seeders:

```
modules/User/Database/Seeders/
├── UserDatabaseSeeder.php     # Main seeder (required)
└── V1/
    ├── UserTableSeeder.php
    └── RoleTableSeeder.php

```

### Main Database Seeder

[](#main-database-seeder)

The main seeder (`ModuleNameDatabaseSeeder.php`) coordinates all module seeders:

```
