webmonks/laravel-api-modules

SOLID principle, modular API code generator for Laravel

v1.0.0 2025-05-26 10:28 UTC

This package is auto-updated.

Last update: 2025-05-27 12:05:02 UTC


README

SOLID-principle Laravel modular code generator for API-first projects.

Features

  • πŸš€ Generate Modular API Code:
    php artisan make:module {Name} [--resource] creates Controllers, Models, Services, Repositories, Interfaces, Requests, Migrations, and Tests (API only) β€” all SOLID and modular.

  • πŸ”— Automatic Repository Binding:
    Auto-binds {Module}RepositoryInterface to {Module}Repository for all modules. No manual registration needed.

  • 🧩 BaseModel & BaseService:
    Optionally generate and extend your own BaseModel and BaseService for DRY, testable, and reusable code.

  • 🏷️ Traits & Helpers:
    Automatically publishes a suite of useful traits and a flexible helper autoloader, with zero manual setup.

  • πŸ“ Customizable Stubs:
    Publish and edit all stub templates to fit your team’s conventions.

  • βš™οΈ Powerful Config:
    Everything is tweakable in config/laravel-api-modules.php.

  • πŸ”„ Auto Route Registration:
    All generated modules auto-register their routes.

  • πŸ›‘οΈ Modern Laravel Support:
    Compatible with Laravel 8–12, PHP 7.2–8.3.

Installation

composer require webmonks/laravel-api-modules

# Publish the config file (optional, but recommended)
php artisan vendor:publish --tag=laravel-api-modules-config

# Publish stub files for full customization (optional)
php artisan vendor:publish --tag=laravel-api-modules-stubs

Usage

Generate a complete module:

# This creates all files for a Blog module in app/Modules/Blog/
php artisan make:module Blog
# for only list api 
php artisan make:module Blog --resource
# for Laravel api resource  

Directory Structure

After generating a module, your app will typically look like:

app/
  Core/
    Interfaces/
    Providers/
    Services/
    Traits/
  Helpers/
    AutoloadFiles/
  Modules/
    Blog/
      Controllers/
      Models/
      Requests/
      Repositories/
      Services/
      routes.php
config/
  laravel-api-modules.php
database/
  migrations/

See docs/STRUCTURE.md for a full breakdown.

Repository Binding

  • The package auto-generates app/Core/Providers/RepositoryServiceProvider.php to bind each {Module}RepositoryInterface to its {Module}Repository.
  • No manual registration needed: This provider is automatically registered by the package if present. You don't need to edit config/app.php.

Helper Autoloading

  • All PHP files in app/Helpers/AutoloadFiles/ are auto-loaded at runtime.
  • Provided via a package HelperServiceProvider (auto-discovered, zero setup).
  • See docs/HELPERS.md for advanced usage and extending helpers.

Traits

  • Required traits:
    • ApiResponser, SoftDeletes
  • Optional traits:
    • ActivityLogHelper, PdfGeneratorTrait, SmsSender, UserUpdater
  • All traits are published to app/Core/Traits/ on first use if not already present.
  • See docs/TRAITS.md for details and customization.

Configuration

  • Configure everything in config/laravel-api-modules.php.
  • Enable/disable traits, base service/model, customize namespaces, stub replacements, and more.
  • See docs/CONFIGURATION.md for a full option reference.

Customization

  • Edit stub files in stubs/laravel-api-modules/ after publishing to match your team’s conventions.
  • Adjust config in config/laravel-api-modules.php.
  • Add your own traits and helpers; they'll be published automatically.

Advanced Topics

Contributing

See CONTRIBUTING.md for guidelines and how to get involved.

License

MIT