Documentation · Chapter 02

Read and extend
a real project.

The final exercise verifies that you can follow the architecture before writing a new feature.

No prior technical vocabulary is required. Every new word is explained before it is used.

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.

FINAL WORKSHOP

Add an About page to a classic application.

  1. Create a project named architecture-lab.
  2. Inspect phpaml.json, public/, src/, and runtime/.
  3. Create an AboutController.
  4. Add GET /about to src/routes/WebApp.php.
  5. Return a simple HTML response, then verify it in the browser.

GUIDED SOLUTION

Build in request order.

phpaml — zsh
aml create architecture-lab
cd architecture-lab
aml make:controller About
aml serve

The 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.

phpaml — zsh
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.

  1. 1
    Prove startup

    The home page should still respond before any change.

  2. 2
    Prove the route

    A disappearing 404 confirms that /about is now recognized.

  3. 3
    Prove the action

    Very simple content confirms the controller is called.

  4. 4
    Improve afterward

    Add presentation and data only after the minimal journey works.

If the page does not work, check in this order.

1
Is the server running?

The terminal should still show that PHPAML is listening on a local address.

2
Are you using the correct address?

Check the port and /about path in the browser.

3
Is the route declared?

A 404 often means the address is not connected to the controller.

4
Do the class and method exist?

The AboutController name and index method must exactly match the route.

5
What does the detailed error say?

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.