frontier/module

Laravel Frontier Modules Package

Installs: 8

Dependents: 0

Suggesters: 2

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/frontier/module

v1.0.0 2025-12-12 15:28 UTC

This package is auto-updated.

Last update: 2025-12-12 23:50:18 UTC


README

Laravel Logo

Latest Version on Packagist Total Downloads License PHP 8.2+ Laravel 10|11|12

Frontier Module

Modular architecture for Laravel applications โ€” A companion package to the Frontier Laravel Starter Kit that enables organizing large applications into self-contained, reusable modules.

โœจ Features

  • ๐Ÿ“ฆ Modular Organization โ€” Break large apps into logical, self-contained modules
  • ๐Ÿ”„ Auto-Discovery โ€” Commands, migrations, factories, policies, and Blade components work automatically
  • ๐Ÿ› ๏ธ Familiar Tooling โ€” Use standard php artisan make:* commands with --module flag
  • ๐Ÿ“‹ Laravel Conventions โ€” Follows standard Laravel patterns you already know
  • ๐Ÿš€ Lightweight โ€” Minimal overhead, powered by InterNACHI/Modular
  • ๐Ÿ“ค Extractable โ€” Modules can become separate Composer packages later
  • โœ… Strict Types โ€” All classes use declare(strict_types=1)
  • ๐Ÿงช Pest Testing โ€” Modern testing framework included

๐Ÿ“‹ Requirements

Requirement Version
PHP 8.2+
Laravel 10.x, 11.x, or 12.x

๐Ÿš€ Installation

composer require frontier/module

Laravel will auto-discover the service provider. No additional configuration required.

Optional: Publish Configuration

php artisan vendor:publish --tag=modular-config

๐Ÿ“– Quick Start

Create a Module

# Create a new module
php artisan make:module user-management

# Update Composer (required after creating modules)
composer update modules/user-management

This scaffolds:

app-modules/
โ””โ”€โ”€ user-management/
    โ”œโ”€โ”€ composer.json
    โ”œโ”€โ”€ src/
    โ”‚   โ””โ”€โ”€ Providers/
    โ”œโ”€โ”€ tests/
    โ”œโ”€โ”€ routes/
    โ”œโ”€โ”€ resources/
    โ””โ”€โ”€ database/

Generate Components

Use standard Laravel make:* commands with --module:

php artisan make:model User --module=user-management
php artisan make:controller UserController --module=user-management
php artisan make:migration create_users_table --module=user-management
php artisan make:request CreateUserRequest --module=user-management

Sync Configuration

# Sync phpunit.xml, PhpStorm settings, etc.
php artisan modules:sync

๐Ÿ“ Module Structure

app-modules/
โ””โ”€โ”€ my-module/
    โ”œโ”€โ”€ composer.json           # Module's Composer configuration
    โ”œโ”€โ”€ src/
    โ”‚   โ”œโ”€โ”€ Models/             # Eloquent models
    โ”‚   โ”œโ”€โ”€ Http/
    โ”‚   โ”‚   โ”œโ”€โ”€ Controllers/    # HTTP controllers
    โ”‚   โ”‚   โ”œโ”€โ”€ Middleware/     # Module-specific middleware
    โ”‚   โ”‚   โ””โ”€โ”€ Requests/       # Form requests
    โ”‚   โ”œโ”€โ”€ Providers/          # Service providers
    โ”‚   โ”œโ”€โ”€ Console/Commands/   # Artisan commands
    โ”‚   โ”œโ”€โ”€ Jobs/               # Queue jobs
    โ”‚   โ”œโ”€โ”€ Events/             # Event classes
    โ”‚   โ”œโ”€โ”€ Listeners/          # Event listeners
    โ”‚   โ””โ”€โ”€ Services/           # Business logic services
    โ”œโ”€โ”€ tests/
    โ”‚   โ”œโ”€โ”€ Feature/
    โ”‚   โ””โ”€โ”€ Unit/
    โ”œโ”€โ”€ routes/
    โ”‚   โ”œโ”€โ”€ web.php
    โ”‚   โ””โ”€โ”€ api.php
    โ”œโ”€โ”€ resources/
    โ”‚   โ”œโ”€โ”€ views/
    โ”‚   โ””โ”€โ”€ lang/
    โ””โ”€โ”€ database/
        โ”œโ”€โ”€ migrations/
        โ”œโ”€โ”€ seeders/
        โ””โ”€โ”€ factories/

