I have a enterprise webapp that is extremely ajax heavy, all data goes though some sort of ajax, so is saving, updating deleting etc. Modeled after the MVC paradigm
The site is mostly compromised of three parts
Interface page An interface page only contains the interface and all the js that goes with it, no data processing of any kind. All data is requested after the interface has loaded. All data is transmitted and received in a common interchange format.(More below) eg. edit_inventory.php or list_inventory.php
Backend Page A backend page that processes data when commands are received kinda like APIs that you see on other webapps, it basically have a giant switch statement of all the commands it accepts. eg. ajax_inventory.php
Classes Page A page with a single class that handles a single object, eg item, invoice, account etc. They currently handle only database connections, getting data and saving data. It is also responsible for error checking and taking care of foreign key links/cascade data.
Copying from a typical CMS, a set of classes, interface and backends are called components.
root
>comp
>inventory
>class_inventory.php
>ajax_inventory.php
>edit_inventory.php
>list_inventory.php
>ajax_inventorymerge.php
>edit_inventorymerge.php
>account
After a while, I noticed this method or idea have generated a lot of files, current at 400+ files just for interfaces and backends. The 400+ pages are quite unique in their own respects, most are complex CRUD interfaces for billing, inventory, reporting, misc data.
The questions, I am looking for answers that are commonly used.
Is this a good pattern, can it be improved?
Should objects and classes such as "Product" responsible for formatting the data into the common interchange format as mentioned earlier?
Should objects allow unfiltered access to their data or only filtered access? Unfiltered access also meant that there must be lots of filtering to be done at the backend level. Filtering is mostly getting rid of unwanted data(waste of bandwidth) or metadata. However, sometimes it might be data that the user should not see(Permission related). Filtering is mostly done on the key-values pair(form_data)
Since there are multiple data forms outputted by an object from html(form_html), messages(msg), key-value pair(form_data) etc. How would one best request the data in one whole, rather than $a->getData(), $a->getMsg, $a->getStuff? Another interchange format? or just use the common interchange format as mentioned earlier?
Common Interchange format(in json)
{"msg":"Sucess",
"form_data":{
"id":100,
"product_code":"BLA",
"size":"3"
},
"form_html":{
"list":"<\/li><\/ul>"
},
"script":"alert('Some stuff');"
}