PHPackages                             mrthito/microservice - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. mrthito/microservice

ActiveLibrary[Caching](/categories/caching)

mrthito/microservice
====================

Lightweight PHP microservice foundation: env, logging, Redis queue, signed events, and HTTP health checks.

1.0.0(1mo ago)41MITPHPPHP ^8.4CI passing

Since May 31Pushed 1mo agoCompare

[ Source](https://github.com/mrthito/microservice)[ Packagist](https://packagist.org/packages/mrthito/microservice)[ Docs](https://github.com/mrthito/microservice)[ RSS](/packages/mrthito-microservice/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

mrthito/microservice
====================

[](#mrthitomicroservice)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9d94fa82e5a57a5ef07fb07cc3fa1532a1a24f6f43cf102f39d85f5e107fa0ab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d72746869746f2f6d6963726f736572766963652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mrthito/microservice)[![Total Downloads](https://camo.githubusercontent.com/a8ceb4d098381b2eeffa2b70166a111917a724182497df33346b45144e69063f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d72746869746f2f6d6963726f736572766963652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mrthito/microservice)[![License](https://camo.githubusercontent.com/7b8397c33dea842a9e6e2281eb0f9d342d206284c33192e82e90a835be500f71/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d72746869746f2f6d6963726f736572766963652e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Lightweight PHP foundation for event-driven microservices that share a Laravel database and Redis queue — with zero framework dependencies.

Requirements
------------

[](#requirements)

- PHP 8.4+
- Extensions: `json`, `openssl`, `pdo`

Installation
------------

[](#installation)

```
composer require mrthito/microservice
```

Features
--------

[](#features)

- `.env` loading without external dependencies
- Secure stdout logging with sensitive field redaction
- PDO MySQL connection helper
- Laravel `APP_KEY` payload decryption
- Minimal Redis RESP client (BRPOP)
- HMAC-SHA256 signed queue event verification
- Minimal HTTP router with **built-in `/health` route by default**
- `Http\Server` for one-line HTTP entrypoints
- `boot.json` service manifest reader

Quick start
-----------

[](#quick-start)

### 1. Implement service config

[](#1-implement-service-config)

```
use MrThito\MicroService\Contracts\MicroServiceConfig;
use MrThito\MicroService\Support\Env;
use MrThito\MicroService\Support\Manifest;

final readonly class Config implements MicroServiceConfig
{
    public static function fromEnvironment(string $basePath): self
    {
        $manifest = Manifest::load($basePath);

        return new self(
            serviceName: $manifest['name'],
            // ... map Env::getString(), Env::getInt(), etc.
        );
    }

    // Implement MicroServiceConfig methods...
}
```

### 2. Wire the queue worker

[](#2-wire-the-queue-worker)

```
use MrThito\MicroService\Bootstrap;
use MrThito\MicroService\Queue\RedisQueueListener;
use MrThito\MicroService\Security\SignedEventVerifier;
use MrThito\MicroService\Support\BaseConfigValidator;
use MrThito\MicroService\Support\Logger;

$config = Bootstrap::boot('/path/to/service', fn () => Config::fromEnvironment('/path/to/service'));
BaseConfigValidator::validate($config);

$logger = new Logger($config->logLevel());

$verifier = new SignedEventVerifier(
    expectedEvent: 'order.created',
    signingSecret: $config->signingSecret(),
    eventMaxAgeSeconds: $config->eventMaxAgeSeconds(),
    payloadValidator: static fn (array $payload): array => [
        'order_id' => (int) $payload['order_id'],
    ],
);

$listener = new RedisQueueListener(
    redisConfig: $config->redis(),
    verifier: $verifier,
    processor: $orderProcessor,
    logger: $logger,
);

$listener->listen();
```

### 3. Expose the HTTP server

[](#3-expose-the-http-server)

Health routes (`/health` and `/`) are registered automatically.

```
use MrThito\MicroService\Http\Server;

$config = Bootstrap::boot('/path/to/service', fn () => Config::fromEnvironment('/path/to/service'));

(new Server($config))->run();
```

Add custom routes before serving:

```
$server = new Server($config);
$server->router()->get('/metrics', static fn (): array => ['uptime' => time()]);

$server->run();
```

Service manifest
----------------

[](#service-manifest)

Each microservice should include a `boot.json` file in its project root:

```
{
    "name": "my_microservice",
    "license": "MIT",
    "scopes": ["orders.process"],
    "health": "/health"
}
```

Load it with `Manifest::load($basePath)`. The `health` path is exposed via `MicroServiceConfig::healthPath()` and used by the default router.

Security
--------

[](#security)

- Sign queue payloads with `EventSigner::sign($payload, $secret)` before publishing.
- Verify events with `SignedEventVerifier` before processing.
- Set `REQUIRE_REDIS_PASSWORD=true` in production when Redis uses AUTH.
- Use signing secrets of at least 32 characters.

Testing
-------

[](#testing)

```
composer test
```

Publishing to Packagist
-----------------------

[](#publishing-to-packagist)

1. Push this repository to GitHub (for example `github.com/mrthito/microservice`).
2. Create a release tag: `git tag v1.0.0 && git push origin v1.0.0`.
3. Submit the repository URL at [packagist.org](https://packagist.org/packages/submit).
4. Enable the Packagist GitHub hook for automatic updates on new tags.

License
-------

[](#license)

The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance91

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

54d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/49310993?v=4)[Prashant Rijal](/maintainers/mrthito)[@mrthito](https://github.com/mrthito)

---

Top Contributors

[![mrthito](https://avatars.githubusercontent.com/u/49310993?v=4)](https://github.com/mrthito "mrthito (5 commits)")

---

Tags

phplaravelpdoevent-drivenredisqueuehmacMicroservice

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mrthito-microservice/health.svg)

```
[![Health](https://phpackages.com/badges/mrthito-microservice/health.svg)](https://phpackages.com/packages/mrthito-microservice)
```

###  Alternatives

[yangusik/laravel-balanced-queue

Laravel queue management with load balancing between partitions (user groups)

8514.8k](/packages/yangusik-laravel-balanced-queue)[kevindees/laravel-redis-queue

Redis queue managment for laravel.

1634.1k](/packages/kevindees-laravel-redis-queue)[eftec/cacheone

A Cache library with minimum dependency

103.5k4](/packages/eftec-cacheone)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
