kadevland/easy-modules

Organize your Laravel application into modules following the Clean Architecture. 30+ commands for fast modular development.

This package is auto-updated.

Last update: 2025-05-25 20:19:39 UTC


README

Latest Version on Packagist Total Downloads GitHub Actions License

โš ๏ธ Development Status: This package is currently in active development (v0.3.0). While functional, some features may change before the stable release.

Easy Module is a Laravel package that enables you to organize your application using modular architecture. Generate organized, maintainable applications with automatic component registration and structured code separation. Clean Architecture configuration is provided as a ready-to-use setup.

โœจ Key Features

  • ๐Ÿ—๏ธ Modular Structure - Organized application architecture with configurable layers
  • โšก Auto-Generation - Create complete modules with one command
  • ๐Ÿ”„ Auto-Discovery - Automatic module registration and loading
  • ๐ŸŽฏ Extensible - Add custom scaffold files and components
  • ๐Ÿš€ Easy to Use - Simple commands with intelligent defaults
  • ๐Ÿ›๏ธ Clean Architecture Ready - Pre-configured setup for Domain, Application, Infrastructure, and Presentation layers
  • ๐Ÿ†• Laravel 12 Ready - Full compatibility with Laravel 12's latest features

๐Ÿš€ Installation & Quick Start

Requirements

  • Laravel 12+ - Built specifically for Laravel 12
  • PHP 8.2+ - Required by Laravel 12
  • Composer - For package management

Installation

Install via Composer:

composer require --dev kadevland/easy-modules

Publish configuration:

# Default way
php artisan vendor:publish --provider="Kadevland\EasyModules\EasyModulesServiceProvider" --tag="config"

# Using Easy Module command
php artisan easymodules:publish

# Publish with options
php artisan easymodules:publish --all      # Config & stubs
php artisan easymodules:publish --stubs    # Stubs only
php artisan easymodules:publish --force    # Force overwrite

Create your first module:

# Single module
php artisan easymodules:new Blog

# Multiple modules
php artisan easymodules:new Blog User Product

# Using aliases
php artisan emodules:new Shop
php artisan emodule:new Auth

๐Ÿ› ๏ธ Commands & Generators

EasyModules provides 29 powerful commands for rapid development:

  • ๐Ÿ”ง 4 Utility commands - Module creation, publishing, module listing, flexible generation
  • ๐Ÿ—๏ธ3 Clean Architecture commands - Entities, services, and custom components
  • ๐Ÿš€ 22 Laravel-compatible commands - All Laravel generators, module-aware

๐Ÿ‘‰ Complete Command Reference Guide - Full documentation with examples

Quick Examples

# Create a complete blog module
php artisan easymodules:new Blog

# Generate Clean Architecture components
php artisan easymodules:make-entity Blog Post
php artisan easymodules:make-service Blog PostService

# Use familiar Laravel commands in modules
php artisan easymodules:make-model Blog Post --migration --factory

# Flexible Clean Architecture generation
php artisan easymodules:make-stub Blog UserRepository repository
php artisan easymodules:make-stub Shop OrderDTO dto
php artisan easymodules:make-stub User EmailValueObject valueobject

# List discovered modules
php artisan easymodules:list --routes

Command Aliases

All commands support these prefixes:

  • easymodules: (full)
  • emodules: (short)
  • emodule: (shortest)

๐Ÿ—๏ธ What Gets Generated

When you run:

php artisan easymodules:new Blog
app/Modules/Blog/
โ”œโ”€โ”€ Application/
โ”‚   โ”œโ”€โ”€ Actions/
โ”‚   โ”œโ”€โ”€ DTOs/
โ”‚   โ”œโ”€โ”€ Interfaces/
โ”‚   โ”œโ”€โ”€ Mappers/
โ”‚   โ”œโ”€โ”€ Rules/
โ”‚   โ”œโ”€โ”€ Services/
โ”‚   โ””โ”€โ”€ Validation/
โ”œโ”€โ”€ Domain/
โ”‚   โ”œโ”€โ”€ Entities/
โ”‚   โ”œโ”€โ”€ Services/
โ”‚   โ””โ”€โ”€ ValueObjects/
โ”œโ”€โ”€ Infrastructure/
โ”‚   โ”œโ”€โ”€ Casts/
โ”‚   โ”œโ”€โ”€ Exceptions/
โ”‚   โ”œโ”€โ”€ Mappers/
โ”‚   โ”œโ”€โ”€ Models/
โ”‚   โ”œโ”€โ”€ Persistences/
โ”‚   โ””โ”€โ”€ Services/
โ”œโ”€โ”€ Presentation/
โ”‚   โ”œโ”€โ”€ Console/
โ”‚   โ”‚   โ””โ”€โ”€ Commands/
โ”‚   โ”œโ”€โ”€ Http/
โ”‚   โ”‚   โ”œโ”€โ”€ Controllers/
โ”‚   โ”‚   โ”œโ”€โ”€ Middlewares/
โ”‚   โ”‚   โ”œโ”€โ”€ Requests/
โ”‚   โ”‚   โ””โ”€โ”€ Resources/
โ”‚   โ”œโ”€โ”€ Mappers/
โ”‚   โ”œโ”€โ”€ Views/
โ”‚   โ”‚   โ””โ”€โ”€ Components/
โ”‚   โ””โ”€โ”€ resources/
โ”‚       โ””โ”€โ”€ views/
โ”œโ”€โ”€ Database/
โ”‚   โ”œโ”€โ”€ Factories/
โ”‚   โ”œโ”€โ”€ Migrations/
โ”‚   โ””โ”€โ”€ Seeders/
โ”œโ”€โ”€ Tests/
โ”‚   โ”œโ”€โ”€ Feature/
โ”‚   โ””โ”€โ”€ Unit/
โ”œโ”€โ”€ Providers/
โ”‚   โ””โ”€โ”€ BlogServiceProvider.php
โ”œโ”€โ”€ config/
โ”‚   โ””โ”€โ”€ config.php
โ”œโ”€โ”€ routes/
โ”‚   โ”œโ”€โ”€ api.php
โ”‚   โ”œโ”€โ”€ console.php
โ”‚   โ””โ”€โ”€ web.php
โ””โ”€โ”€ lang/

