When any single request is made to Joomla it always loads and executes in the same pattern. Once you know how this pattern works you can make the right decisions on how to design your extensions.So all requests in Joomla either go to index.php at the root, or they go to the index.php file in the administrator folder.
In this case, we're going to take a look at the index.php file at the root.
So first Joomla loads what's known as the bootstrap code.
This code is going to load the configuration file and get the database started and do a few other things to get everything in place, so that Joomla can execute the rest of the code.
Then comes the application which is initialized.
In this case, we're getting the site application and we're just getting it started so that we can begin to run code on the front end of Joomla
Next the application is routed.
The router is going to take a look at the URL that's being passed into Joomla and decide what code it needs to run after that.
After the application is routed then Joomla dispatches the application.
In this step Joomla is running the component and all the modules. So it's going to run the login module and the menu modules and it's going to run the component that's going to generate the article that's going to be displayed. And it's going to gather all the output from all these different pieces and just hold them in memory for a little bit.
Then finally, after it has all the output from all the different components and modules Joomla is going to load up the template and then backfill all of the placeholders for the module positions and the component. So now right before the output goes back to the browser we have one last chance to make any modifications we want. And then finally the output from the application is sent back to the browser.
Even if you want to build something simple with no template, still go through index.php rather than build your own PHP script. For security it's important that all PHP requests go through Joomla and not directly to individual scripts.Joomla's standard execution flow gives you ample opportunity for adding code at strategic points. When you understand how Joomla executes you can avoid needless hacks and workarounds.