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

v1.1.0 2025-10-30 13:41 UTC

This package is not auto-updated.

Last update: 2025-10-30 20:00:30 UTC


README

Smart Laravel Artisan module generator package - Generates complete modules (Model, Controller, Service, Repository, Policy, Observer, Views, Routes) with full automation and best practices.### ๐Ÿ“ฆ ุจุงูƒุฌ ุชูˆู„ูŠุฏ ู…ูˆุฏูŠู„ุงุช ู„ุงุฑุงููŠู„ ุฐูƒูŠ ูˆู‚ุงุจู„ ู„ู„ุชุฎุตูŠุต ุงู„ูƒุงู…ู„

License: MIT---

Laravel

PHP## ุงู„ููƒุฑุฉ ุจุงุฎุชุตุงุฑ

ุจุงุณุชุฎุฏุงู… ุฃู…ุฑ ูˆุงุญุฏ ูู‚ุท ุชู‚ุฏุฑ ุชูˆู„ุฏ:

---- 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::resource with 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 --force is used

  • Complete Cleanup: Delete command removes all traces (routes, views, bindings, attributes)---

---## ุงู„ุชุฑูƒูŠุจ ุงู„ุณุฑูŠุน

๐Ÿ“ฆ Installation1. ุฃุถู ุงู„ุจูƒฺ† ุฏุงุฎู„ ู…ุฌู„ุฏ packages ููŠ ู…ุดุฑูˆุนูƒ

  1. ุซุจุชู‡ุง ูŠุฏูˆูŠุงู‹ ููŠ 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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. 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