Method before code.
Do not begin by creating files at random. First express the request as a journey: the browser requests GET /about; a route must recognize that address; a controller must produce the response; the browser must finally receive status 200 and HTML. That sentence becomes both your implementation and diagnostic plan.
Add an About page to a classic application.
- Create a project named architecture-lab.
- Inspect phpaml.json, public/, src/, and runtime/.
- Create an AboutController.
- Add GET /about to src/routes/WebApp.php.
- Return a simple HTML response, then verify it in the browser.
GUIDED SOLUTION
Build in request order.
aml create architecture-lab
cd architecture-lab
aml make:controller About
aml serveThe command creates the controller under src/controllers. Then add the route to src/routes/WebApp.php and connect it to AboutController::index. The route must be loaded before the browser can reach the action.
public function index(Request $request): Response
{
return Response::html('<main><h1>About</h1><p>My first PHPAML page.</p></main>');
}Open /about. A 200 response proves that entry point, router, controller, and response work together. A 404 generally means the route is not registered; a 500 means processing started and then failed.
Work through small proofs.
- 1Prove startup
The home page should still respond before any change.
- 2Prove the route
A disappearing 404 confirms that /about is now recognized.
- 3Prove the action
Very simple content confirms the controller is called.
- 4Improve afterward
Add presentation and data only after the minimal journey works.
If the page does not work, check in this order.
The terminal should still show that PHPAML is listening on a local address.
Check the port and /about path in the browser.
A 404 often means the address is not connected to the controller.
The AboutController name and index method must exactly match the route.
In development, the error screen and terminal identify the file and line to inspect.
Knowledge check
CHECK YOUR UNDERSTANDING
Why is the controller under src/ rather than public/?
Show the answer
Because the controller is internal code. Only public/index.php should be directly exposed to the Web.
CHECK YOUR UNDERSTANDING
Why is a route required?
Show the answer
It connects an HTTP method and path to the action that handles them.
SUMMARY
What to remember
- You can follow a complete request.
- You can distinguish public, application, and rebuildable code.
- You can distribute model, view, and controller responsibilities.
- You can now approach migration of an older project.