maatify/rate-limiter

Flexible PSR-15 rate limiter supporting Redis, MongoDB, and MySQL via real and fake drivers. Provides multi-strategy algorithms, burst control, sliding window, token bucket, and integration with Maatify Data Repository.

Installs: 157

Dependents: 1

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 1

Open Issues: 0

pkg:composer/maatify/rate-limiter

dev-main 2025-12-08 07:11 UTC

This package is auto-updated.

Last update: 2025-12-08 07:11:17 UTC


README

PSR-compliant distributed rate limiting engine supporting Redis, MongoDB, and MySQL with adaptive exponential backoff.

Maatify.dev

Version PHP PHP Version

Build

Monthly Downloads Total Downloads

Stars License Status Code Quality

PHPStan Coverage

Changelog Security

๐Ÿš€ Overview

Maatify Rate Limiter is a fully decoupled, PSR-compliant rate-limiting engine designed for:

  • Native PHP
  • Slim Framework
  • Laravel Middleware
  • Custom API Gateways

It provides distributed rate-limiting with adaptive exponential backoff, unified across:

  • Redis
  • MongoDB
  • MySQL

Why this library?

  • Zero storage lock-in
  • Unified attempt/status/reset API
  • Global per-IP rate limit
  • Adaptive Exponential Backoff (2โฟ)
  • Full PSR-7 / PSR-15 middleware compatibility
  • PHPStan Level Max ready

โœ… Supported Drivers

Backend Driver Type Use Case
Redis Real Driver High-performance in-memory limits
MongoDB Real Driver Distributed analytics
MySQL Real Driver Persistent audit & compliance

๐Ÿ“ฆ Installation

composer require maatify/rate-limiter

โšก Quick Usage

use Maatify\RateLimiter\Resolver\RateLimiterResolver;
use Maatify\RateLimiter\Enums\RateLimitActionEnum;
use Maatify\RateLimiter\Enums\PlatformEnum;

$resolver = new RateLimiterResolver(['driver' => 'redis']);
$limiter  = $resolver->resolve();

$status = $limiter->attempt(
    '127.0.0.1',
    RateLimitActionEnum::LOGIN,
    PlatformEnum::WEB
);

echo $status->remaining;

๐Ÿ“˜ Full usage examples (Native, Slim, Laravel, API, Enums, Backoff): โžก๏ธ examples/Examples.md

๐Ÿงฉ Key Features

  • Unified API: attempt(), status(), reset()
  • Global Per-IP Limit
  • Adaptive Exponential Backoff
  • DTO-based Response Model
  • PSR-7 / PSR-15 Middleware Ready
  • Custom Enum Contracts
  • Driver Resolver
  • Strict Validation & Type Safety
  • PHPStan Level Max

๐Ÿ“„ Documentation

๐Ÿ“š Development History & Phase Details
  • Phase 1 โ€“ Environment Setup
  • Phase 2 โ€“ Core Architecture
  • Phase 3 โ€“ Storage Drivers
  • Phase 3.1 โ€“ Enum Contracts Refactor
  • Phase 4 โ€“ Resolver & Middleware
  • Phase 4.1 โ€“ Continuous Integration
  • Phase 5 โ€“ Exponential Backoff & Global Rate Limit

๐Ÿงฑ Dependencies Overview

maatify/rate-limiter relies on PSR standards and selected open-source libraries.

๐Ÿ”Œ Direct Open-Source Dependencies

Library Purpose
psr/http-message HTTP message interfaces
psr/http-server-middleware PSR-15 middleware
psr/http-server-handler Request handler
redis / predis Redis driver
mongodb/mongodb MongoDB driver
phpunit/phpunit Testing
phpstan/phpstan Static analysis

๐Ÿงช Testing

composer test

Runs:

  • Driver consistency tests
  • Resolver tests
  • Middleware header tests
  • Backoff & global limit tests
  • Coverage reporting

๐Ÿชช License

MIT License ยฉ Maatify.dev โ€” Free to use, modify, and distribute with attribution.

๐Ÿ‘ค Author

Engineered by Mohamed Abdulalim (@megyptm)
Backend Lead & Technical Architect โ€” https://www.maatify.dev

๐Ÿค Contributors

Special thanks to the Maatify.dev engineering team and all open-source contributors. Your efforts help make this library stable, secure, and production-ready.

Before opening a Pull Request, please read:

Built with โค๏ธ by Maatify.dev โ€” Unified Ecosystem for Modern PHP Libraries