User Tools

Site Tools


z_appendix_101:php_entry_point_for_the_ai_era

22. A Simple Front Controller — The Quiet Coordinator

— the small place where everything comes together

The Entry Point.

Once we have:

…we need one last piece:

A quiet coordinator that ties the whole request cycle together.

This is the
front controller.

Just a single entry point
where our application begins
.


1. What a Front Controller Really Is

A front controller is simply:

One file that
receives every request
and decides
what to do next.

In modern PHP, that file is usually
public/index.php.

Its job is small:

  • set up the environment
  • register the error handler
  • create the router
  • register routes
  • dispatch the request

That’s it.

Everything else lives elsewhere.


2. The Smallest Front Controller We Can Write

// public/index.php
 
require __DIR__ . '/../vendor/autoload.php';
 
$errorHandler = new ErrorHandler();
set_exception_handler([$errorHandler, 'handle']);
 
$router = new Router();
 
$router->get('/about', fn() => about());
$router->get('/users/{id}', fn($id) => $userController->show($id));
 
$router->dispatch($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);

This is the entire shape:

  • prepare
  • route
  • dispatch

Everything else is refinement.


3. Why the Front Controller Matters

Without a front controller:

  • routing leaks into random files
  • error handling becomes inconsistent
  • controllers get messy
  • responses become unpredictable
  • the application loses its calm

With a front controller:

  • everything has a place
  • the request cycle becomes readable
  • the application feels intentional
  • AI has a clear structure to follow

This is the quiet center of our application.


4. Giving the Front Controller a Little More Structure

As our application grows, we may add:

  • dependency injection
  • configuration
  • middleware
  • session handling
  • authentication

But the shape stays the same.

The front controller remains the small, steady place where everything begins.


5. Why This Matters in the AI Era

When we ask AI to “set up an application,” it may:

  • generate a full framework
  • create dozens of files
  • mix concerns
  • over‑engineer the bootstrap
  • hide the request cycle

Our literacy lets us steer the conversation:

“Keep the front controller simple.”
“Put routing here.”
“Register the error handler here.”
“Let controllers stay thin.”
“Let the domain stay clean.”

We’re not memorizing architecture
— we’re shaping intention
.


6. When to Ask AI for a Front Controller

The moment when our application needs a single place to begin

We may start with:

“Add a route for /users.”

AI gives us a standalone file.

Then we ask:

“Add error handling.”

AI adds code to another file.

Then we ask:

“Add controllers.”

AI spreads logic across more files.

We feel the fragmentation.
We feel the noise.
We feel the concept.

This is the moment to say:

“Give me a simple front controller 
that coordinates everything.”

AI will produce a clean entry point.

This is the literacy we’re learning:

When the application begins to scatter,
we ask for a front controller
.


7. The Mental Model in One Sentence

A front controller is the quiet place
where
our application wakes up,
takes a breath,
and begins
.

Once we see this shape, we can collaborate with AI on any application structure
— from a tiny script to a full framework —
without losing clarity.



Tony de Araujo —New York


z_appendix_101/php_entry_point_for_the_ai_era.txt · Last modified: by editor