PHPackages                             rawnoq/laravel-hmvc - 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. rawnoq/laravel-hmvc

ActiveLibrary[Framework](/categories/framework)

rawnoq/laravel-hmvc
===================

A professional Laravel package for Hierarchical Model-View-Controller (HMVC) architecture with complete modular structure support

1.1.0(5mo ago)0112MITPHPPHP ^8.2

Since Nov 13Pushed 5mo agoCompare

[ Source](https://github.com/rawnoq/rawnoq-laravel-hmvc)[ Packagist](https://packagist.org/packages/rawnoq/laravel-hmvc)[ RSS](/packages/rawnoq-laravel-hmvc/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (12)Used By (0)

Laravel HMVC Package
====================

[](#laravel-hmvc-package)

A professional, feature-rich Hierarchical Model-View-Controller (HMVC) package for Laravel applications. This package provides a complete modular architecture solution with automatic route loading, view registration, migration management, and comprehensive Artisan command support.

📋 Table of Contents
-------------------

[](#-table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Module Management](#module-management)
- [Artisan Commands](#artisan-commands)
- [Module Structure](#module-structure)
- [Configuration](#configuration)
- [Advanced Usage](#advanced-usage)
- [Examples](#examples)
- [Contributing](#contributing)
- [License](#license)

✨ Features
----------

[](#-features)

### Core Features

[](#core-features)

- ✅ **Complete HMVC Architecture** - Organize your application into independent, reusable modules
- ✅ **Automatic Route Loading** - Routes are automatically discovered and loaded from modules
- ✅ **View Registration** - Module views are automatically registered with Laravel
- ✅ **Translation Support** - Automatic language file loading from modules
- ✅ **Migration Management** - Module-specific migrations with dedicated commands
- ✅ **Service Provider Support** - Each module can have its own service providers
- ✅ **Configuration Management** - Module-specific configuration files
- ✅ **Module Status Management** - Enable/disable modules dynamically

### Artisan Commands

[](#artisan-commands)

- ✅ **Make Commands** - Full support for creating components within modules
- ✅ **Module Management Commands** - Create, list, enable, disable modules
- ✅ **Migration &amp; Seeding** - Module-specific database operations
- ✅ **Case-Insensitive** - Module names work regardless of case

### Supported Components

[](#supported-components)

All Laravel `make:` commands support the `--module` option:

- Controllers, Models, Requests, Factories, Seeders, Migrations, Policies
- Middleware, Commands, Events, Listeners, Observers
- Resources, Tests, Notifications, Mail, Jobs, Exceptions
- Rules, Casts, Channels, Components, Enums, Scopes
- Views, Classes, Interfaces, Traits, DTOs, Config, Providers, Job Middleware

📦 Requirements
--------------

[](#-requirements)

- PHP 8.2 or higher
- Laravel 11.0+ or Laravel 12.0+

🚀 Installation
--------------

[](#-installation)

### Step 1: Install via Composer

[](#step-1-install-via-composer)

```
composer require rawnoq/laravel-hmvc
```

The package will automatically register PSR-4 autoloading for your modules. **No manual configuration needed!**

### Step 2: Publish Configuration (Optional)

[](#step-2-publish-configuration-optional)

```
php artisan vendor:publish --tag=hmvc-config
```

This will publish the configuration file to `config/hmvc.php`.

### Step 3: Publish Stubs (Optional)

[](#step-3-publish-stubs-optional)

```
php artisan vendor:publish --tag=hmvc-stubs
```

This will publish module stubs to `stubs/hmvc/module/` for customization.

### ⚠️ Note on Autoloading

[](#️-note-on-autoloading)

The package automatically registers PSR-4 autoloading for the `Modules` namespace. You **do not need** to manually add it to your `composer.json`. The autoloading is registered programmatically and works on both **Linux** and **Windows** systems.

🎯 Quick Start
-------------

[](#-quick-start)

### Create Your First Module

[](#create-your-first-module)

```
php artisan module:make Blog
```

This command will create a complete module structure:

```
modules/
└── Blog/
    ├── Config/
    │   └── config.php
    ├── Database/
    │   ├── Factories/
    │   ├── Migrations/
    │   └── Seeders/
    │       └── DatabaseSeeder.php
    ├── Http/
    │   ├── Controllers/
    │   │   └── BlogController.php
    │   ├── Middleware/
    │   ├── Requests/
    │   └── Resources/
    ├── Providers/
    │   └── ServiceProvider.php
    ├── Resources/
    │   ├── lang/
    │   └── views/
    ├── Routes/
    │   ├── web.php
    │   └── api.php
    └── Models/

```

### Create Components Within Modules

[](#create-components-within-modules)

```
# Create a controller in a module
php artisan make:controller PostController --module=Blog

# Create a model with migration and factory
php artisan make:model Post --module=Blog --migration --factory

# Create a request
php artisan make:request StorePostRequest --module=Blog

# Create middleware
php artisan make:middleware CheckAuth --module=Blog
```

📚 Module Management
-------------------

[](#-module-management)

### List All Modules

[](#list-all-modules)

```
php artisan module:list
```

Output:

```
+--------+---------+--------+-------------+-----------+------------+-------+
| Module | Status  | Routes | Controllers | Providers | Migrations | Views |
+--------+---------+--------+-------------+-----------+------------+-------+
| Blog   | Enabled | ✓      | ✓           | ✓         | ✓          | ✓     |
| User   | Enabled | ✓      | ✓           | ✓         | ✗          | ✓     |
+--------+---------+--------+-------------+-----------+------------+-------+

```

### Enable/Disable Modules

[](#enabledisable-modules)

```
# Enable a module
php artisan module:enable Blog

# Disable a module
php artisan module:disable Blog
```

### Run Module Migrations

[](#run-module-migrations)

```
# Run migrations for a specific module
php artisan module:migrate Blog

# Run migrations with seeding
php artisan module:migrate Blog --seed
```

### Run Module Seeders

[](#run-module-seeders)

```
php artisan module:seed Blog
```

🛠️ Artisan Commands
-------------------

[](#️-artisan-commands)

### Module Management Commands

[](#module-management-commands)

CommandDescription`module:make {name}`Create a new HMVC module scaffold`module:list`List all registered HMVC modules`module:enable {name}`Enable a disabled HMVC module`module:disable {name}`Disable an HMVC module`module:migrate {name}`Run database migrations for a specific module`module:seed {name}`Run the database seeder for a specific module### Module Options

[](#module-options)

The `module:make` command supports several options:

```
# Create a module with force (overwrite if exists)
php artisan module:make Blog --force

# Create a plain module (no scaffold)
php artisan module:make Blog --plain

# Create a module with API routing scaffold
php artisan module:make Blog --api
```

### Make Commands with Module Support

[](#make-commands-with-module-support)

All Laravel `make:` commands support the `--module` option:

#### Basic Components

[](#basic-components)

```
php artisan make:controller PostController --module=Blog
php artisan make:model Post --module=Blog
php artisan make:request StorePostRequest --module=Blog
php artisan make:middleware CheckAuth --module=Blog
php artisan make:policy PostPolicy --module=Blog
```

#### Database Components

[](#database-components)

```
php artisan make:migration create_posts_table --module=Blog
php artisan make:factory PostFactory --module=Blog
php artisan make:seeder PostSeeder --module=Blog
```

#### Event System

[](#event-system)

```
php artisan make:event PostCreated --module=Blog
php artisan make:listener SendPostNotification --module=Blog
php artisan make:observer PostObserver --module=Blog
```

#### Jobs &amp; Queues

[](#jobs--queues)

```
php artisan make:job ProcessPost --module=Blog
php artisan make:job-middleware RateLimitMiddleware --module=Blog
```

#### API &amp; Resources

[](#api--resources)

```
php artisan make:resource PostResource --module=Blog
php artisan make:test PostTest --module=Blog
```

#### Notifications &amp; Mail

[](#notifications--mail)

```
php artisan make:notification PostPublished --module=Blog
php artisan make:mail PostMail --module=Blog
```

#### Validation &amp; Rules

[](#validation--rules)

```
php artisan make:rule CustomRule --module=Blog
php artisan make:cast JsonCast --module=Blog
```

#### Broadcasting

[](#broadcasting)

```
php artisan make:channel PostChannel --module=Blog
```

#### View Components

[](#view-components)

```
php artisan make:component PostCard --module=Blog
php artisan make:view post.show --module=Blog
```

#### Other Components

[](#other-components)

```
php artisan make:command ProcessCommand --module=Blog
php artisan make:enum PostStatus --module=Blog
php artisan make:scope PublishedScope --module=Blog
php artisan make:class PostService --module=Blog
php artisan make:interface PostRepositoryInterface --module=Blog
php artisan make:trait HasSlug --module=Blog
php artisan make:dto PostDto --module=Blog
php artisan make:config post --module=Blog
php artisan make:provider PostServiceProvider --module=Blog
php artisan make:exception PostNotFoundException --module=Blog
```

**Note:** All commands work normally without `--module` option (standard Laravel behavior).

📁 Module Structure
------------------

[](#-module-structure)

A typical module structure looks like this (matching Laravel's standard structure):

```
modules/
└── Blog/
    ├── App/
    │   ├── Http/
    │   │   ├── Controllers/         # Controllers
    │   │   ├── Middleware/          # HTTP middleware
    │   │   ├── Requests/            # Form requests
    │   │   └── Resources/           # API resources
    │   ├── Models/                  # Eloquent models
    │   ├── Providers/
    │   │   └── ServiceProvider.php  # Module service provider
    │   ├── Policies/                # Authorization policies
    │   ├── Events/                  # Event classes
    │   ├── Listeners/               # Event listeners
    │   ├── Observers/               # Model observers
    │   ├── Notifications/           # Notification classes
    │   ├── Mail/                    # Mail classes
    │   ├── Jobs/                    # Job classes
    │   ├── Exceptions/              # Exception classes
    │   ├── Rules/                   # Validation rules
    │   ├── Casts/                   # Custom casts
    │   ├── Broadcasting/            # Broadcasting channels
    │   ├── View/
    │   │   └── Components/          # View components
    │   ├── Enums/                   # Enums
    │   ├── Console/
    │   │   └── Commands/            # Artisan commands
    │   ├── Interfaces/              # Interfaces
    │   ├── Traits/                  # Traits
    │   └── DTOs/                    # Data Transfer Objects
    ├── Database/
    │   ├── Factories/               # Model factories
    │   ├── Migrations/              # Database migrations
    │   └── Seeders/                 # Database seeders
    ├── Resources/
    │   ├── Lang/                    # Translation files
    │   └── Views/                   # Blade views
    ├── Routes/
    │   ├── web.php                  # Web routes
    │   └── api.php                  # API routes
    ├── Config/
    │   └── config.php               # Module configuration
    └── Tests/                       # Test classes

```

⚙️ Configuration
----------------

[](#️-configuration)

The configuration file is located at `config/hmvc.php`:

```
return [
    // Module namespace
    'namespace' => 'Modules',

    // Modules directory path
    'modules_path' => base_path('modules'),

    // Status file location
    'status_file' => storage_path('app/hmvc/modules.php'),

    // Directory structure for modules
    'directories' => [
        'controllers' => ['App/Http/Controllers'],
        'models' => ['App/Models'],
        'requests' => ['App/Http/Requests'],
        // ... and more
    ],

    // Route configuration
    'routes' => [
        [
            'name' => 'web',
            'path' => 'routes/web.php',
            'middleware' => ['web'],
            'prefix' => null,
            'enabled' => true,
        ],
        [
            'name' => 'api',
            'path' => 'routes/api.php',
            'middleware' => ['api'],
            'prefix' => 'api',
            'enabled' => true,
        ],
    ],
];
```

### Customizing Module Directories

[](#customizing-module-directories)

You can customize the directory structure in `config/hmvc.php`:

```
'directories' => [
    'controllers' => ['App/Http/Controllers', 'Controllers'],
    'models' => ['App/Models', 'Entities'],
    // Add custom directories
],
```

🎓 Advanced Usage
----------------

[](#-advanced-usage)

### Module Service Providers

[](#module-service-providers)

Each module can have its own service provider located at `Providers/ServiceProvider.php`:

```
