PHPackages                             uncover/modular-monolith-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. uncover/modular-monolith-laravel

ActiveLibrary[Framework](/categories/framework)

uncover/modular-monolith-laravel
================================

Modular monolith architecture scaffolding for Laravel

v1.4.1(3mo ago)19MITPHPPHP ^8.0CI passing

Since Mar 26Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/uncoverthefuture-org/modular-monlith-laravel)[ Packagist](https://packagist.org/packages/uncover/modular-monolith-laravel)[ RSS](/packages/uncover-modular-monolith-laravel/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (10)Dependencies (18)Versions (25)Used By (0)

Laravel Modular Monolith Package
================================

[](#laravel-modular-monolith-package)

 [![Latest Version](https://camo.githubusercontent.com/87e70018b0d25c328fadb5c7a3530cdedbbc4f4dfa3b8015cdd595fcb3e1bc8f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f756e636f7665722f6d6f64756c61722d6d6f6e6f6c6974682d6c61726176656c2e737667)](https://packagist.org/packages/uncover/modular-monolith-laravel) [![Total Downloads](https://camo.githubusercontent.com/598859f16aa21f2e0f7cb9c18d9592a39e47d1d8a0ae2c3fb912d674005ad75b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f756e636f7665722f6d6f64756c61722d6d6f6e6f6c6974682d6c61726176656c2e737667)](https://packagist.org/packages/uncover/modular-monolith-laravel) [![License](https://camo.githubusercontent.com/f554b974dc9334d4bd3d2ceab06e38a03a14da87f5755855bf110b4f8dec7afa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f756e636f7665722f6d6f64756c61722d6d6f6e6f6c6974682d6c61726176656c2e737667)](https://packagist.org/packages/uncover/modular-monolith-laravel) [![Tests](https://github.com/uncoverthefuture-org/modular-monlith-laravel/actions/workflows/tests.yml/badge.svg)](https://github.com/uncoverthefuture-org/modular-monlith-laravel/actions)

A Laravel package that provides scaffolding for building modular monolith applications with standardized CRUD patterns, UUID support, and automatic route registration.

Features
--------

[](#features)

- **One Command Module Generation**: Generate Controller, Model, Validation, Middleware, Service, and Observer with a single artisan command
- **Base Classes with Full CRUD**: Pre-built base classes with complete CRUD operations (create, read, update, delete, query)
- **Route Macro**: `Route::moduleResource()` for automatic REST endpoint registration
- **UUID Support**: Automatic UUID generation and handling
- **Batch Operations**: Built-in support for batch create and delete
- **Flexible Validation**: Per-action validation rules (create, read, update, delete, query)
- **Service Layer**: Base service with caching, transaction support, and query methods
- **Observers**: Base observer for model lifecycle events
- **Publishable Base Classes**: Customize base classes if needed

Requirements
------------

[](#requirements)

- PHP 8.0+
- Laravel 9.0, 10.0, or 11.0

Installation
------------

[](#installation)

```
composer require uncover/modular-monolith-laravel
```

The package will auto-register its service provider.

Quick Start
-----------

[](#quick-start)

### 1. Generate a Module

[](#1-generate-a-module)

```
# Generate controller and model (default)
php artisan modular:make EmailVerification

# Generate all components
php artisan modular:make EmailVerification --all

# Generate with specific components
php artisan modular:make EmailVerification --validation --middleware --service --observer --migration
```

This creates:

- `app/Http/Controllers/EmailVerificationController.php` - Extends `ModularController`
- `app/Models/EmailVerification.php` - Extends `ModularModel`
- `app/Validations/EmailVerificationValidation.php` - Extends `ModularValidation`
- `app/Http/Middleware/EmailVerificationMiddleware.php` - Extends `ModularMiddleware`
- `app/Services/EmailVerificationService.php` - Extends `ModularService`
- `app/Observers/EmailVerificationObserver.php` - Extends `ModularObserver`
- `database/migrations/xxxx_xx_xx_create_email_verifications_table.php` (with --migration)

### 2. Add Routes

[](#2-add-routes)

In your `routes/api.php`:

```
use App\Http\Controllers\EmailVerificationController;

// Basic usage
Route::moduleResource('email-verifications', EmailVerificationController::class);

// With middleware
Route::moduleResource('email-verifications', EmailVerificationController::class, [
    'middleware' => ['auth:sanctum', 'EmailVerificationMiddleware']
]);
```

The `moduleResource` macro automatically creates:

- `POST /email-verifications` → `create`
- `GET /email-verifications` → `query`
- `GET /email-verifications/{id}` → `read`
- `PATCH /email-verifications/{id}` → `update`
- `DELETE /email-verifications/{id?}` → `delete`

Command Options
---------------

[](#command-options)

OptionDescription`--controller`Generate a controller (default: true)`--model`Generate a model (default: true)`--validation`Generate a validation class`--middleware`Generate a middleware class`--service`Generate a service class`--observer`Generate an observer class`--migration`Create a migration file`--all`Generate all components`--force`Overwrite existing filesConfiguration
-------------

[](#configuration)

Publish the config file:

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

### Available Options

[](#available-options)

```
// config/modular.php

// Customize paths
'paths' => [
    'controller' => app_path('Http/Controllers'),
    'model' => app_path('Models'),
    'validation' => app_path('Validations'),
    'middleware' => app_path('Http/Middleware'),
    'service' => app_path('Services'),
    'observer' => app_path('Observers'),
    'migration' => database_path('migrations'),
],

// Customize namespaces
'namespaces' => [
    'controller' => 'App\Http\Controllers',
    'model' => 'App\Models',
    'validation' => 'App\Validations',
    'middleware' => 'App\Http\Middleware',
    'service' => 'App\Services',
    'observer' => 'App\Observers',
],

// Route configuration
'routes' => [
    'middleware' => ['api'],
    'use_plural' => true,      // email-verifications vs email-verification
    'separator' => '-',        // email-verifications vs emailVerifications
],
```

Publishing Base Classes
-----------------------

[](#publishing-base-classes)

If you want to customize the base classes:

```
php artisan vendor:publish --tag=modular-base-classes
```

This publishes all base classes to your app, allowing you to override and customize them.

Base Classes
------------

[](#base-classes)

### ModularController

[](#modularcontroller)

The base controller provides these methods:

- `create(Request $request)` - Create single or batch records
- `read(string $id)` - Get a single record by UUID
- `update(Request $request, string $id)` - Update a record
- `delete(Request $request, ?string $id = null)` - Delete single or batch
- `query(Request $request)` - List with filtering, sorting, pagination

#### Query Parameters

[](#query-parameters)

The `query` method supports:

- **Pagination**: `?per_page=25`
- **Sorting**: `?sort_by=created_at&sort_order=desc`
- **Filtering**: `?filter[status]=active`
- **Search**: `?search=john&search_fields=name,email`
- **Eager Loading**: `?include=author,comments`

#### Generated Controller

[](#generated-controller)

```
class EmailVerificationController extends ModularController
{
    protected static string $model = EmailVerification::class;
    protected static string $validation = EmailVerificationValidation::class;

    // Add custom methods if needed
    public function customMethod(Request $request)
    {
        // Your custom logic
    }
}
```

### ModularModel

[](#modularmodel)

The base model includes:

- UUID primary key (`uuid` column)
- HasUuids trait for automatic UUID generation
- Soft deletes support
- Route key by UUID

#### Generated Model

[](#generated-model)

```
class EmailVerification extends ModularModel
{
    protected $table = 'email_verifications';

    protected $fillable = [
        'uuid',
        // Add your fillable attributes here
    ];
}
```

### ModularValidation

[](#modularvalidation)

Base validation class with action-based rules:

```
class EmailVerificationValidation extends ModularValidation
{
    protected static function createRules(Request $request): array
    {
        return [
            'email' => ['required', 'email'],
        ];
    }

    protected static function updateRules(Request $request): array
    {
        return [
            'email' => ['sometimes', 'email'],
        ];
    }
}
```

### ModularMiddleware

[](#modularmiddleware)

Base middleware with per-action authorization:

```
class EmailVerificationMiddleware extends ModularMiddleware
{
    protected array $actionMethodMap = [
        'create' => 'authorizeCreate',
        'read' => 'authorizeRead',
        'update' => 'authorizeUpdate',
        'delete' => 'authorizeDelete',
        'query' => 'authorizeQuery',
    ];

    protected function authorizeCreate(Request $request): bool
    {
        return auth()->user()->can('email-verification.create');
    }
}
```

### ModularService

[](#modularservice)

Base service with caching and CRUD operations:

```
class EmailVerificationService extends ModularService
{
    protected static string $model = EmailVerification::class;
    protected static ?int $cacheDuration = 3600; // Enable caching

    // Add custom methods
    public static function findByEmail(string $email): ?EmailVerification
    {
        return static::getModel()::where('email', $email)->first();
    }
}
```

### ModularObserver

[](#modularobserver)

Base observer for model lifecycle:

```
class EmailVerificationObserver extends ModularObserver
{
    public static function getObservedModel(): string
    {
        return EmailVerification::class;
    }

    public function created(EmailVerification $model): void
    {
        // Handle after creation
    }
}
```

Register in a service provider:

```
// AppServiceProvider.php
public function boot()
{
    EmailVerificationObserver::register();
}
```

JSON Response Format
--------------------

[](#json-response-format)

```
// Success
{
    "status": "success",
    "message": "Record created",
    "data": { ... }
}

// Paginated
{
    "status": "success",
    "message": "Success",
    "data": [ ... ],
    "pagination": {
        "current_page": 1,
        "last_page": 5,
        "per_page": 15,
        "total": 73
    }
}

// Error
{
    "status": "error",
    "message": "Validation failed",
    "errors": {
        "email": ["The email field is required."]
    }
}
```

Custom Stubs
------------

[](#custom-stubs)

You can customize the generated file templates:

```
php artisan vendor:publish --tag=modular-stubs
```

Then edit files in `stubs/modular/` directory.

Testing
-------

[](#testing)

```
composer test
```

Or run specific tests:

```
./vendor/bin/phpunit tests/Unit/
./vendor/bin/pest tests/Feature/
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

Please see [SECURITY](SECURITY.md) for our security policy.

License
-------

[](#license)

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

Credits
-------

[](#credits)

- [Uncover](https://uncoverthefuture.org)
- [All Contributors](https://github.com/uncoverthefuture-org/modular-monlith-laravel/graphs/contributors)

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance82

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

10

Last Release

92d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8656e6b0fe9b536d6c65b9a85d3a9edbbd42ff0a1f8b1b7e0dbf3f16fb9a801f?d=identicon)[uncoverthefuture](/maintainers/uncoverthefuture)

---

Top Contributors

[![sirdavis99](https://avatars.githubusercontent.com/u/55281305?v=4)](https://github.com/sirdavis99 "sirdavis99 (50 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (10 commits)")

---

Tags

laravelscaffoldingmodularmonolith

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/uncover-modular-monolith-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/uncover-modular-monolith-laravel/health.svg)](https://phpackages.com/packages/uncover-modular-monolith-laravel)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k51.0M7.6k](/packages/larastan-larastan)[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k89.4M575](/packages/laravel-passport)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k28.4M137](/packages/laravel-cashier)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k14.1M122](/packages/laravel-pulse)[laravel/ai

The official AI SDK for Laravel.

9782.1M162](/packages/laravel-ai)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
