|
1 | | -# laravel-microservice-core |
| 1 | +# Laravel Microservice Core |
2 | 2 |
|
3 | 3 | [](https://packagist.org/packages/kroderdev/laravel-microservice-core) |
4 | 4 | [](https://packagist.org/packages/kroderdev/laravel-microservice-core) |
5 | 5 | [](LICENSE) |
6 | 6 |
|
7 | | -A toolkit that turns **Laravel 12** into a lightweight base for distributed microservices. |
| 7 | +A toolkit that turns **Laravel 12** into a lightweight base for distributed microservices. |
8 | 8 |
|
9 | | -## Features |
| 9 | +## Key Features |
10 | 10 |
|
11 | | -- Middleware for JWT validation, correlation IDs and permission checks |
12 | | -- Authorization helpers using roles and permissions |
13 | | -- HTTP client macros and an API Gateway client |
14 | | -- Session guard and controllers for frontend authentication |
15 | | -- Health check endpoint at `/api/health` |
16 | | -- Base model for API gateway resources |
| 11 | +This package packages common microservice concerns so you can focus on your service logic: |
17 | 12 |
|
18 | | ---- |
19 | | - |
20 | | -## Documentation |
21 | | - |
22 | | -See the [wiki](https://github.com/KroderDev/laravel-microservice-core/wiki) for full documentation. |
23 | | - |
24 | | ---- |
| 13 | +- JWT authentication middleware and a session guard for frontend interactions |
| 14 | +- Correlation ID propagation for tracing requests across services |
| 15 | +- Role and permission gates with convenient helpers |
| 16 | +- HTTP client macros and a configurable API Gateway client |
| 17 | +- Base model and query builder class for working with remote resources through the gateway |
| 18 | +- Optional health check endpoint out of the box |
25 | 19 |
|
26 | 20 | ## Quick start |
27 | 21 |
|
28 | | -Install via Composer: |
| 22 | +Install the package via Composer: |
29 | 23 |
|
30 | 24 | ```bash |
31 | 25 | composer require kroderdev/laravel-microservice-core |
32 | 26 | ``` |
33 | 27 |
|
34 | | -### Publish Configuration |
35 | | - |
36 | | -After installation, publish the configuration file to your Laravel project: |
| 28 | +Publish the configuration to customize defaults: |
37 | 29 |
|
38 | 30 | ```bash |
39 | 31 | php artisan vendor:publish --provider="Kroderdev\LaravelMicroserviceCore\Providers\MicroserviceServiceProvider" |
40 | 32 | ``` |
41 | 33 |
|
42 | | -You can now customize the settings to match your microservice environment. |
| 34 | +## Basic usage |
| 35 | + |
| 36 | +Configure your API gateway URL and JWT settings in `config/microservice.php`. |
| 37 | +Then extend the base model to interact with remote resources: |
| 38 | + |
| 39 | +Scaffold your remote model via the new Artisan command: |
| 40 | + |
| 41 | +```bash |
| 42 | +php artisan make:model RemoteUser --remote |
| 43 | +``` |
| 44 | + |
| 45 | +This will generate a RemoteUser model that extends the core Model class with remote-resource support. |
| 46 | + |
| 47 | +```php |
| 48 | +use Kroderdev\\LaravelMicroserviceCore\\Models\\Model; |
| 49 | + |
| 50 | +class RemoteUser extends Model |
| 51 | +{ |
| 52 | + protected static string $endpoint = '/users'; |
| 53 | + protected $fillable = ['id', 'name']; |
| 54 | +} |
| 55 | + |
| 56 | +$users = RemoteUser::all(); |
| 57 | +``` |
| 58 | + |
| 59 | +Add the provided middleware to your routes to validate JWTs and propagate correlation IDs: |
| 60 | + |
| 61 | +```php |
| 62 | +Route::middleware(['jwt.auth'])->group(function () { |
| 63 | + Route::get('/profile', fn () => 'ok'); |
| 64 | +}); |
| 65 | +``` |
| 66 | + |
| 67 | +## Documentation |
| 68 | + |
| 69 | +Full documentation lives in the [project wiki](https://github.com/KroderDev/laravel-microservice-core/wiki). |
| 70 | + |
| 71 | +## Contributing |
| 72 | + |
| 73 | +Contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. |
| 74 | + |
| 75 | +## License |
| 76 | + |
| 77 | +This project is open-sourced software licensed under the [MIT license](LICENSE). |
0 commit comments