In this episode, we're reorganizing our application's structure to get ready for some more advanced features and better code practices.
We start by moving away from putting everything inside index.php
. Instead, we're setting up a designated bootstrap
directory at the root of our project. Here, we create an app.php
file strictly for bootstrapping—meaning, it's responsible for setting up everything our app needs before it can start handling requests. This keeps our code clean, modular, and easier to maintain. We simply require this bootstrap file from index.php
now.
We also talk about scoping out the app's responsibilities with an App
class, where we'll handle things like managing dependencies (think requests and responses) and kicking the app off using a run
method. At this stage, we scaffold the method and wire it up so our bootstrap file runs the app as expected.
There's a bit of prep at the start of bootstrapping, like possibly setting up custom error handling. We also start registering routes (initially in the bootstrap file), but we'll soon break routing out to a dedicated file for better organization. Eventually, we'll support separate files for web and API routes as needed.
Finally, we discuss the basics that almost every framework has: some initial setup, an application container for managing things like requests and routes, routes registration, and finally running the app to respond to incoming requests. This episode lays the groundwork for those best practices!