PHPackages                             munguia-er/laravel-clean-generator - 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. [API Development](/categories/api)
4. /
5. munguia-er/laravel-clean-generator

ActiveLibrary[API Development](/categories/api)

munguia-er/laravel-clean-generator
==================================

Generates Clean Architecture structure for Laravel — DTOs, Repositories, Services, Controllers with Web &amp; API stacks

v1.1.0(2mo ago)03↓50%MITPHPPHP ^8.1|^8.2|^8.3CI passing

Since Feb 27Pushed 2mo agoCompare

[ Source](https://github.com/munguia-er/laravel-clean-generator)[ Packagist](https://packagist.org/packages/munguia-er/laravel-clean-generator)[ Docs](https://github.com/munguia-er/laravel-clean-generator)[ RSS](/packages/munguia-er-laravel-clean-generator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (3)Used By (0)

laravel-clean-generator
=======================

[](#laravel-clean-generator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9f8a3d0989441c32e8432f7714d17bd0a5af07567b9f9f5042bc594860a2fb7e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d756e677569612d65722f6c61726176656c2d636c65616e2d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/munguia-er/laravel-clean-generator)[![PHP Version](https://camo.githubusercontent.com/0c992c6dd4d4b3656cde8ad8324975bfe10300c5dd96a48ffafdcf249108391a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d756e677569612d65722f6c61726176656c2d636c65616e2d67656e657261746f723f7374796c653d666c61742d737175617265)](https://packagist.org/packages/munguia-er/laravel-clean-generator)[![License](https://camo.githubusercontent.com/93b44e273152627f05271b33a8cbf91ab098697e263494562dede4f8af0e2272/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d756e677569612d65722f6c61726176656c2d636c65616e2d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Tests](https://camo.githubusercontent.com/503b79c311cdbbe6034beef3d95ceeadb08199ff616c195f3bff6ef4584ac337/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d756e677569612d65722f6c61726176656c2d636c65616e2d67656e657261746f722f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/munguia-er/laravel-clean-generator/actions)

A Laravel Artisan package that scaffolds a **Clean Architecture** (or Simple App-based) structure from a single command. It introspects your database schema and generates fully typed **DTOs**, **Repository interfaces &amp; implementations**, **Service interfaces &amp; implementations**, and **Controllers** — organized by architecture and stack (Web or API).

---

Features
--------

[](#features)

- 🏗 **Dual architecture support** — `clean` (Domain/Application/Infrastructure layers) or `simple` (flat App-based)
- 🌐 **Web &amp; API controllers** — configurable default stack, HTML or JSON responses
- 🛡 **Smart Form Requests** — auto-generates `StoreRequest` and `UpdateRequest` with schema-mapped validation arrays (unique rules, foreign keys, limits, enums)
- 🗂 **Module sub-paths** — `Blog/Post` generates `App/DTOs/Blog/PostData.php`, not `App/Blog/Post/DTOs`
- 🎯 **Explicit Primary Keys** — extracts primary key type and auto-increment status dynamically from the database
- 🔐 **Strict validation** — stops early if the model is missing and `--table` is not provided
- 🔄 **Model preservation** — never moves or overwrites an existing model
- 📦 **Auto-binding** — automatically registers Repository and Service bindings in `AppServiceProvider`
- 🛣 **Auto-routing** — injects `Route::resource()` or `Route::apiResource()` into the correct route file
- 🧬 **Schema introspection** — detects SoftDeletes, primary keys, nullable columns, casts
- ✅ **Full test coverage** — runs against Orchestra Testbench

---

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

[](#requirements)

DependencyVersionPHP`^8.1`Laravel`10.x`, `11.x``nikic/php-parser``^5.0``doctrine/dbal``^3.8 | ^4.0`---

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

[](#installation)

```
composer require munguia-er/laravel-clean-generator
```

The service provider is registered automatically via Laravel's package discovery.

Publish the configuration file:

```
php artisan vendor:publish --tag=clean-generator-config
```

---

Configuration
-------------

[](#configuration)

`config/clean-generator.php`

```
return [
    /*
     | Active architecture: 'clean' (default) or 'simple'.
     */
    'architecture'    => 'clean',

    /*
     | Default controller stack when neither --api nor --web is passed.
     | Options: 'web' | 'api'
     */
    'default_stack'   => 'web',

    'base_namespace'  => 'App',
    'base_path'       => null, // defaults to app_path()

    /*
     | Auto-register generated bindings and routes, respectively.
     */
    'auto_register'   => [
        'bindings' => true,
        'routes'   => true,
    ],

    /*
     | Directory paths for each artifact type, keyed by architecture.
     */
    'architectures' => [
        'simple' => [
            'models'                 => 'Models',
            'dtos'                   => 'DTOs',
            'requests'               => 'Http/Requests',
            'repository_interfaces'  => 'Interfaces/Repositories',
            'repositories'           => 'Repositories',
            'service_interfaces'     => 'Interfaces/Services',
            'services'               => 'Services',
            'controllers'            => 'Http/Controllers',
        ],
        'clean' => [
            'models'                 => 'Models',
            'dtos'                   => 'Domain/DTOs',
            'requests'               => 'Application/Http/Requests',
            'repository_interfaces'  => 'Domain/Contracts',
            'repositories'           => 'Infrastructure/Repositories',
            'service_interfaces'     => 'Domain/Services',
            'services'               => 'Domain/Services',
            'controllers'            => 'Application/Http/Controllers',
        ],
    ],
];
```

---

Usage
-----

[](#usage)

### Basic

[](#basic)

```
# Infer table from model name (model must exist)
php artisan clean:generate Post

# Specify table explicitly (generates model too)
php artisan clean:generate Post --table=posts

# Module sub-paths
php artisan clean:generate Blog/Post --table=posts
php artisan clean:generate Blog/Admin/Post --table=posts
```

### Web vs API

[](#web-vs-api)

```
# Web controller (HTML hardcoded responses)
php artisan clean:generate Blog/Post --table=posts --web

# API controller (JSON responses) — all files placed under Api/ sub-path
php artisan clean:generate Blog/Post --table=posts --api

# Using both flags is an error
php artisan clean:generate Blog/Post --table=posts --api --web  # → ERROR
```

> **Note:** When `--api` is used, an `Api/` segment is automatically injected into every layer's sub-path. This keeps Web and API scaffolding cleanly separated when both coexist in the same project.

### Options

[](#options)

OptionDescription`{model}`Model name, optionally with module path (`Blog/Post`)`--table=`Database table to introspect. Required when the model does not exist.`--api`Generate an API (JSON) controller under `Api/` sub-path`--web`Generate a Web (HTML) controller`--force`Overwrite existing files---

Generated Structure
-------------------

[](#generated-structure)

### Simple architecture — `php artisan clean:generate Blog/Post --table=posts --web`

[](#simple-architecture--php-artisan-cleangenerate-blogpost---tableposts---web)

```
app/
├── Models/Blog/Post.php
├── DTOs/Blog/
│   ├── PostData.php
│   ├── CreatePostData.php
│   └── UpdatePostData.php
├── Http/
│   ├── Requests/Blog/
│   │   ├── StorePostRequest.php
│   │   └── UpdatePostRequest.php
│   └── Controllers/Blog/PostController.php
├── Interfaces/
│   ├── Repositories/Blog/PostRepositoryInterface.php
│   └── Services/Blog/PostServiceInterface.php
├── Repositories/Blog/EloquentPostRepository.php
└── Services/Blog/PostService.php

```

### Clean architecture — `php artisan clean:generate Blog/Post --table=posts --api`

[](#clean-architecture--php-artisan-cleangenerate-blogpost---tableposts---api)

```
app/
├── Models/Api/Blog/Post.php
├── Domain/
│   ├── DTOs/Api/Blog/
│   │   ├── PostData.php
│   │   ├── CreatePostData.php
│   │   └── UpdatePostData.php
│   ├── Contracts/Api/Blog/PostRepositoryInterface.php
│   └── Services/Api/Blog/
│       ├── PostServiceInterface.php
│       └── PostService.php
├── Infrastructure/Repositories/Api/Blog/EloquentPostRepository.php
└── Application/Http/
    ├── Requests/Api/Blog/
    │   ├── StorePostRequest.php
    │   └── UpdatePostRequest.php
    └── Controllers/Api/Blog/ApiPostController.php

```

---

Architecture Principles
-----------------------

[](#architecture-principles)

### Layer responsibility

[](#layer-responsibility)

LayerResponsibility**Models**Eloquent ORM models, SoftDeletes, casts**DTOs**Typed, readonly value objects for data transfer**Form Requests**HTTP request validation logic and data authorization**Repository Interfaces**Persistence contract (domain layer)**Repository Implementations**Eloquent concrete implementations**Service Interfaces**Business logic contract**Service Implementations**Orchestrates repository + business rules**Controllers**HTTP entry point; delegates entirely to service layer### Model handling behavior

[](#model-handling-behavior)

- If `--table` is provided → model is **always generated** (at the Api/-prefixed path when `--api`)
- If `--table` is **not** provided and the model **exists** → model is left untouched; all other layers are generated around it
- If `--table` is **not** provided and the model **does not exist** → command fails immediately with a descriptive error

---

Versioning
----------

[](#versioning)

This package follows [Semantic Versioning](https://semver.org/):

- **MAJOR** — breaking changes to the generated file structure or command API
- **MINOR** — new flags, new generators, new architecture options
- **PATCH** — bug fixes, documentation, internal refactors

---

Testing
-------

[](#testing)

```
composer test
```

The test suite uses [Orchestra Testbench](https://github.com/orchestral/testbench) with an in-memory SQLite database.

---

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

[](#contributing)

Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on the development workflow and how to submit pull requests.

---

Code of Conduct
---------------

[](#code-of-conduct)

This project adheres to the [Contributor Covenant](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code.

---

License
-------

[](#license)

MIT — see [LICENSE](LICENSE) for details.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance86

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~4 days

Total

2

Last Release

70d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/16d2f884c610438751c8a7efcd2a40288342bdcce2e5b52b6a68a241dc42331a?d=identicon)[munguia-er](/maintainers/munguia-er)

---

Top Contributors

[![munguia-er](https://avatars.githubusercontent.com/u/77714212?v=4)](https://github.com/munguia-er "munguia-er (11 commits)")

---

Tags

apiweblaravelcode generatorscaffoldartisanrepository patternddddtoclean architecture

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/munguia-er-laravel-clean-generator/health.svg)

```
[![Health](https://phpackages.com/badges/munguia-er-laravel-clean-generator/health.svg)](https://phpackages.com/packages/munguia-er-laravel-clean-generator)
```

###  Alternatives

[andreaselia/laravel-api-to-postman

Generate a Postman collection automatically from your Laravel API

1.0k586.2k3](/packages/andreaselia-laravel-api-to-postman)[sebdesign/artisan-cloudflare

Laravel artisan commands for Cloudflare

77273.8k](/packages/sebdesign-artisan-cloudflare)

PHPackages © 2026

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