Skip to content

High-performance multi-driver rate limiting library (Redis, MongoDB, MySQL) with exponential backoff, global IP limits, and PSR middleware integration for enterprise-grade API protection

License

Notifications You must be signed in to change notification settings

Maatify/rate-limiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

79 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Maatify Rate Limiter

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

About

High-performance multi-driver rate limiting library (Redis, MongoDB, MySQL) with exponential backoff, global IP limits, and PSR middleware integration for enterprise-grade API protection

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages