Skip to content

KroderDev/laravel-microservice-core

Repository files navigation

Laravel Microservice Core

Packagist Version Downloads License

A toolkit that turns Laravel 12 into a lightweight base for distributed microservices.

Key Features

This package packages common microservice concerns so you can focus on your service logic:

  • JWT authentication middleware and a session guard for frontend interactions
  • Correlation ID propagation for tracing requests across services
  • Role and permission gates with convenient helpers
  • HTTP client macros and a configurable API Gateway client
  • Base model and query builder class for working with remote resources through the gateway
  • Optional health check endpoint out of the box

Quick start

Install the package via Composer:

composer require kroderdev/laravel-microservice-core

Publish the configuration to customize defaults:

php artisan vendor:publish --provider="Kroderdev\LaravelMicroserviceCore\Providers\MicroserviceServiceProvider"

Basic usage

Configure your API gateway URL and JWT settings in config/microservice.php. Then extend the base model to interact with remote resources:

Scaffold your remote model via the new Artisan command:

php artisan make:model RemoteUser --remote

This will generate a RemoteUser model that extends the core Model class with remote-resource support.

use Kroderdev\LaravelMicroserviceCore\Models\Model;

class RemoteUser extends Model
{
    protected static string $endpoint = '/users';
    protected $fillable = ['id', 'name'];
}

$users = RemoteUser::all();

Add the provided middleware to your routes to validate JWTs and propagate correlation IDs:

Route::middleware(['jwt.auth'])->group(function () {
    Route::get('/profile', fn () => 'ok');
});

Documentation

Full documentation lives in the project wiki.

Contributing

Contributions welcome! See CONTRIBUTING.md for guidelines.

License

This project is open-sourced software licensed under the MIT license.