kornelius / strict-architecture
Perkakas penjaga standar arsitektur dan penamaan untuk Laravel 12
Requires
- php: ^8.2
- illuminate/console: ^12.0
- illuminate/support: ^12.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Strict Architecture is a Laravel package designed to enforce a consistent Controller-Service-Repository architecture across your project.
It provides an automated module generator, architecture scanner, and Git pre-commit hook to help maintain code quality, naming conventions, and architectural consistency across development teams.
Features
-
Fast Module Generator Generate the complete module structure—including Controller, Model, Migration, Service, Repository, View, and Pest Test—with a single command.
-
Architecture Scanner Scan your project for file naming violations and ensure that your codebase follows the defined architectural standards.
-
Git Pre-commit Hook Automatically prevent commits when architectural naming violations are detected or when Pest tests fail.
-
Built-in Pest Integration Generated test templates are automatically configured for the Laravel testing environment to ensure the required Laravel base classes and environment are available.
Requirements
- PHP 8.1 or higher
- Laravel 10.0 or higher
- Pest Testing Framework
Installation
Install the package via Composer:
composer require kornelius/strict-architecture
After installation, install the Git pre-commit hook:
php artisan strict:install-hook
The hook will automatically validate your architecture and run your Pest test suite before every commit.
Usage
1. Create a New Module
Use the make:strict Artisan command to generate a complete module:
php artisan make:strict Transaksi
The command generates the following files:
app/Http/Controllers/TransaksiController.php
app/Models/Transaksi.php
app/Services/TransaksiService.php
app/Repositories/TransaksiRepository.php
database/migrations/xxxx_xx_xx_xxxxxx_create_transaksis_table.php
resources/views/transaksi.blade.php
tests/Feature/TransaksiTest.php
Additional Options
| Option | Description |
|---|---|
--route |
Automatically add a resource route to routes/web.php. |
--no-test |
Skip generating the Pest test file. |
For example:
php artisan make:strict Transaksi --route
To generate the module without a test:
php artisan make:strict Transaksi --no-test
2. Scan the Architecture
To verify whether your project follows the enforced naming conventions, run:
php artisan strict:scan
The scanner will display a list of files that violate the defined naming standards.
A successful scan indicates that no naming violations were detected.
Enforced Naming Standards
Strict Architecture enforces specific file naming conventions to maintain consistency throughout the project.
PascalCase
The following files must use PascalCase:
- Controllers
- Models
- Services
- Repositories
Examples:
UserController.php
User.php
UserService.php
UserRepository.php
snake_case / lowercase
The following files must use snake_case or lowercase naming:
- Blade view files
- Migration files
Examples:
user-profile.blade.php
create_users_table.php
add_status_to_users_table.php
Git Pre-commit Hook
When you run:
php artisan strict:install-hook
Strict Architecture installs a script into:
.git/hooks/pre-commit
Every time you run:
git commit
the hook will automatically:
-
Run the architecture scanner:
php artisan strict:scan
-
Run the Pest test suite:
./vendor/bin/pest
If either process fails, the commit will be automatically blocked.
This helps prevent architectural violations and failing tests from being committed to the repository.
Example Workflow
A typical development workflow looks like this:
# Generate a new module php artisan make:strict Transaksi --route # Make your changes... # Run the architecture scanner php artisan strict:scan # Run the test suite ./vendor/bin/pest # Commit your changes git add . git commit -m "Add Transaksi module"
If the Git hook is installed, the architecture scan and Pest tests will also run automatically during the commit process.
License
Strict Architecture is open-source software licensed under the MIT License.