Relayer Documentation
A convention-first PHP full-stack framework: routing, APIs, authentication, caching and the database wired into a single boot entry, Next.js App Router-style.
Getting Started
Tutorial
Routing
- Routing & PagesFile conventions under src/Pages, the two ways to write a page, dynamic segments, and layouts.
- API RoutesMethod-specific handlers via route.php. Each handler returns a Response.
- Middleware & CORSCross-route common processing via src/Pages/middleware.php, and how to use the built-in CORS.
Features
- Server ActionsCSRF-protected form handlers. How to register them in function style and class style.
- Defer ComponentsLazily fetch only the per-user components while the page body stays on the CDN cache.
- React IslandsEmbed client React components inside server-rendered HTML.
- Per-Page ScriptsDeclare external scripts specific to a page or layout with $ctx->js() / PageComponent::addJs() / LayoutComponent::addJs().
- Services & DIService registration via services.yaml and AppConfigurator, autowiring, and factories.
- AuthenticationUserProvider / password authentication, role protection, and Bearer token authentication for Firebase/Cognito.
- ValidationZod-style schema validator. Types, constraints, per-field errors, and a practical flow with function-style pages plus server actions.
- HTTP Caching & ETagCache-Control, ETag, conditional GET, and 304 via #[Cache] / $ctx->cache(), plus EtagStore (static/dynamic ETags).
- HTTP ClientFetching external APIs with HttpClient. DI binding, HttpResponse, 4xx/5xx are not exceptions, request-scoped memoization.
- DatabaseAutowiring of the PDO wrapper Database via DATABASE_DSN, and request-scoped caching.
- LoggerPSR-3 logger backed by Monolog. LoggerInterface DI binding, LOG_LEVEL/LOG_FILE, {placeholder} interpolation, dev profiler integration and redaction.
- Internationalization (i18n)Zero-dependency translator, file-based catalogs, automatic locale resolution, and localization of framework-standard messages. Opt-in via configuration.
- Tehilim integrationWire the schema-first DB toolkit polidog/tehilim into Relayer and put its queries on the profiler timeline via the profiler hook.
Development
Operations
- CLI Commandsvendor/bin/relayer (init / upgrade / routes / routes:compile / container:compile / profiler:clear) and usephp compile.
- Environment Variables & .env CascadeThe .env / .env.local / .env.{APP_ENV} priority via symfony/dotenv, and a list of the available environment variables.
- Deployment (Dockerfile)How to build a Dockerfile for a Relayer app — production build, PSX precompilation, route precompilation, DI container precompilation, and the front controller. FrankenPHP / nginx + php-fpm examples.
- CDN CachingKey points for putting a Relayer app behind a CDN such as Cloudflare — edge caching via s-maxage, the Cache Rule that puts HTML on the edge, the trap of a session cookie causing a full BYPASS and how to avoid it, plus verification and purging.