A powerful SOLID-principle Laravel modular code generator specifically designed for API-first projects.
Transform your Laravel development with intelligent module generation that creates clean, maintainable, and scalable API architectures following industry best practices.
- Zero Frontend Concerns: Pure API-focused architecture
- SOLID Principles: Every generated component follows dependency injection and single responsibility
- Repository Pattern: Clean separation of data access logic
- Service Layer: Business logic abstraction for better testability
- Complete Module Scaffold: Controllers, Models, Services, Repositories, Interfaces, Requests, Migrations, Tests
- Two Generation Modes: Simple list APIs or full CRUD resources
- Auto-Wired Dependencies: Everything is pre-configured and ready to use
- Smart Naming: Consistent naming conventions across all components
- One Command Setup: Generate complete modules with a single artisan command
- Zero Configuration: Works out of the box with sensible defaults
- Full Customization: Publish and modify all templates to match your standards
- IDE Friendly: Proper type hints and interfaces for better development experience
| Component | Version |
|---|---|
| PHP | ^7.4 | ^8.0 | ^8.1 | ^8.2 | ^8.3 |
| Laravel | ^8.0 | ^9.0 | ^10.0 | ^11.0 | ^12.0 |
# Install the package
composer require webmonks/laravel-api-modules# Publish configuration for customization
php artisan vendor:publish --tag=laravel-api-modules-config
# Publish stub templates for team-specific modifications
php artisan vendor:publish --tag=laravel-api-modules-stubsThat's it! The package is auto-discovered and ready to use. π
# Create a simple list-only API module
php artisan make:module Blog
# Create a full CRUD resource module
php artisan make:module Product --resource# Preview what would be removed (dry-run)
php artisan remove:module Blog --preview
# Remove with interactive confirmation
php artisan remove:module Blog
# Remove with automatic backup (default)
php artisan remove:module Product
# Remove without confirmations
php artisan remove:module Product --force
# Remove without creating backup
php artisan remove:module Product --force --no-backupapp/Modules/Blog/
βββ Controllers/BlogController.php # List endpoint only
βββ Models/Blog.php # Eloquent model with traits
βββ Services/BlogService.php # Business logic layer
βββ Repositories/BlogRepository.php # Data access layer
βββ Request/ListBlogRequest.php # Validation for list endpoint
βββ routes.php # Auto-registered routes
app/Core/
βββ Interfaces/BlogRepositoryInterface.php # Repository contract
βββ Providers/RepositoryServiceProvider.php # Auto-generated bindings
database/migrations/
βββ xxxx_xx_xx_xxxxxx_create_blogs_table.php
tests/
βββ Feature/Modules/Blog/BlogFeatureTest.php
βββ Unit/Modules/Blog/BlogUnitTest.php
app/Modules/Product/
βββ Controllers/ProductController.php # Full CRUD endpoints
βββ Models/Product.php # Eloquent model
βββ Services/ProductService.php # Complete business logic
βββ Repositories/ProductRepository.php # Full data operations
βββ Request/
β βββ ListProductRequest.php # List validation
β βββ ViewProductRequest.php # View validation
β βββ CreateProductRequest.php # Create validation
β βββ UpdateProductRequest.php # Update validation
β βββ DeleteProductRequest.php # Delete validation
βββ routes.php # All CRUD routes
After generating your first module, your Laravel application will have this enhanced structure:
app/
βββ Core/ # ποΈ Architecture Layer
β βββ Interfaces/ # Repository contracts
β β βββ BlogRepositoryInterface.php
β βββ Providers/ # Auto-generated service bindings
β β βββ RepositoryServiceProvider.php
β βββ Services/ # Shared base services
β β βββ BaseService.php
β βββ Traits/ # Reusable functionality
β βββ ApiResponser.php # Standard API responses
β βββ ActivityLogHelper.php # Model activity tracking
β βββ PdfGeneratorTrait.php # PDF generation
β βββ SmsSender.php # SMS notifications
β βββ UserUpdater.php # Auto user tracking
βββ Helpers/ # π§ Utility Functions
β βββ AutoloadFiles/ # Auto-loaded helpers
β βββ string_helpers.php
βββ Models/ # ποΈ Shared Models
β βββ BaseModel.php # Enhanced base model
βββ Modules/ # π― Your API Modules
βββ Blog/
βββ Controllers/BlogController.php
βββ Models/Blog.php
βββ Repositories/BlogRepository.php
βββ Services/BlogService.php
βββ Request/ListBlogRequest.php
βββ routes.php # Auto-discovered routes
config/
βββ laravel-api-modules.php # Package configuration
database/migrations/
βββ 2024_01_01_000000_create_blogs_table.php
tests/
βββ Feature/Modules/Blog/BlogFeatureTest.php
βββ Unit/Modules/Blog/BlogUnitTest.php
Complete cleanup with safety checks! The package provides:
- π Preview Mode: See exactly what files will be removed before deletion
- π¦ Automatic Backup: Creates timestamped backups before removal (optional)
β οΈ Multi-stage Confirmations: Multiple safety prompts prevent accidental deletion- π§Ή Complete Cleanup: Removes all related files (controllers, models, tests, migrations, interfaces)
- π Repository Binding Cleanup: Automatically cleans up service provider bindings
- π¨ Security Validation: Prevents path traversal and validates module names
# Safe removal with all protections
php artisan remove:module UserProfile
# Quick preview of what would be removed
php artisan remove:module UserProfile --preview
# Force removal without confirmations
php artisan remove:module UserProfile --force --no-backupZero Configuration Required! The package automatically:
- Generates
RepositoryServiceProvider.phpto bind interfaces to implementations - Registers the provider in Laravel's service container
- Creates proper dependency injection for all your modules
// This happens automatically - no manual binding needed!
$this->app->bind(
BlogRepositoryInterface::class,
BlogRepository::class
);The package includes battle-tested traits for common API functionality:
| Trait | Purpose | Auto-Included |
|---|---|---|
ApiResponser |
Consistent API response format | β Required |
ActivityLogHelper |
Track model changes and actions | βοΈ Optional |
PdfGeneratorTrait |
Generate PDFs from Blade templates | βοΈ Optional |
SmsSender |
Send SMS via Twilio with logging | βοΈ Optional |
UserUpdater |
Auto-manage created_by, updated_by fields |
βοΈ Optional |
Drop any PHP helper files into app/Helpers/AutoloadFiles/ and they're automatically available throughout your application:
// app/Helpers/AutoloadFiles/api_helpers.php
function transform_response($data, $message = 'Success') {
return ['data' => $data, 'message' => $message];
}
// Available everywhere in your app automatically!
return transform_response($users, 'Users retrieved successfully');The package works perfectly with zero configuration, but offers extensive customization options:
π View Configuration Options
// config/laravel-api-modules.php
return [
// Directory Structure
'modules_dir' => 'app/Modules',
'core_interfaces_dir' => 'app/Core/Interfaces',
// Namespaces
'namespace' => 'App\\Modules',
'interface_namespace' => 'App\\Core\\Interfaces',
// Base Classes
'enable_base_model' => true, // Generate BaseModel
'enable_base_service' => true, // Generate BaseService
'model_extends_base' => 'BaseModel',
// Code Generation
'generate_migration' => true, // Create migrations
'generate_tests' => true, // Create test files
'auto_discover_routes' => true, // Auto-register routes
// Traits Configuration
'base_model_traits' => [
'ApiResponser' => true, // Required
'ActivityLogHelper' => true, // Optional
'PdfGeneratorTrait' => true, // Optional
'SmsSender' => true, // Optional
'UserUpdater' => true, // Optional
],
];# Generate a simple blog list API
php artisan make:module Blog
# Remove the blog module safely (with backup)
php artisan remove:module BlogGenerated controller will have a clean, testable structure:
// app/Modules/Blog/Controllers/BlogController.php
class BlogController extends Controller
{
protected $blogService;
public function __construct(BlogService $blogService)
{
$this->blogService = $blogService; // Auto-injected
}
public function list(ListBlogRequest $request)
{
$response = $this->blogService->listBlogs($request->validated());
return $this->successResponse(
$response,
'Blogs retrieved successfully',
Response::HTTP_OK
);
}
}# Generate a complete product management API
php artisan make:module Product --resource
# Preview what would be removed before deletion
php artisan remove:module Product --preview
# Remove with force (skip confirmations)
php artisan remove:module Product --forceThis creates a full API with endpoints:
GET /api/products- List products with filteringGET /api/products/{id}- Get single productPOST /api/products- Create new productPUT /api/products/{id}- Update productDELETE /api/products/{id}- Delete product
// app/Helpers/AutoloadFiles/product_helpers.php
function calculate_discount($original_price, $discount_percent) {
return $original_price * (1 - $discount_percent / 100);
}
function format_currency($amount) {
return '$' . number_format($amount, 2);
}// Use anywhere in your application
$discounted_price = calculate_discount($product->price, 15);
$formatted_price = format_currency($discounted_price);Publish stubs and modify them to match your team's conventions:
php artisan vendor:publish --tag=laravel-api-modules-stubsEdit any stub in stubs/laravel-api-modules/ to customize generated code:
// stubs/laravel-api-modules/controller.stub
class {{model}}Controller extends Controller
{
// Your custom controller template
// Add your standard methods, middleware, etc.
}The generated BaseModel and BaseService can be extended with your common functionality:
// app/Models/BaseModel.php - Auto-generated, customize as needed
abstract class BaseModel extends Model
{
use ApiResponser, ActivityLogHelper, UserUpdater;
// Add your common model methods here
public function scopeActive($query) {
return $query->where('is_active', true);
}
}The package generates comprehensive test files for each module:
// tests/Feature/Modules/Blog/BlogFeatureTest.php
class BlogFeatureTest extends TestCase
{
public function test_can_list_blogs()
{
$response = $this->getJson('/api/blogs');
$response->assertStatus(200)
->assertJsonStructure(['data', 'message']);
}
}Run tests for your modules:
# Run all tests
php artisan test
# Run specific module tests
php artisan test tests/Feature/Modules/Blog/
php artisan test tests/Unit/Modules/Blog/- π Directory Structure Deep Dive - Understand the generated architecture
- π§ Helper System Guide - Master the auto-loader and create custom helpers
- π·οΈ Traits Reference - Leverage built-in traits and create your own
- βοΈ Configuration Reference - Customize every aspect of generation
- π Migration Guide - Upgrade between versions smoothly
- π Changelog - Track all changes and improvements
- π€ Contributing Guidelines - Join our development community
- π Security Policy - Report security vulnerabilities
- βοΈ Code of Conduct - Community standards
We welcome contributions from the community! Whether it's:
- π Bug Reports: Found an issue? Let us know!
- π‘ Feature Requests: Have ideas for improvements?
- π§ Code Contributions: Submit pull requests with enhancements
- π Documentation: Help improve our guides and examples
See our Contributing Guidelines for details.
Laravel API Modules is crafted with β€οΈ by WebMonks Technologies
- Lead Developer: Darshan Baraiya
- Company: WebMonks Technologies
- Laravel - The PHP Framework for Web Artisans
- PHP - A popular general-purpose scripting language
- SOLID Principles - Object-oriented design principles
- Repository Pattern - Clean architecture pattern
This package is open-sourced software licensed under the MIT License.
Made with β€οΈ for the Laravel community
β Give us a star β’ π¦ View on Packagist β’ π Report Issues