PHPackages                             webmonks/laravel-api-modules - 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. webmonks/laravel-api-modules

ActiveLibrary[API Development](/categories/api)

webmonks/laravel-api-modules
============================

SOLID principle, modular API code generator for Laravel

v1.14(8mo ago)115MITPHPPHP &gt;=7.4CI passing

Since Sep 3Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/damku999/laravel-api-modules)[ Packagist](https://packagist.org/packages/webmonks/laravel-api-modules)[ RSS](/packages/webmonks-laravel-api-modules/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (12)Versions (7)Used By (0)

🚀 Laravel API Modules
=====================

[](#-laravel-api-modules)

[![Latest Version on Packagist](https://camo.githubusercontent.com/99aeacafbdd16e7a62f71386341e0a6c7ad4b9a814c2ff692ce2f7c3f9cf9066/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7765626d6f6e6b732f6c61726176656c2d6170692d6d6f64756c65732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/webmonks/laravel-api-modules)[![Total Downloads](https://camo.githubusercontent.com/af9bbe16a331fbe3d817b3637cb57aeb73e1c5513572e64744c80d1c9a3a568e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7765626d6f6e6b732f6c61726176656c2d6170692d6d6f64756c65732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/webmonks/laravel-api-modules)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Laravel](https://camo.githubusercontent.com/2682dee62fd8005fb8cd5bf0e7b99e99afec36141f306ed324cb71914950601c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d382e78253230746f25323031322e782d6666326432303f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c)](https://laravel.com)[![PHP](https://camo.githubusercontent.com/1c76d3ef17215b809578e196daa9d319ec740863c363dcdd982fd5dba8a84353/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e34253230746f253230382e332d3737376262343f7374796c653d666c61742d737175617265266c6f676f3d706870)](https://php.net)

**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.

---

✨ Why Laravel API Modules?
--------------------------

[](#-why-laravel-api-modules)

### 🎯 **Built for API Excellence**

[](#-built-for-api-excellence)

- **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

### ⚡ **Intelligent Generation**

[](#-intelligent-generation)

- **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

### 🔧 **Developer Experience**

[](#-developer-experience)

- **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

---

📦 Installation
--------------

[](#-installation)

### Requirements

[](#requirements)

ComponentVersion**PHP**`^7.4` | `^8.0` | `^8.1` | `^8.2` | `^8.3`**Laravel**`^8.0` | `^9.0` | `^10.0` | `^11.0` | `^12.0`### Quick Install

[](#quick-install)

```
# Install the package
composer require webmonks/laravel-api-modules
```

### Configuration (Optional)

[](#configuration-optional)

```
# 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-stubs
```

That's it! The package is auto-discovered and ready to use. 🎉

---

🚀 Quick Start
-------------

[](#-quick-start)

### Generate Your First Module

[](#generate-your-first-module)

```
# Create a simple list-only API module
php artisan make:module Blog

# Create a full CRUD resource module
php artisan make:module Product --resource
```

### Remove Modules Safely

[](#remove-modules-safely)

```
# 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-backup
```

### What Gets Generated?

[](#what-gets-generated)

#### Simple Module (`php artisan make:module Blog`)

[](#simple-module-php-artisan-makemodule-blog)

```
app/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

```

#### Resource Module (`php artisan make:module Product --resource`)

[](#resource-module-php-artisan-makemodule-product---resource)

```
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

```

### Your Project Structure

[](#your-project-structure)

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

```

---

🔧 Core Features
---------------

[](#-core-features)

### 🗑️ **Safe Module Removal**

[](#️-safe-module-removal)

**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-backup
```

### 🔗 Automatic Repository Binding

[](#-automatic-repository-binding)

**Zero Configuration Required!** The package automatically:

- Generates `RepositoryServiceProvider.php` to 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
);
```

### 🏷️ Smart Traits System

[](#️-smart-traits-system)

The package includes battle-tested traits for common API functionality:

TraitPurposeAuto-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### 🔄 Helper Autoloader

[](#-helper-autoloader)

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');
```

---

⚙️ Configuration
----------------

[](#️-configuration)

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
    ],
];
```

---

💡 Usage Examples
----------------

[](#-usage-examples)

### Example 1: Blog API Module

[](#example-1-blog-api-module)

```
# Generate a simple blog list API
php artisan make:module Blog

# Remove the blog module safely (with backup)
php artisan remove:module Blog
```

Generated 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
        );
    }
}
```

### Example 2: Full CRUD Product API

[](#example-2-full-crud-product-api)

```
# 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 --force
```

This creates a full API with endpoints:

- `GET /api/products` - List products with filtering
- `GET /api/products/{id}` - Get single product
- `POST /api/products` - Create new product
- `PUT /api/products/{id}` - Update product
- `DELETE /api/products/{id}` - Delete product

### Example 3: Custom Helper Integration

[](#example-3-custom-helper-integration)

```
// 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);
```

---

🔧 Advanced Customization
------------------------

[](#-advanced-customization)

### Custom Stub Templates

[](#custom-stub-templates)

Publish stubs and modify them to match your team's conventions:

```
php artisan vendor:publish --tag=laravel-api-modules-stubs
```

Edit 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.
}
```

### Extending Base Classes

[](#extending-base-classes)

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);
    }
}
```

---

🧪 Testing
---------

[](#-testing)

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/
```

---

📚 Documentation
---------------

[](#-documentation)

### Complete Guides

[](#complete-guides)

- **[📁 Directory Structure Deep Dive](docs/STRUCTURE.md)** - Understand the generated architecture
- **[🔧 Helper System Guide](docs/HELPERS.md)** - Master the auto-loader and create custom helpers
- **[🏷️ Traits Reference](docs/TRAITS.md)** - Leverage built-in traits and create your own
- **[⚙️ Configuration Reference](docs/CONFIGURATION.md)** - Customize every aspect of generation
- **[🚀 Migration Guide](docs/UPGRADE.md)** - Upgrade between versions smoothly

### Resources

[](#resources)

- **[📋 Changelog](docs/CHANGELOG.md)** - Track all changes and improvements
- **[🤝 Contributing Guidelines](docs/CONTRIBUTING.md)** - Join our development community
- **[🔐 Security Policy](SECURITY.md)** - Report security vulnerabilities
- **[⚖️ Code of Conduct](CODE_OF_CONDUCT.md)** - Community standards

---

🤝 Contributing
--------------

[](#-contributing)

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](docs/CONTRIBUTING.md) for details.

---

🏆 Credits
---------

[](#-credits)

**Laravel API Modules** is crafted with ❤️ by [WebMonks Technologies](https://webmonks.in)

- **Lead Developer**: [Darshan Baraiya](mailto:darshan@webmonks.in)
- **Company**: [WebMonks Technologies](https://webmonks.in)

### Built With

[](#built-with)

- **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

---

📄 License
---------

[](#-license)

This package is open-sourced software licensed under the [MIT License](LICENSE).

---

### 🌟 Star this repository if it helped you!

[](#-star-this-repository-if-it-helped-you)

**Made with ❤️ for the Laravel community**

[⭐ Give us a star](https://github.com/damku999/laravel-api-modules) • [📦 View on Packagist](https://packagist.org/packages/webmonks/laravel-api-modules) • [🐛 Report Issues](https://github.com/damku999/laravel-api-modules/issues)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance61

Regular maintenance activity

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

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 ~1 days

Total

6

Last Release

249d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/db4eb155c593a3464664968d1af6c21853391ea61147d1576f11389496f2e431?d=identicon)[damku999](/maintainers/damku999)

---

Top Contributors

[![damku999](https://avatars.githubusercontent.com/u/8331339?v=4)](https://github.com/damku999 "damku999 (6 commits)")

---

Tags

apilaravelcode generatormodulemodulesrestfulmodularsolidwebmonks

###  Code Quality

TestsPest

Static AnalysisPHPStan, Psalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/webmonks-laravel-api-modules/health.svg)

```
[![Health](https://phpackages.com/badges/webmonks-laravel-api-modules/health.svg)](https://phpackages.com/packages/webmonks-laravel-api-modules)
```

###  Alternatives

[api-ecosystem-for-laravel/dingo-api

A RESTful API package for the Laravel and Lumen frameworks.

3121.5M10](/packages/api-ecosystem-for-laravel-dingo-api)[internachi/modular

Modularize your Laravel apps

1.1k662.4k8](/packages/internachi-modular)[obiefy/api-response

Simple Laravel package to return Json responses.

17324.6k](/packages/obiefy-api-response)

PHPackages © 2026

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