phpsamurai / laravel-module-maker
A Laravel package for generating modular HMVC structures with artisan commands
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/phpsamurai/laravel-module-maker
Requires
- php: ^8.2
- laravel/framework: ^12.0
Requires (Dev)
- orchestra/testbench: ^9.0
- phpunit/phpunit: ^11.0
Suggests
- livewire/livewire: Required for generating Livewire-based modules (^3.0)
This package is auto-updated.
Last update: 2025-10-09 11:54:03 UTC
README
ποΈ Laravel Module Maker
Transform Your Laravel App into a Modular Masterpiece
Build scalable, maintainable Laravel applications with self-contained HMVC modules.
One command. Complete module. Zero configuration.
Quick Start β’ Features β’ Commands β’ Examples β’ Support
π― What Is This?
Laravel Module Maker is a powerful package that generates complete, production-ready modules for your Laravel applications using the HMVC (Hierarchical Model-View-Controller) pattern.
The Problem
Traditional Laravel App Your App After Module Maker
βββββββββββββββββββββ ββββββββββββββββββββββββββββββ
app/ modules/
βββ Controllers/ βββ Product/
β βββ UserController βββ Controllers/
β βββ ProductController βββ Models/
β βββ OrderController βββ Views/
β βββ ... (100+ files) βββ Routes/
βββ Models/ βββ Tests/
β βββ ... (50+ files) βββ ... (self-contained)
βββ ... (messy!) βββ Order/
β βββ ... (self-contained)
β Hard to maintain βββ User/
β Tight coupling βββ ... (self-contained)
β Difficult to scale
β
Easy to maintain
β
Loose coupling
β
Scales effortlessly
The Solution
php artisan make:module Product --type=full
You get: A complete, self-contained module with API, UI, database, tests, and more. In 2 seconds.
β¨ Features
| π Module Types | π§ Automation | π¦ Management | π¨ UI/UX |
|---|---|---|---|
| Full-Stack | Auto-register providers | List modules | Tailwind CSS |
| API-only | Auto-update composer | Delete safely | Alpine.js |
| Livewire-only | Auto-add navigation | Health checks | Responsive |
| With relationships | Auto-register routes | Dashboard | Real-time validation |
πͺ Magical Features
- π§ Auto Navigation: Adds links to your layout automatically
- π₯ Health Monitoring: 10-point health check system
- π Dashboard: Beautiful overview of all modules
- π Relationships: Scaffold BelongsTo and HasMany relationships
- β‘ Zero Config: Everything works out of the box
- π‘οΈ Safe Deletion: Double confirmation + automatic cleanup
π Requirements
PHP >= 8.2 Laravel >= 12.0 Composer >= 2.0 Livewire >= 3.0 (optional, for Livewire modules)
π Installation
composer require phpsamurai/laravel-module-maker
Optional: For Livewire modules:
composer require livewire/livewire
That's it! Ready to use. No configuration needed.
β‘ Quick Start
Create Your First Module
php artisan make:module Blog --type=full
Run Migrations
php artisan migrate
Access Your Module
- π Web UI:
http://your-app.test/blogs - π API:
http://your-app.test/api/blogs
See the Magic
php artisan module:dashboard
Done! Your module is ready with UI, API, database, tests, and navigation. π
π― Module Types
| Type | Command | What You Get | Use Case |
|---|---|---|---|
|
π Full-Stack Recommended |
--type=full |
β’ API Controller |
Complete features needing both UI and API |
| π API |
--type=api |
β’ API Controller |
Backend services, REST APIs, microservices |
| β‘ Livewire |
--type=livewire |
β’ Livewire Components |
UI for existing APIs, frontend features |
π All Commands
π¨ Module Creation
# Interactive mode (prompts for type) php artisan make:module Product # Full-Stack module (API + Livewire) php artisan make:module Product --type=full # API module (backend only) php artisan make:module Product --type=api # Livewire module (UI only) php artisan make:module Product --type=livewire # With relationships php artisan make:module-with-relations OrderItem \ --type=full \ --belongs-to=Order \ --belongs-to=Product \ --has-many=Review # With options php artisan make:module Product --force --no-tests --no-seeders
π Module Management
# Interactive dashboard php artisan module:dashboard # List all modules php artisan list:modules # Check module health php artisan module:health Product # Check all modules health php artisan module:health # Delete module (with confirmation) php artisan delete:module Product # Force delete (no confirmation) php artisan delete:module Product --force
βοΈ Customization
# Publish configuration php artisan vendor:publish --tag=module-maker-config # Publish stub templates php artisan vendor:publish --tag=module-maker-stubs
ποΈ What Gets Generated
Full-Stack Module Structure
modules/Product/
β
βββ π Controllers/
β βββ ProductApiController.php # RESTful API with search, filter, pagination
β
βββ π Livewire/
β βββ Index.php # List with real-time search & delete
β βββ Create.php # Create form with validation
β βββ Edit.php # Edit form with validation
β
βββ π Models/
β βββ Product.php # Eloquent model with scopes
β
βββ π Views/
β βββ livewire/
β βββ index.blade.php # Tailwind styled list view
β βββ create.blade.php # Tailwind styled form
β βββ edit.blade.php # Tailwind styled form
β
βββ π Routes/
β βββ web.php # Livewire routes (/products)
β βββ api.php # API routes (/api/products)
β
βββ π Http/
β βββ Resources/
β β βββ ProductResource.php # JSON resource transformer
β β βββ ProductCollection.php # JSON collection wrapper
β βββ Middleware/ # Ready for custom middleware
β βββ Requests/ # Ready for form requests
β
βββ π Database/
β βββ Migrations/
β β βββ 2025_xx_xx_create_product_table.php
β βββ Seeders/
β β βββ ProductSeeder.php # Sample data seeder
β βββ Factories/
β βββ ProductFactory.php # Factory for testing
β
βββ π Tests/
β βββ Feature/
β β βββ ProductTest.php # HTTP endpoint tests
β βββ Unit/
β βββ ProductTest.php # Model unit tests
β
βββ π Providers/
β βββ ProductServiceProvider.php # Auto-registered provider
β
βββ π Config/ # Module-specific config
Total: 18 files, ~35 KB, Production-ready
π₯ Automatic Features
What Happens Automatically
When you run php artisan make:module Product --type=full:
|
β File Generation
β Registration
|
β Configuration
β UI Enhancement
|
What You Need to Do
php artisan migrate
That's it! Everything else is automatic. π
π» Code Examples
Generated API Controller
namespace Modules\Product\Controllers; class ProductApiController { public function index(Request $request): JsonResponse { $query = Product::query(); // π Built-in search if ($request->has('search')) { $query->where('name', 'like', "%{$request->search}%"); } // π― Built-in filtering if ($request->has('is_active')) { $query->where('is_active', $request->is_active); } // π Built-in pagination $products = $query->paginate(15); return response()->json(new ProductCollection($products)); } // β store(), show(), update(), destroy() included }
Generated Livewire Component
namespace Modules\Product\Livewire; use Livewire\Component; use Livewire\WithPagination; class Index extends Component { use WithPagination; public $search = ''; public $confirmingDeletion = false; // π Real-time search protected $queryString = ['search']; // ποΈ Delete with confirmation public function delete($id) { $this->confirmingDeletion = true; $this->deletingId = $id; } public function render() { $products = Product::query() ->when($this->search, fn($q) => $q->where('name', 'like', "%{$this->search}%") ) ->latest() ->paginate(15); return view('products::livewire.index', [ 'products' => $products ]); } }
Generated Routes
// Web Routes (Livewire UI) Route::get('/products', Index::class)->name('products.index'); Route::get('/products/create', Create::class)->name('products.create'); Route::get('/products/{product}/edit', Edit::class)->name('products.edit'); // API Routes (JSON) Route::prefix('products')->group(function () { Route::get('/', [ProductApiController::class, 'index']); Route::post('/', [ProductApiController::class, 'store']); Route::get('/{product}', [ProductApiController::class, 'show']); Route::put('/{product}', [ProductApiController::class, 'update']); Route::delete('/{product}', [ProductApiController::class, 'destroy']); });
π Advanced Features
1. π§ Automatic Navigation
Navigation links are added automatically!
php artisan make:module Product --type=full
Before:
<nav> <a href="/">Home</a> <a href="/orders">Orders</a> </nav>
After:
<nav> <a href="/">Home</a> <a href="/orders">Orders</a> <a href="/products">Products</a> β Added automatically! </nav>
Features:
- β Auto-adds for Livewire/Full-Stack modules
- β Auto-removes when module deleted
- β No duplicates
- β Maintains formatting
2. π Interactive Dashboard
See everything at a glance!
php artisan module:dashboard
Output:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ποΈ LARAVEL MODULE MAKER DASHBOARD ποΈ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π MODULE STATISTICS
Total Modules: 5
Full-Stack Modules: 3
API Modules: 2
Livewire Modules: 0
Total Routes: 45
Total Files: 85
Total Size: 250.5 KB
π¦ YOUR MODULES
ββββββββββββ¬βββββββββββββ¬βββββββββ¬ββββββββββ
β Module β Type β Routes β Health β
ββββββββββββΌβββββββββββββΌβββββββββΌββββββββββ€
β Category β Full-Stack β 9 β β
100% β
β Order β Full-Stack β 9 β β
100% β
β Product β Full-Stack β 9 β β
100% β
β Tag β API β5 β β
100% β
β UserUI β Livewire β 3 β β
100% β
ββββββββββββ΄βββββββββββββ΄βββββββββ΄ββββββββββ
β‘ QUICK ACTIONS
β’ Create: php artisan make:module {name} --type=full
β’ Health: php artisan module:health {name}
β’ Delete: php artisan delete:module {name}
3. π₯ Health Check System
Monitor your modules' health!
# Check single module php artisan module:health Product # Check all modules php artisan module:health
10-Point Health Check:
- β Has controllers/components
- β Has models
- β Has routes
- β Has views
- β Has migrations
- β Has tests
- β Has service provider
- β Provider registered
- β Routes registered
- β Namespace configured
Health Scores:
- π’ 90-100%: Excellent
- π‘ 70-89%: Needs attention
- π΄ Below 70%: Critical
4. π Relationship Scaffolding
Generate modules with relationships built-in!
php artisan make:module-with-relations OrderItem \ --type=full \ --belongs-to=Order \ --belongs-to=Product \ --has-many=Review
Automatically generates:
In Model:
public function order() { return $this->belongsTo(\Modules\Order\Models\Order::class); } public function product() { return $this->belongsTo(\Modules\Product\Models\Product::class); } public function reviews() { return $this->hasMany(\Modules\Review\Models\Review::class); }
In Migration:
$table->foreignId('order_id')->constrained()->onDelete('cascade'); $table->foreignId('product_id')->constrained()->onDelete('cascade');
π Real-World Examples
Example 1: E-commerce Platform
# Step 1: Create product catalog php artisan make:module Product --type=full php artisan migrate # Step 2: Create orders with relationships php artisan make:module-with-relations Order \ --type=full \ --has-many=OrderItem # Step 3: Create order items with relationships php artisan make:module-with-relations OrderItem \ --type=full \ --belongs-to=Order \ --belongs-to=Product # Step 4: View dashboard php artisan module:dashboard # Done! You have: # β Product catalog with UI and API # β Order management with relationships # β Order items linked to orders and products # β All navigation links added automatically
Example 2: Blog Platform
# Backend API php artisan make:module Post --type=api php artisan make:module Comment --type=api # Frontend UIs php artisan make:module BlogPublic --type=livewire php artisan make:module BlogAdmin --type=livewire # Result: Separate backend and multiple frontends!
Example 3: SaaS Application
# Core modules php artisan make:module User --type=full php artisan make:module Subscription --type=full php artisan make:module Payment --type=full # Feature modules php artisan make:module Analytics --type=api php artisan make:module Reporting --type=api # UI modules php artisan make:module Dashboard --type=livewire php artisan make:module Settings --type=livewire # Check everything php artisan module:dashboard
π API Endpoints
Generated Endpoints
| Method | Endpoint | Features |
|---|---|---|
GET |
/api/products |
List, search, filter, paginate, sort |
POST |
/api/products |
Create with validation |
GET |
/api/products/{id} |
Show single resource |
PUT |
/api/products/{id} |
Update with validation |
DELETE |
/api/products/{id} |
Delete resource |
Example API Usage
# List products curl http://your-app.test/api/products # Search curl "http://your-app.test/api/products?search=laptop" # Filter curl "http://your-app.test/api/products?is_active=1" # Paginate curl "http://your-app.test/api/products?page=2" # Create curl -X POST http://your-app.test/api/products \ -H "Content-Type: application/json" \ -d '{"name":"Laptop","description":"Gaming laptop"}' # Update curl -X PUT http://your-app.test/api/products/1 \ -H "Content-Type: application/json" \ -d '{"name":"Updated Laptop"}' # Delete curl -X DELETE http://your-app.test/api/products/1
Response Format:
{
"data": [
{
"id": 1,
"name": "Product Name",
"description": "Description",
"is_active": true,
"created_at": "2025-10-09T12:00:00.000000Z"
}
],
"meta": {
"total": 100,
"per_page": 15,
"current_page": 1
}
}
π¨ Livewire Components
Interactive UI Components
Index Component:
- π Real-time search
- π Pagination
- ποΈ Delete with confirmation modal
- β Success/error messages
- π± Responsive design
Create Component:
- π Form with validation
- β‘ Real-time validation
- π― Wire:model binding
- β Success redirect
Edit Component:
- π Pre-filled form
- β‘ Real-time validation
- πΎ Update functionality
- β Success redirect
Example Livewire View
<div class="max-w-7xl mx-auto px-4"> <!-- Search --> <input wire:model.live="search" placeholder="Search products..." class="w-full px-4 py-2 border rounded-lg"> <!-- Results --> <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mt-4"> @foreach($products as $product) <div class="bg-white p-6 rounded-lg shadow"> <h3>{{ $product->name }}</h3> <p>{{ $product->description }}</p> <button wire:click="delete({{ $product->id }})" class="text-red-600 hover:text-red-800"> Delete </button> </div> @endforeach </div> <!-- Pagination --> {{ $products->links() }} </div>
π§ͺ Testing
Generated Tests
Feature Test:
public function test_product_can_be_created(): void { $response = $this->post(route('api.products.store'), [ 'name' => 'Test Product', 'description' => 'Test description', ]); $response->assertStatus(201); $this->assertDatabaseHas('products', [ 'name' => 'Test Product' ]); }
Unit Test:
public function test_product_active_scope(): void { Product::factory()->create(['is_active' => true]); Product::factory()->create(['is_active' => false]); $this->assertCount(1, Product::active()->get()); }
Livewire Test:
public function test_can_create_product_via_livewire(): void { Livewire::test(Create::class) ->set('name', 'New Product') ->call('save') ->assertRedirect(route('products.index')); }
Run Tests
# All tests php artisan test # Specific module php artisan test modules/Product/Tests/ # With coverage php artisan test --coverage
βοΈ Configuration
Publish Config
php artisan vendor:publish --tag=module-maker-config
Available Options
return [ // Module directory 'path' => 'modules', // Namespace prefix 'namespace' => 'Modules', // Default module type 'default_type' => 'api', // Auto-register routes 'auto_register_routes' => true, // Route types to register 'route_registration' => 'both', // 'web', 'api', or 'both' // Generation options 'generate_tests' => true, 'generate_seeders' => true, 'generate_factories' => true, ];
Customize Stubs
php artisan vendor:publish --tag=module-maker-stubs
Stubs copied to resources/stubs/module-maker/
Available variables:
| Variable | Output | Use |
|---|---|---|
{{module}} |
Product |
Class names |
{{moduleLower}} |
product |
Variables |
{{moduleSnake}} |
product |
Tables |
{{modulePlural}} |
Products |
Labels |
{{namespace}} |
Modules |
Namespaces |
{{moduleNamespace}} |
Modules\Product |
Full namespace |
π¨ Troubleshooting
β Class Not Found
composer dump-autoload php artisan optimize:clear
Verify bootstrap/providers.php contains your service provider.
β Routes Not Working
php artisan route:clear php artisan route:list --name=products
Check service provider is registered.
β Livewire Component Not Found
composer require livewire/livewire php artisan optimize:clear
Ensure @livewireStyles and @livewireScripts in layout.
β Views Not Found
php artisan view:clear
Use namespace notation: products::livewire.index
β Navigation Link Not Added
Check resources/views/components/layouts/app.blade.php exists.
The package creates it automatically for first Livewire module.
π Best Practices
β DO
- Use PascalCase for module names:
ProductCatalog,UserManagement - Plan relationships before creating modules
- Run health checks before deployment
- Use dashboard to monitor modules
- Test modules after generation
- Backup before deleting modules
- Use Full-Stack for complete features
β DON'T
- Use snake_case for module names
- Skip migrations after creating modules
- Delete without confirmation in production
- Ignore health warnings
- Create without planning structure
- Use --force without backups
π― Use Cases
π Performance
Production Optimization
# Cache everything php artisan route:cache php artisan config:cache php artisan view:cache # Optimize autoloader composer install --optimize-autoloader --no-dev
Module Performance
- β‘ Fast Generation: 1-3 seconds per module
- β‘ Lazy Loading: Resources loaded only when needed
- β‘ Efficient Autoloading: PSR-4 compliant
- β‘ Zero Runtime Overhead: Only used during generation
- β‘ Optimized Queries: Includes pagination and filtering
π Command Reference
Complete Command List
| Command | Description | Example |
|---|---|---|
make:module |
Create module | php artisan make:module Product --type=full |
make:module-with-relations |
Create with relationships | php artisan make:module-with-relations OrderItem --belongs-to=Order |
list:modules |
List all modules | php artisan list:modules |
module:dashboard |
Show dashboard | php artisan module:dashboard |
module:health |
Check health | php artisan module:health Product |
delete:module |
Delete module | php artisan delete:module Product |
Command Options
| Option | Available On | Description |
|---|---|---|
--type={full|api|livewire} |
make:module | Module type |
--belongs-to={Model} |
make:module-with-relations | BelongsTo relationship |
--has-many={Model} |
make:module-with-relations | HasMany relationship |
--force |
make:module, delete:module | Skip confirmations |
--no-tests |
make:module | Skip test generation |
--no-seeders |
make:module | Skip seeder generation |
--no-factories |
make:module | Skip factory generation |
π Learning Path
Beginner
- Install the package
- Create your first module:
php artisan make:module Blog --type=full - Run migrations:
php artisan migrate - Visit in browser:
/blogs - Explore the generated files
Intermediate
- Create multiple modules
- Use relationships:
make:module-with-relations - Customize stubs
- Monitor with dashboard
- Run health checks
Advanced
- Publish configuration
- Customize all stubs
- Create custom module types
- Integrate with CI/CD
- Build complex architectures
π€ Contributing
We welcome contributions!
- Fork the repository
- Create feature branch:
git checkout -b feature/amazing - Commit changes:
git commit -m 'Add amazing feature' - Push branch:
git push origin feature/amazing - Open Pull Request
Development
git clone https://github.com/phpsamurai/laravel-module-maker.git
cd laravel-module-maker
composer install
π License
MIT License - see LICENSE file for details.
π¬ Support
Need Help?
π§ Email β’ π Issues β’ π Wiki
π Changelog
Version 1.0.2 (October 2025)
π Initial Release
Core Features:
- β Three module types (Full-Stack, API, Livewire)
- β Interactive CLI with type selection
- β 27 customizable stub templates
- β Complete HMVC structure generation
Automation:
- β Auto-register service providers
- β Auto-update composer autoload
- β Auto-register routes (web & API)
- β Auto-register Livewire components
- β Auto-add navigation links
- β Auto-create Livewire layout
Module Management:
- β List modules with statistics
- β Interactive dashboard
- β Health check system (10-point)
- β Safe module deletion
- β Automatic cleanup
Advanced Features:
- β Relationship scaffolding
- β BelongsTo and HasMany support
- β Foreign key generation
- β Navigation management
- β Health monitoring
Developer Experience:
- β Beautiful CLI output
- β Helpful tips and suggestions
- β Comprehensive error messages
- β Progress indicators
- β Double confirmations for safety
πΊοΈ Roadmap
Coming Soon
- π Module update command
- π¦ Module export/import
- π Module dependency graph
- π Multi-language support
- π¨ More UI frameworks (Bootstrap, Vuetify)
- π§© Plugin system
- π Advanced analytics
- π Permission scaffolding
- π Performance dashboard
- π± Mobile-first templates
β Show Your Support
If this package helps you build better Laravel applications:
β Star on GitHub π¬ Leave Feedback
Laravel Module Maker - Your magic wand for building modular Laravel applications.
Transform monolithic apps into modular masterpieces with a single command.