albaraa / aztec
Automatic CRUD generator for Laravel modules
Requires
- php: ^8.1
- doctrine/dbal: ^4.4
- illuminate/console: ^12.0
- illuminate/filesystem: ^12.0
- illuminate/support: ^12.0
- nikic/php-parser: ^5.7
README
Introduction
Aztec is a powerful Laravel package designed to automate the generation of a clean, layered architecture for your application modules. It goes beyond simple CRUD generation by implementing a robust Service-Repository pattern, ensuring your controllers remain thin and your business logic is well-encapsulated.
Installation
You can install the package via composer:
composer require albaraa/aztec
Features
- Layered Architecture: Generates Controller, Service, Repository (Interface & Implementation), API Resource, and Form Requests.
- Module Support: Designed to work intimately with modular structures (e.g.,
Modules/Blog). - Interactive Generation: CLI prompts guide you through selecting relationships for resources, adding custom filters, and configuring relation syncing.
- Smart Validation: Automatically builds validation rules and translation keys (e.g.,
validations.module.field.rule) based on your model's attributes and casts. - Automatic Wiring: Automatically binds repositories in your Module's ServiceProvider and appends routes to
web.php.
Usage
Generating CRUD
The main entry point is the aztec:make-crud command. It requires the Module name and the Model name (which must already exist).
php artisan aztec:make-crud {Module} {Model}
Example:
To generate CRUD for a Post model inside the Blog module:
php artisan aztec:make-crud Blog Post
The Generation Flow
When you run the command, Aztec performs the following steps:
- Analysis: It inspects your Model file to understand its fillable attributes, casts, and relationships.
- Interactive Configuration:
- Resources: It asks which relationships should be included in the API Resource.
- Service Layer: It prompts you to add custom filters for the listing endpoint (e.g., filter by status, type, etc.) and asks which relationships should be synced automatically during create/update operations.
- File Generation:
- Repository: Generates
PostRepositoryInterfaceandEloquentPostRepository. It checksBlogServiceProviderand binds the interface to the implementation automatically. - Service: Generates
PostServicecontaining business logic. It handles pagination, search (smartly guessing searchable fields), custom filtering, and transaction-wrapped CRUD operations. - Requests: Generates
PostStoreRequestandPostUpdateRequestwith rules inferred from your model. It also generates amessages()method returning code-based keys (e.g.,validations.blog.title.required) for frontend localization. - Controller: Generates
PostControllerwhich injects thePostService. It remains clean and acts only as a gateway. - Resource: Generates
PostResourceto format the JSON response. - Routes: Appends standard RESTful routes to
Modules/Blog/routes/web.phpwith a clean group structure.
- Repository: Generates
Directory Structure Idea
Assuming a Blog module and Post model, Aztec creates/updates:
Modules/Blog/
├── app/
│ ├── Http/
│ │ ├── Controllers/
│ │ │ └── PostController.php
│ │ ├── Requests/
│ │ │ ├── PostStoreRequest.php
│ │ │ └── PostUpdateRequest.php
│ │ ├── Resources/
│ │ │ └── PostResource.php
│ ├── Repositories/
│ │ ├── Interfaces/
│ │ │ └── PostRepositoryInterface.php
│ │ ├── EloquentPostRepository.php
│ ├── Services/
│ │ └── PostService.php
│ └── Providers/
│ └── BlogServiceProvider.php [Updated for Binding]
└── routes/
└── web.php [Updated with Routes]
Customization
You can customize the available layers and generation behavior by publishing the config file (if available):
php artisan vendor:publish --tag=aztec-config
Crafted for developers who value clean code and speed.