Request Lifecycle
Every request to a Wordless site follows a predictable, transparent flow. Understanding this lifecycle helps you extend the system and debug issues.
The Complete Flow
Browser Request
↓
/public/index.php (entry point)
↓
bootstrap/app.php (initialize container and services)
↓
Application::handle($request)
↓
ErrorMiddleware (catches exceptions)
↓
CacheMiddleware (checks for cached responses)
↓
Router::resolve($path)
↓
Explicit Routes? (sitemap.xml, custom routes)
↓ No
File-Based Routes (ContentController)
↓
ContentRepository::find($path)
↓
File exists?
↓ Yes
PhpFileParser::parseFile() (extract metadata, render body)
↓
ContentController::handle() (merge with layout)
↓
Renderer::render('page', $data)
↓
Response sent to browser
Step-by-Step Breakdown
1. Entry Point
/public/index.php is the only file directly accessible via HTTP.
It bootstraps the application and handles the request.
<?php
$app = require __DIR__ . '/../bootstrap/app.php';
$request = Request::fromGlobals();
$response = $app->handle($request);
$response->send();
2. Bootstrap
bootstrap/app.php initializes all services:
- Load configuration
- Register services in the container
- Boot plugins
- Register named routes
3. Request Parsing
The Request object extracts:
- HTTP method (GET, POST, etc.)
- Path (/about, /blog/hello-world)
- Query parameters
- Headers
4. Middleware Stack
Middleware wraps the main request handling:
ErrorMiddleware
└─ CacheMiddleware
└─ Router
Each middleware can inspect, modify, or intercept requests and responses.
5. Routing
The router checks for explicit routes first (e.g., /sitemap.xml),
then falls back to file-based routing for regular pages.
6. Content Loading
The repository finds the matching file, extracts metadata, and renders the content body.
7. Rendering
If the content template declares a layout, the body is wrapped in that layout.
8. Response
The final HTML is sent back to the browser with appropriate headers and status code.
Error Handling
If any step fails:
- 404: Content file not found
- 500: Exception thrown during rendering
- The ErrorMiddleware catches the exception
- An error template is rendered with the appropriate status code
Caching
The CacheMiddleware checks if a response is cached and returns it directly, bypassing the expensive content loading and rendering steps.
Key Principles
- Transparency: No hidden routing or magic behavior
- Predictability: The flow is always the same
- Extensibility: Middleware and hooks allow customization
- Performance: Middleware like caching can optimize before expensive operations