You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The README has been streamlined to focus on quick installation and configuration steps, removing detailed middleware and usage documentation. For comprehensive guides and examples, users are now directed to the project's wiki.
A toolkit that turns **Laravel 12** into a lightweight base for distributed microservices.
6
8
7
-
## Overview
9
+
## Quick start
8
10
9
-
This package provides a robust foundation for building Laravel-based microservices, focusing on stateless authentication, authorization, and distributed system best practices. Out of the box, you’ll find:
10
-
11
-
-**JWT Authentication Middleware:**
12
-
Securely validates JWT tokens and hydrates the authenticated user for each request.
13
-
14
-
-**Role & Permission Middleware:**
15
-
Restrict access to routes based on user roles or permissions, with support for both JWT-embedded and dynamically loaded access control.
16
-
17
-
-**LoadAccess Middleware:**
18
-
Optionally fetches the latest roles and permissions for the authenticated user from a centralized permission service or API Gateway.
19
-
20
-
-**Gateway Guard:**
21
-
Session-based guard that refreshes JWT tokens via the API Gateway and loads permissions automatically.
22
-
23
-
-**Correlation ID Middleware:**
24
-
Automatically generates or propagates a unique correlation ID for every request, enabling end-to-end tracing across distributed systems.
25
-
26
-
-**Configurable Middleware Aliases & Groups:**
27
-
Easily enable, disable, or rename middleware via configuration, and use convenient groups like `microservice.auth` group for full authentication and authorization in one step.
28
-
29
-
-**HTTP Client Macros:**
30
-
Pre-configured HTTP clients for communicating with your API Gateway or other services. They automatically forward the current correlation ID header and propagate gateway errors to the caller.
31
-
32
-
-**Ready-to-publish Configuration:**
33
-
All settings are customizable via a single config file, making it easy to adapt the package to your environment.
34
-
35
-
This toolkit is designed to be flexible, extensible, and easy to integrate into any Laravel microservice architecture.
> To install the dev branch, append `:dev-main` to the package name.
49
-
50
17
### Publish Configuration
51
18
52
19
After installation, publish the configuration file to your Laravel project:
@@ -60,289 +27,16 @@ You can now customize the settings to match your microservice environment.
60
27
61
28
---
62
29
63
-
## Middlewares
64
-
65
-
This package provides a set of middleware designed to enhance your Laravel microservice with common cross-cutting concerns. You can enable, disable or rename each middleware by editing the `middleware_aliases` section in `config/microservice.php`.
66
-
67
-
```php
68
-
// config/microservice.php
69
-
70
-
'middleware_aliases' => [
71
-
'jwt_auth' => 'jwt.auth', // alias for JWT Authentication middleware
72
-
'correlation_id' => 'correlation.id', // alias for Correlation ID middleware
73
-
'disabled_mw' => '', // empty string disables a middleware
74
-
],
75
-
```
76
-
77
-
### JWT Authentication
78
-
79
-
**Alias**: the string you assign to `jwt_auth` in `middleware_aliases`, e.g. `jwt.auth`.
Validates the presence and integrity of a JSON Web Token (JWT) in the `Authorization` header of incoming requests. On success, the decoded payload is attached to the request for downstream use; on failure, a 401 response is returned.
Loads the authenticated user's roles and permissions, typically from a centralized permission service (such as an API Gateway or dedicated permissions microservice).
126
-
By default, the `ValidateJwt` middleware will automatically load `roles` and `permissions` from the JWT payload if they are present.
127
-
However, if you have a centralized permission service, you can use `LoadAccess` to fetch and hydrate the latest roles and permissions for the user, ensuring up-to-date authorization data.
Generates or propagates a unique `X-Correlation-ID` header for each request, enabling end-to-end tracing across distributed systems. If the incoming request already has the header, it will be reused; otherwise, a new UUID is generated. The header is added to both the request and the response.
203
-
204
-
#### Configuration (`config/microservice.php`)
205
-
206
-
```php
207
-
'correlation' => [
208
-
'header' => 'X-Correlation-ID',
209
-
'length' => 36,
210
-
],
211
-
```
212
-
213
-
#### Usage
214
-
215
-
Automatically prepended to the `api` middleware group (when enabled), or apply explicitly:
You no longer need to stack `jwt.auth` + `load.access` manually—just use `microservice.auth` wherever you need full auth + authorization.
252
-
253
-
---
254
-
255
-
### Authorization
256
-
257
-
This package hooks into Laravel's Gate so Blade directives work with your roles and permissions. Any ability is treated as a permission by default; prefix an ability with `role:` or `permission:` to be explicit.
Use `Http::apiGateway()` and its related macros for service-to-service calls. Each macro forwards the current correlation ID header when available.
305
-
306
-
If the gateway responds with an error (for example, a `503`), an `ApiGatewayException` is thrown and automatically returned to the client with the same status code.
307
-
308
-
---
309
-
310
-
## Public Release and Roadmap
311
-
312
-
This toolkit is still maturing. Upcoming plans include:
313
-
314
-
- Strengthening middleware modules
315
-
- Increasing test coverage
316
-
- Publishing more integration examples
317
-
318
-
A stable **v1.0** is on the horizon. Please share feedback or ideas in the issue tracker!
319
-
320
-
---
321
-
322
-
## Extending the Core
323
-
324
-
This package keeps its dependencies minimal so you can tailor each microservice as needed. Consider these optional packages when expanding your stack:
325
-
326
-
-**RabbitMQ Messaging** – Integrate [iamfarhad/LaravelRabbitMQ](https://github.com/iamfarhad/LaravelRabbitMQ) if you rely on RabbitMQ for queues. Install the package via Composer and update your queue connection to `rabbitmq`.
327
-
-**Prometheus Metrics** – Expose service metrics with [spatie/laravel-prometheus](https://github.com/spatie/laravel-prometheus). Publish the configuration and register the `/metrics` route in your service.
328
-
-**Additional Tools** – Depending on your requirements, you might add packages for service discovery, distributed tracing, or improved concurrency (e.g., Laravel Octane or Horizon).
329
-
330
-
These extensions remain completely optional, allowing you to keep the core lightweight while adding features specific to your environment.
331
-
332
38
---
333
39
334
40
## Documentation
335
41
336
-
Additional guides and examples are available in the [wiki](https://github.com/KroderDev/laravel-microservice-core/wiki).
337
-
338
-
---
339
-
340
-
## Contributing
341
-
342
-
Community contributions are encouraged! To get started:
343
-
344
-
1. Fork the repository and create a feature branch.
345
-
2. Commit your changes with tests when possible.
346
-
3. Open a pull request describing your work.
347
-
348
-
Feel free to start a discussion or issue if you have questions about the roadmap or want to propose a feature.
42
+
See the [wiki](https://github.com/KroderDev/laravel-microservice-core/wiki) for full documentation.
0 commit comments