When I speak of scripting languages I am speaking of languages like Python, Perl, and (in my case) PHP. After using CodeIgniter, Zend, and lots of other fun MVC systems it seems clear that one thing one one seems to agree on is the folder structure (alongWithOTher things_like_that). This is really causing a problem for me because I can't find any good documentation on the benefits of different structure designs. Most people just recommend one because that is what they use without regard for improvements in design.
One of the things I hope we can all agree on is that checking the file system for existing files when autoloading classes is very bad practice. Our classes should not be in one of 5 possible locations causing a barrage of file_exists() checks for each library we load.
So anyway, I am trying to collect directory structures that I can compare to find the best practices when planning for applications that:
So here is what I have so far. Keep in mind that libs is just a term meaning your main library/class directory and may even contain models depending on the folder structure. Also, I excluded any type of static content (JS/CSS/images) as that stuff is really an after thought and not related to our serverside code - it may even be on another server! The same thing with caches, file uploads, lang, and all other generated content.
/controllers
/views
/models
/libs
/config
index.php
This kind of reminds me of the Zend framework which piles everything into a single libs folder (which also includes subfolders to keep things organized). Only works for a single site.
/libs
/site
/controllers
/views
/models
/config
index.php
This would a multi-site version of the above structure.
/libs
/functions
/site
/controllers
/models
/views
/config
/site2
/controllers
/models
/views
/config
/modules
/user
/controllers
/models
/views
index.php
This would be version that would allow multiple sites and drop in modules. The modules would be self contained MVC apps like a forum which would include business logic, CRUD, and views.
So does anyone have a perfect structure they could share or guide me in choosing a good extend-able design?
Here is an overly complex example that does a good job of organizing everything - at the cost of clarity and simplicity.
(source: gsdesign.ro)
Not to specifically recommend symfony, but rather it's approach, which I think is pretty good (but not "perfect")
Allows for:
Also, among symfony's ups and downs, one thing I think it does pretty well is caching. And I don't mean template/view caching - I mean compilation-like caching.
When a project is executed the first time, symfony builds a master file of library classes which, upon successive hits to the application, not only removes dozens or even hundreds of stat calls per request, but performs other optimizations like the removal of comments.
It also caches configuration data and autoload information, all of which can be tweaked to suit your needs.
We use a structure similar to your last "multi-site" option for a mutli-site forum engine we built in house and it works out really well. You can always copy modules over if you need, and it also allows for the possibility of Site A customizing their module a little without affecting Site B.
When you get into practical applications of this, you're talking about completely separate teams, maybe even businesses using those two sites, a little division is not the worst thing. We also have a shared modules folder, but if you name a file the same thing in the Site's modules folder, it uses that version instead. Using that and __autoload (assuming PHP), then the Site devs don't really have to worry about where the module is located to use it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With