LeanPHP is a small PHP 8.2 framework for JSON APIs. It keeps the moving parts visible: a router, request and response objects, middleware, validation, JWT auth, rate limiting, logging, and a thin PDO wrapper.
The project is intentionally plain. There is no service container, ORM, template layer, or command bus. If you need those, Laravel or Symfony will serve you better. If you want a compact API skeleton that is easy to read and change, this is the point of the project.
- HTTP request and response classes
- RFC 7807 problem responses
- Route parameters, constraints, groups, HEAD handling, and CORS preflight handling
- Middleware for errors, request IDs, CORS, JSON body checks, bearer auth, scopes, rate limits, and ETags
- JWT issuing and verification with key IDs
- Input validation with common rules
- PDO helpers for queries and transactions
- File and APCu rate limit stores
- PHPUnit and PHPStan configuration
- PHP 8.2 or newer
- Composer
- PDO SQLite for the demo database
- APCu if you want the APCu rate limit store
composer install
cp .env.example .env
php scripts/seed.phpTo run the local server, use:
php -S localhost:8000 -t public public/router.phpcurl http://localhost:8000/healthcurl -X POST http://localhost:8000/login \
-H "Content-Type: application/json" \
-d '{"email":"[email protected]","password":"secret"}'Use the returned token:
curl http://localhost:8000/v1/users \
-H "Authorization: Bearer YOUR_TOKEN_HERE"composer test
php -d memory_limit=512M vendor/bin/phpstan analysecomposer stan may fail on machines where PHP uses the default 128 MB memory limit. The command above keeps PHPStan on the same config and gives it enough memory.
Generate the route cache before deploying with:
php bin/route_cache.phpClosure routes are skipped because PHP cannot safely cache closures with var_export(). Use controller handlers for routes you want cached.
Start with docs/README.md.
MIT. See LICENSE.