๐Ÿ’ก Usage Examples

Module Routes

app-modules/user-management/routes/api.php

<?php

declare(strict_types=1);

use Illuminate\Support\Facades\Route;
use Modules\UserManagement\Http\Controllers\UserController;

Route::prefix('api/users')->middleware(['api', 'auth:sanctum'])->group(function () {
    Route::get('/', [UserController::class, 'index']);
    Route::post('/', [UserController::class, 'store']);
    Route::get('/{user}', [UserController::class, 'show']);
});

Module Controller

<?php

declare(strict_types=1);

namespace Modules\UserManagement\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Modules\UserManagement\Services\UserService;

class UserController
{
    public function __construct(
        private readonly UserService $userService
    ) {}

    public function index(): JsonResponse
    {
        return response()->json([
            'data' => $this->userService->getAllUsers()
        ]);
    }
}

Blade Components

Components are auto-registered with module namespace:

// app-modules/dashboard/src/View/Components/StatCard.php
namespace Modules\Dashboard\View\Components;

use Illuminate\View\Component;

class StatCard extends Component
{
    public function __construct(
        public string $title,
        public string|int $value
    ) {}

    public function render()
    {
        return view('dashboard::components.stat-card');
    }
}
{{-- Usage --}}
<x-dashboard::stat-card title="Users" :value="$count" />

Translations

// app-modules/user-management/resources/lang/en/messages.php
return [
    'welcome' => 'Welcome, :name!',
];

// Usage
__('user-management::messages.welcome', ['name' => $user->name]);

๐Ÿ”ง Artisan Commands

Module Management

Command Description
php artisan make:module <name> Create a new module
php artisan modules:list List all modules
php artisan modules:sync Sync project configs
php artisan modules:cache Cache module discovery
php artisan modules:clear Clear module cache

Supported Make Commands

All Laravel make:* commands support --module:

php artisan make:controller UserController --module=my-module
php artisan make:model User --module=my-module
php artisan make:migration create_users_table --module=my-module
php artisan make:request CreateUserRequest --module=my-module
php artisan make:resource UserResource --module=my-module
php artisan make:policy UserPolicy --module=my-module
php artisan make:event UserCreated --module=my-module
php artisan make:listener SendEmail --module=my-module
php artisan make:job ProcessUser --module=my-module
php artisan make:command ImportUsers --module=my-module
php artisan make:factory UserFactory --module=my-module
php artisan make:seeder UserSeeder --module=my-module
php artisan make:test UserTest --module=my-module

Database Seeding

php artisan db:seed --module=my-module
php artisan db:seed --class=UserSeeder --module=my-module

๐ŸŽฏ When to Use Modules

โœ… Use Modules When:

Scenario Benefit
Large applications (50+ models) Better organization
Multiple domains Separate bounded contexts
Team development Independent workstreams
Potential extraction Easy to extract as packages

โŒ Stick to Traditional Structure When:

Scenario Reason
Small apps (< 20 models) Overhead not worth it
Simple CRUD apps No clear domain boundaries
Rapid prototyping Speed over organization

โš™๏ธ Configuration

Custom Namespace

Edit config/app-modules.php:

return [
    'modules_namespace' => 'App\\Modules',  // Default: 'Modules'
    'modules_path' => base_path('app-modules'),
];

Production Caching

# Add to deployment script
php artisan modules:cache

๐Ÿ› ๏ธ Development

Running Tests

composer test

Code Linting

composer lint        # Fix code style with Pint
composer lint:test   # Check code style

Rector Refactoring

composer rector      # Apply automated refactorings
composer rector:dry  # Preview changes without applying

๐Ÿ”— Frontier Ecosystem

Package Purpose
frontier/frontier Laravel Starter Kit
frontier/module Modular architecture
frontier/action Action pattern
frontier/repository Repository pattern

๐Ÿ“š Documentation

For comprehensive documentation including advanced examples, inter-module communication patterns, and best practices, see AI_GUIDE.md.

๐Ÿค Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details.

๐Ÿ“„ License

The MIT License (MIT). Please see License File for more information.

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

Mohamed Khedr
Email: 0xkhdr@gmail.com

Made with โค๏ธ for the Laravel community