You raised a very interesting and fundamental question. The question concerning the large scale project architecture and the folder structure organization (which is secondary to the architecture).
Today the most common approach to building the CMS framework architecture is the use of MVC pattern. There are some good articles about building your own MVC frameworks, one of them is Build an MVC Framework with PHP.
MVC stands for Model, View, Controller. You may call these approaches whatever you like - MVC, HMVC, MVP. The essence is to isolate the individual components of your system. The "Controller" retrieves the data from the "Model" and sends them to "View", which renders the final HTML. You have already implemented the "V" in your
contacts.php and "MC" in your
contacts_class.php. So you have isolated the view from the model and controller. Now you can easily change your "View" leaving other parts intact.
I am not suggesting you to blindly follow the MVC, MVP or whatever else "MV" pattern. It is the matter of appropriateness, efficacy and taste.
The common dynamic website application may include such components like:
- The entry point, say
- The helper libraries / classes
- The request router
- The modules, components or controllers
- The template engine or maybe single views
The real web application may include any other components like event handlers, event dispatchers and hooks, but these are in fact nuances. Well, let me present it the way I want to present it:
The common framework operation routine as follows:
- The browser request is sent directly to the entry point executable / script (
- The entry point script loads the helper libraries, classes and performs some further initialization of our programming environment.
- The URL is passed to the request router instance. This step can be the part of step 2.
- The request router parses the URL and dispatches the operation to a particular component, module or controller.
- The component (or controller) processes the routed request and sends the data to the view to be rendered.
The corresponding project folder structure is shown in the diagram.
I would suggest you to investigate how the other frameworks are implemented. The recommended CMS / frameworks to begin with are CodeIgniter, OpenCart, Joomla 1.5 and Tango CMS.