← All work
Open source Free & open source

Laravel Module Scaffolding

Domain-Driven CRUD Generator Package

Type
Open source
Built with
PHP 8.2+, Laravel 10/11/12/13, Composer
Toolkit
7 technologies

Overview

A production-ready Composer package that automates end-to-end CRUD module generation for Laravel applications following domain-driven design principles.

Born from frustration with existing scaffolding tools that didn't match real-world architectural preferences, this package generates complete, opinionated modules reflecting a clean, maintainable architecture.

The generator creates full module stacks in seconds—from database migrations and models through controllers, services, query classes, validation layers, Blade views, and class-based JavaScript files—all organised under a domain-oriented namespace structure. Unlike generic scaffolders, it respects your architectural conventions: Spatie Data DTOs as direct method parameters (eliminating FormRequest boilerplate), explicit column selection in query classes for performance, class-based JavaScript modules stored as organised resources, and a cohesive layered architecture pattern.

Active Project: This is a living tool continuously refined based on real-world usage in long-running production applications, with planned expansions for multiple architectural patterns to serve diverse developer preferences.

The hard parts

What made it tricky.

Every project has a few problems that decide whether it works in real life. These were the ones here, and how we handled them.

  1. 01

    Opinionated Yet Flexible Architecture

    Challenge

    Creating a generator that enforces good architectural practices without being overly rigid or one-size-fits-all

    Solution

    Built configuration-driven stubs with a publishable override system, allowing developers to customise templates while maintaining core conventions (DDD structure, service layer pattern, query objects)

  2. 02

    Multiple Validation Strategies

    Challenge

    Supporting both FormRequest and Spatie Data DTO validation approaches without code duplication

    Solution

    Implemented validation abstraction layer with switchable stub generation, allowing DTOs to be passed directly as method arguments (your preferred pattern)

  3. 03

    Flexible Data Source Resolution

    Challenge

    Accommodating multiple field definition methods (existing tables, YAML definitions, interactive prompts) without complex logic

    Solution

    Implemented priority-based resolution strategy: existing schema → YAML file → interactive prompts, giving developers a choice while maintaining sensible defaults

  4. 04

    JavaScript Module Organisation

    Challenge

    Generating class-based JavaScript modules that integrate seamlessly with Vite compilation and production minification

    Solution

    Generated JavaScript files as organised class-based modules stored in the resources folder with Vite configuration compatibility for centralised compilation via app.blade.php

  5. 05

    Cross-Version Compatibility

    Challenge

    Supporting Laravel 10, 11, 12, and 13 with different feature sets and API changes

    Solution

    Abstracted version-specific behaviour through configuration and tested against all supported versions with CI pipeline validation

  6. 06

    Stub Customisation Without Maintenance Burden

    Challenge

    Allowing developers to customise code generation while maintaining package upgradability

    Solution

    Implemented a publishable stub system where only modified stubs are used; unmodified stubs fall back to package defaults

  7. 07

    Query Performance and Explicitness

    Challenge

    Preventing N+1 queries and forcing developers to think about data access patterns

    Solution

    Generated Query classes with explicit column selection enforcement (configurable), making data access intentions clear in the codebase

Under the hood

The stack.

  • PHP 8.2+
  • Laravel 10/11/12/13
  • Composer
  • Artisan Commands
  • Blade
  • Spatie Data
  • YAML
Try it yourself
composer require gajjar-mitul/laravel-module-scaffolding

Free to use under its open-source licence. Issues and pull requests are welcome.

View on GitHub ↗
Next project 20 / 20 Laravel Bootstrap CLI One command to a ready local site on Linux: new Laravel app, nginx vhost, PHP-FPM, MySQL database and trusted SSL. Open source Bash Shell Scripting nginx Read the case study