webmonks / laravel-api-modules
SOLID principle, modular API code generator for Laravel
Requires
- php: >=7.2
- barryvdh/laravel-dompdf: ^2.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0|^12.0
- twilio/sdk: *
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 ownBaseModel
andBaseService
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 inconfig/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
- Directory Structure Deep Dive
- Helpers System
- Traits & Extending Models
- Full Configuration Reference
- Upgrade Guide
- Changelog
Contributing
See CONTRIBUTING.md for guidelines and how to get involved.
License
MIT