pushery / frontline-api-for-laravel
Puts a Laravel API behind the Frontline API gateway: publishes its routes, tiers and keys as signed sheets, admits only the requests the gateway signed, and counts what the gateways report.
Package info
github.com/pushery/frontline-api-for-laravel
pkg:composer/pushery/frontline-api-for-laravel
Requires
- php: ^8.4
- ext-json: *
- ext-mbstring: *
- ext-sodium: *
- laravel/framework: ^13.0
- symfony/console: ^7.0 || ^8.0
- symfony/http-kernel: ^7.0 || ^8.0
Requires (Dev)
- dedoc/scramble: ^0.13.48
- fakerphp/faker: ^1.24
- larastan/larastan: ^3.9.3
- laravel/ai: ^1.4.2
- laravel/boost: ^2.10.4
- laravel/mcp: ^1.3.0
- laravel/pao: ^1.1
- laravel/pint: ^1.0
- opis/json-schema: ^2.6.2
- orchestra/testbench: ^11.2
- orchestra/testbench-core: ^11.6
- pestphp/pest: ^5.3.1
- pestphp/pest-plugin-agent: ^5.0
- pestphp/pest-plugin-browser: ^5.2
- pestphp/pest-plugin-evals: ^5.1
- pestphp/pest-plugin-laravel: ^5.0
- pestphp/pest-plugin-phpstan: ^5.0
- pestphp/pest-plugin-type-coverage: ^5.1.1
- phpstan/phpstan: ^2.3.5
- phpstan/phpstan-deprecation-rules: ^2.0.5
- predis/predis: ^3.7.1
- pushery/sqlens-for-laravel: ^0.38.0
- rector/rector: ^2.7.0
- spaze/phpstan-disallowed-calls: ^4.12
- symfony/yaml: ^7.4.17 || ^8.1.5
Suggests
- dedoc/scramble: Describes the gateway's route declarations in the OpenAPI document Scramble generates
Provides
None
Conflicts
None
Replaces
None
README
Frontline API for Laravel
Puts a Laravel API behind the Frontline API gateway: publishes its routes, tiers and keys as signed sheets, admits only the requests the gateway signed, and counts what the gateways report.
Documentation
Full documentation at docs.pushery.com/frontline-api-for-laravel. This README is the quick start; the guides and the configuration reference live there.
Requirements
- A Frontline API gateway in front of the API host. The gateway is a separate service and not yet publicly available.
- PHP 8.4+ (tested on 8.4.27, 8.5.x and 8.6.x)
- Laravel 13+, as the full
laravel/frameworkrather than separateilluminate/*components - The
sodiumextension (ext-sodium), which signs the sheets for the gateway with Ed25519 - Redis 6.2 or later, or Valkey, for the sheets the gateways read and the counts they write
Tested on PostgreSQL 18.7 and MySQL 8.4.13, the databases Laravel Cloud runs (serverless Postgres and MySQL 8.4 LTS). The fast suite runs on SQLite. The store's commands run against Redis 6.2, the oldest version the package supports, through both PhpRedis and Predis.
Tested on the floor of the declared PHP range, because a >= promise is only proven
by running on the boundary, and on the minor versions above it, so the range above the
floor is exercised here rather than first by a consumer. The patch named for the floor is
the one the tests run on, and a newer patch of that minor is covered by the same promise.
Installation
composer require pushery/frontline-api-for-laravel
The service provider is registered automatically through package discovery.
Configuration
Publish the configuration file:
php artisan vendor:publish --tag=frontline-api-config
This writes config/frontline-api.php, where every option is documented inline.
php artisan migrate runs the package's migrations from the package as they are. To keep
them in your application instead, decide before your first php artisan migrate: call
\Pushery\FrontlineApi\FrontlineApiServiceProvider::ignoreMigrations(tablesExist: true) in the register method
of your AppServiceProvider first, then publish and run them:
php artisan vendor:publish --tag=frontline-api-migrations php artisan migrate
Without that call both copies stay registered, and with Laravel's default configuration the
published one runs under a new name and fails on a table that already exists. The same goes
for --tag=frontline-api, which publishes every resource at once, the migrations included.
tablesExist: true tells the package that your application migrates its tables, so its schedule
stays: the sheets and the heartbeat go out every minute, and the meter is counted and pruned.
ignoreMigrations() alone declines the tables and takes all of that off the schedule.
Publish the migrations once. The release notes name each migration a later release adds: copy
that file from vendor/pushery/frontline-api-for-laravel/database/migrations into
database/migrations, renamed to start with today's date so it runs after the copies you have,
then run php artisan migrate. Publishing the tag again writes every migration a second time under a
new date, and migrate runs each copy as a new migration over the tables the original
created. If php artisan migrate has already run them from the package, copy the files from
that directory under their own names instead of publishing them: the migrations table knows
them by those names, so migrate leaves them alone.
To change the package's translations, publish them and edit the copies:
php artisan vendor:publish --tag=frontline-api-lang
The translations land in lang/vendor/frontline-api, where Laravel reads them before the
package's own.
Usage
The gateway forwards the requests of your API host to Laravel and reads its rules from sheets this
package publishes: the routes with their declarations, the tiers with their limits, and the keys
with their abilities. In config/frontline-api.php, name the product, its environment and the API
host, the Redis connection the gateways read and the disk for the copies of the sheets, then make
the signing key:
php artisan frontline:signing-key 2026-11
Name the classes your keys and tiers come from in the same file. The package resolves each from the container:
'sources' => [ 'keys' => \App\Frontline\ApiKeys::class, 'tiers' => \App\Frontline\PlanTiers::class, ],
Register Laravel's own limits behind the gateway in the boot method of a service provider, with
the way to tell the tier of a request's caller, and declare the routes of the API host:
use Illuminate\Http\Request; use Pushery\FrontlineApi\Limits\SecondLine; SecondLine::register(fn (Request $request): ?string => $request->user()?->tier);
use Illuminate\Support\Facades\Route; use Pushery\FrontlineApi\Http\Middleware\VerifyFrontlineSignature; Route::domain('api.example.com') ->middleware([VerifyFrontlineSignature::class, 'throttle:frontline']) ->frontline(limitClass: 'standard') ->group(base_path('routes/api.php'));
Run the scheduler and a queue worker: the package publishes every sheet each minute and counts what
the gateways report, and php artisan frontline:status shows the state of both. The
documentation covers the key and tier
sources, the route declaration, the commands, the health checks and changing the signing key.
Testing
The test suite is not part of the published package: the tests and their PHPUnit
configuration stay in the development repository, so a clone of this repository has no
composer test. CONTRIBUTING.md says how a change is tested on its way in.
Security
Please review the security policy and report vulnerabilities privately rather than opening a public issue.
Built by PUSHERY
This package is built and maintained by PUSHERY — a Berlin-based studio building Laravel applications, SaaS products, and open-source tools.
Building a Laravel UI? WireKit is PUSHERY's open-source Livewire component kit. Browse the rest of our work at pushery.com.
License
The MIT License (MIT). See LICENSE for details.