eng-mohamedemad-dev / command-module-generator
Smart Laravel artisan module generator package - Generates complete modules (Model, Controller, Service, Repository, Policy, Observer, Views, Routes) with full automation and best practices
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/eng-mohamedemad-dev/command-module-generator
Requires
- php: >=8.2
- illuminate/support: ^11.0|^12.0
README
Smart Laravel Artisan module generator package - Generates complete modules (Model, Controller, Service, Repository, Policy, Observer, Views, Routes) with full automation and best practices.### ๐ฆ ุจุงูุฌ ุชูููุฏ ู ูุฏููุงุช ูุงุฑุงููู ุฐูู ููุงุจู ููุชุฎุตูุต ุงููุงู ู
## ุงูููุฑุฉ ุจุงุฎุชุตุงุฑ
ุจุงุณุชุฎุฏุงู ุฃู ุฑ ูุงุญุฏ ููุท ุชูุฏุฑ ุชููุฏ:
---- Model
- Controller (API ุฃู Web)
๐ Features- Service
-
Repository & Interface
-
Full Module Generation: Create complete modules with Model, Controller, Service, Interface, Repository (optional), Policy, Observer, Views, and Resources- Request(s) (ู ูู ุฃู ู ูููู)
-
API & Web Support: Automatically distinguishes between API and Web modules- Resource
-
Smart Route Registration: Auto-adds
Route::resourcewith proper imports to routes files- Policy -
Auto Binding: Automatically binds interfaces to services/repositories in ServiceProvider- Observer
-
Model Attributes: Uses modern PHP attributes for Policy and Observer registration- Views Blade (ููููุจ)
-
View Customization: Support for custom view paths via
--pathู ุน ุฑุจุท ูู ุดูุก ุจุจุนุถู ุชููุงุฆููุง + ุญุฐู ูู ุฐูู ุจููุณ ุงูุณูููุฉ. -
Safe Overwriting: Protects existing files unless
--forceis used -
Complete Cleanup: Delete command removes all traces (routes, views, bindings, attributes)---
---## ุงูุชุฑููุจ ุงูุณุฑูุน
๐ฆ Installation1. ุฃุถู ุงูุจฺู ุฏุงุฎู ู ุฌูุฏ packages ูู ู ุดุฑูุนู
- ุซุจุชูุง ูุฏููุงู ูู composer ูู ูุฒู ุงูุฃู ุฑ
Install the package via composer:3. ูุนูู ุงูู ServiceProvider ุฏุงุฎู config/app.php ุงู ุณูุนู
ู AutoDiscovery:
```bash'providers' => [ composer require eng-mohamedemad-dev/command-module-generator ... ``` CommandModuleGenerator\CommandModuleGeneratorServiceProvider::class, ], The package will auto-register its service provider.``` 4. ุงูุดุฑ ู ูู ุงูููููุฌ ูุชุฎุตูุต ุงูุฎูุงุฑุงุช: ---```bash php artisan vendor:publish --tag=command-module-generator-config ## ๐ Usage``` 5. (ุงุฎุชูุงุฑู) ุงูุดุฑ stubs ูุชุนุฏูู ููุงูุจู: ### Generate a Module```bash php artisan vendor:publish --tag=command-module-generator-stubs #### Web Module``` ```bash php artisan make:module Car --type=web--- php artisan make:module Brand --type=web --path=admin/brand ```## ุฃูู ุงูู ูุฒุงุช ูุงูุฎูุงุฑุงุช ุงูุงูุชุฑุงุถูุฉ - ุชุญูู ูู ูู ู ุง ูุชู ุชูููุฏู ู ู ุฎูุงู ู ูู `config/module-generator.php`: #### API Module - `default_type`: web/api ```bash - `default_views_path`: ู ุณุงุฑ ุงููุงุฌูุงุช ููููุจ (ุงูุชุฑุงุถู resources/views/{module}) php artisan make:module Invoice --type=api - `make_repo`: ุชูููุฏ ุฑูุจูุฒูุชูุฑูุ php artisan make:module Product --type=api --repo - `make_resource`, `make_policy`, `make_observer`: ูุนูู/ุนุทูู ุฃู ููุน ``` - `requests_mode`: split (ููููุฏ ู ูููู) ุฃู single (ู ูู ูุงุญุฏ) - ุฃุณู ุงุก ู ููุงุช ุงูุฑููููุณุชุงุช (store/update) ### Delete a Module --- ```bash php artisan delete:module Car --type=web## ุฃู ุซูุฉ ุฃูุงู ุฑ ุนู ููุฉ php artisan delete:module Invoice --type=api```bash ```php artisan make:module Car # ุชูููุฏ ู ูุฏูู/ุฎุฏู ุฉ/ููุชุฑููุฑ... ุงูุชุฑุงุถู web php artisan make:module Invoice --type=api --repo # ุชูููุฏ ูู ุดูุก ูู ูุฏููู API+ ุชูููุฏ repository ---php artisan make:module Ticket --path=admin/tickets # ูุถุน ุงููุงุฌูุงุช ุจู ุฌูุฏ ู ุนูู php artisan make:module Post --no-policy # ูุนุทูู ุชูููุฏ ุงูุจูููุตู ููุท ## โ๏ธ Optionsphp artisan make:module City --requests-mode=single # ูููุฏ ู ูู request ูุงุญุฏ ููุท | Option | Description |php artisan delete:module Car # ูุญุฐู ูู ู ููุงุช ู ูุฏููู Car (ูู ู ุง ุชู ุชูููุฏู) |--------|-------------|``` | `--type=web\|api` | Select between web or API module (default: `api`) | | `--repo` | Generate Repository + RepositoryInterface and bind to service |- ุฃู ุฎูุงุฑ ูู ุชุฑุณูู ุจุงูุฃู ุฑุ ุณูุนู ู ุจุงูููู ุฉ ุงูู ูุฌูุฏุฉ ูู ุงูููููุฌ ุงูุชุฑุงุถููุง. | `--path=custom` | Custom view folder path (for web modules) | | `--force` | Allow overwriting existing service, repository, and interface files |--- ---## ุชุฎุตูุต ููุงูุจ (stubs) ุงูุชูููุฏ - ุชุณุชุทูุน ูุดุฑ stubs ุนุดุงู ุชุนุฏู ุฃู ูุงูุจ ุชูููุฏ: ## ๐ Generated Structure```bash php artisan vendor:publish --tag=command-module-generator-stubs When you run `php artisan make:module Car --type=api --repo`, the package generates:``` - ุบูุฑ ูู ู ุฌูุฏ `stubs/command-module-generator` ุจุญุฑูุฉโฆ ูู ุชูููุฏ ูุงุญู ุณูุฃุฎุฐ ุชุนุฏููุงุชู!
app/---
โโโ Console/
โโโ Http/## ุญุฐู ู ุง ุชู ุชูููุฏู (delete:module)
โ โโโ Controllers/- ูุญุฐู ุฌู ูุน ุงูู ููุงุช ูุงูุนูุงูุงุช ูููุฏ ุงูุฑุจุท ู ู AppServiceProvider.
โ โ โโโ Api/- ูุนุทูู ูุธุงูุฉ ูุงู ูุฉ ููู ูุฏููู ูู ุฎุทูุฉ ูุงุญุฏุฉ (ูุง ุชุญุชุงุฌ ุชูุธูู ูุฏูู).
โ โ โโโ CarController.php # API Controller with CRUD
โ โโโ Requests/---
โ โ โโโ CarRequest.php # Form Request validation
โ โโโ Resources/## ุฃุณุฆูุฉ ู ุชูุฑุฑุฉ โ
โ โโโ CarResource.php # API Resource transformer
โโโ Interfaces/ุณ: ูู ุบูุฑุช ููุงูุจ stubs ูู ูุงุฒู ุฃุญุฐู ุงูุจูุฌ ุฅุฐุง ุญุฏุซุชูุงุ
โ โโโ CarRepositoryInterface.php # Repository contractุฌ: ุฃุจุฏูุง. ููุงูุจู ุงูุดุฎุตูุฉ ูุง ุชุชุฃุซุฑ ุจุชุญุฏูุซ ุงูุจูุฌ.
โโโ Models/
โ โโโ Car.php # Eloquent Model (with Policy/Observer attributes)ุณ: ูู ุนุฏูุช ุงูููููุฌ ููุทุ ูู ุชุชุบูุฑ ุงูููู ููุช ุฃู ุฑ ุงูุชูููุฏุ
โโโ Observers/ุฌ: ูุนู ุ ุฃู ุชูููุฏ ูุงุญู ูุฃุฎุฐ ุงูููู ุงูุฌุฏูุฏุฉ ููุฑูุง.
โ โโโ CarObserver.php # Model Observer
โโโ Policies/ุณ: ููู ุฃุชุฃูุฏ ุฃู ูู ุดูุก ูุนู ูุ
โ โโโ CarPolicy.php # Authorization Policyุฌ: ุฌุฑุจ ุฃูุงู ุฑ make:module ู ุน ุงุณู ุฌุฏูุฏ + delete:module ููุงุณู ููุณูโฆ ุฑุงูุจ ู ุฌูุฏุงุช app ูresources/views ูAppServiceProvider.
โโโ Repositories/
โ โโโ CarRepository.php # Repository implementation---
โโโ Services/
โโโ CarService.php # Business logic layer## Roadmap
- ุฏุนู ู ุฒูุฏ ู ู ุฃููุงุน ุงูุณูู/ุงูููุงูุจ
database/migrations/- ุฃูุงู ุฑ publish ุฅุถุงููุฉ
โโโ xxxx_xx_xx_create_cars_table.php # Migration file- ุชุญุณูู ูุญุต ุงูุฃุฎุทุงุก ูุชุนุฑูุจ ุงูุฑุณุงุฆู
- ุฅุถุงูุฉ ุงุฎุชุจุงุฑุงุช ูุงุณุชุนู ุงูุงุช ุฌุงูุฒุฉ ููู ุฌุชู ุน
routes/
โโโ api.php # Auto-registered Route::resource---
## Summary (EN)
### For Web Modules (--type=web)A smart highly-configurable module generator for Laravel. Generate, clean up, and customize all module layers with one command. Full flexibility for your workflow!
Additional files:
resources/views/ โโโ car/ โโโ index.blade.php โโโ create.blade.php โโโ edit.blade.php โโโ show.blade.php
routes/ โโโ web.php # Auto-registered Route::resource
---
## ๐ง How It Works
### Service Layer Pattern
The package implements the Service Layer pattern for clean separation of concerns:
```php
// Controller โ Service โ Model/Repository
class CarController extends Controller
{
public function __construct(private CarService $service) {}
public function index(Request $request)
{
$data = $this->service->list(15);
return CarResource::collection($data);
}
}
Auto Binding
Services and repositories are automatically bound in AppServiceProvider:
public function register(): void { $this->app->bind(\App\Interfaces\CarInterface::class, \App\Services\CarService::class); $this->app->bind(\App\Interfaces\CarRepositoryInterface::class, \App\Repositories\CarRepository::class); }
Modern Attributes
Uses PHP 8 attributes for Policy and Observer registration:
use Illuminate\Database\Eloquent\Attributes\UsePolicy; use Illuminate\Database\Eloquent\Attributes\ObservedBy; #[UsePolicy(CarPolicy::class)] #[ObservedBy([CarObserver::class])] class Car extends Model { // }
๐ฏ Best Practices
This package follows Laravel best practices:
- โ Route Model Binding for automatic model resolution
- โ Form Request Validation for clean controller code
- โ Resource Pattern for API transformations
- โ Service Layer for business logic separation
- โ Repository Pattern (optional) for data access abstraction
- โ Policy for authorization
- โ Observer for model events
- โ tap() Helper for fluent updates
๐ Examples
Example 1: Simple API Module
php artisan make:module Product --type=api
Generates a complete API module with:
- ProductController (API CRUD)
- ProductService
- ProductInterface
- ProductRequest
- ProductResource
- ProductPolicy
- ProductObserver
- Product Model with attributes
- Migration
- Auto-registered API routes
Example 2: Web Module with Custom Path
php artisan make:module Category --type=web --path=admin/categories
Generates web module with views in resources/views/admin/categories/
Example 3: API Module with Repository
php artisan make:module Order --type=api --repo
Generates API module + Repository pattern implementation
๐๏ธ Delete Command
The delete command removes all generated files and cleans up:
- โ Model, Controller, Service, Repository, Interface
- โ Policy, Observer, Request, Resource
- โ Migration files
- โ Views (for web modules)
- โ Route registrations
- โ Service bindings in AppServiceProvider
- โ Model attributes (Policy/Observer imports and decorators)
php artisan delete:module Product --type=api
๐ Internationalization
This package supports both English and Arabic:
Arabic Commands
# ุชูููุฏ ู ูุฏููู php artisan make:module ู ูุชุฌ --type=api # ุญุฐู ู ูุฏููู php artisan delete:module ู ูุชุฌ --type=api
๐ฎ Roadmap
- Configuration file for customizing generated code
- Stub file publishing for custom templates
- GUI for module generation
- Seeders auto-generation
- ACL/Permissions integration
- Multi-language support in generated code
- Test file generation
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
๐ License
This package is open-sourced software licensed under the MIT license.
๐จโ๐ป Author
Mohamed Emad
Email: eng.mohamedemad.dev@gmail.com
GitHub: @eng-mohamedemad-dev
โญ Support
If you find this package helpful, please give it a โญ on GitHub!
Made with โค๏ธ for the Laravel Community