Plus these files are auto-generated:

  • BlogServiceProvider.php - Automatically registered with Laravel
  • config/config.php - Module-specific configuration
  • routes/*.php - Route files with example routes
  • All folder structure following Clean Architecture principles

โš™๏ธ Configuration & Customization

Flexible configuration in config/easymodules.php

return [
    // Module location and namespace
    'base_path' => app_path('Modules'),
    'base_namespace' => 'App\\Modules',

    // Laravel 12 auto-discovery
    'auto_discover' => true,

    // Custom paths per component
    'paths' => [
        'controller' => 'Presentation/Http/Controllers',
        'model' => 'Infrastructure/Models',
        'entity' => 'Domain/Entities',
        'service' => 'Application/Services',
        // ...
    ],

    // Custom stubs
    'stubs' => [
        'controller' => 'easymodules/controller.stub',
        'entity' => 'easymodules/entity.stub',
        // ...
    ]
];

Customizable stubs

# Publish stubs for customization
php artisan easymodules:publish --stubs

# Modify in resources/stubs/easymodules/

๐Ÿ”„ Laravel 12 Auto-Discovery

EasyModules integrates perfectly with Laravel 12:

โœ… Automatic registration of ServiceProviders โœ… Route discovery for web, API and console โœ… Module configuration loading โœ… Asset support with Vite

# See all discovered modules
php artisan easymodules:list --routes

๐Ÿงช Testing Configuration

PHPUnit

<!-- phpunit.xml -->
<testsuites>
    <testsuite name="Feature">
        <directory suffix="Test.php">./tests/Feature</directory>
        <directory suffix="Test.php">./app/Modules/*/Tests/Feature</directory>
    </testsuite>
    <testsuite name="Unit">
        <directory suffix="Test.php">./tests/Unit</directory>
        <directory suffix="Test.php">./app/Modules/*/Tests/Unit</directory>
    </testsuite>
</testsuites>

Pest

// tests/Pest.php
uses(Tests\TestCase::class)->in('Feature', 'Unit');
uses(Tests\TestCase::class)->in('app/Modules/*/Tests/Feature');
uses(Tests\TestCase::class)->in('app/Modules/*/Tests/Unit');

๐Ÿ”ง Vite Integration (Laravel 12)

// vite.config.js
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import { glob } from 'glob';

const moduleAssets = [
    ...glob.sync('app/Modules/*/Presentation/resources/js/**/*.js'),
    ...glob.sync('app/Modules/*/Presentation/resources/css/**/*.css'),
];

export default defineConfig({
    plugins: [
        laravel({
            input: [
                'resources/css/app.css',
                'resources/js/app.js',
                ...moduleAssets,
            ],
            refresh: [
                'app/Modules/*/Presentation/resources/views/**',
                'app/Modules/*/routes/**',
            ],
        }),
    ],
});

๐Ÿ› ๏ธ Benefits of Modular Architecture

โœ… Separation of Concerns

  • Domain : Pure business logic, independent
  • Application : Use cases and orchestration
  • Infrastructure : Persistence and external services
  • Presentation : User interface and APIs

โœ… Maintainability

  • Code organized by functionality
  • Isolated and fast tests
  • Easier team development

โœ… Scalability

  • Add features without impact
  • Independent and reusable modules
  • Possibility to extract into packages

๐Ÿ“š Complete Documentation

๐Ÿค Contributing

Contributions are welcome! Please see contributing guide.

๐Ÿ“ Changelog

Please see CHANGELOG for more information on recent changes.

๐Ÿ”’ Security

For security issues, please email kadevland@kaosland.net.

๐Ÿ“„ License

Open-source package under MIT license.

๐Ÿ‘จโ€๐Ÿ’ป Credits

Made with โค๏ธ by Kadevland

โญ Star us on GitHub if this project helps you!

Laravel Easy Modules - Your modular architecture in 30 seconds ๐Ÿš€