Web application directory structure
During my experience as a web developer, I always found that a well organized directory structure is the base of a good web application. Through the years I have frequently modified the structure, because I felt some things just weren’t right.
Below I will list the directory structure which currently works pretty well for my needs. I will not go into too much details, as I think most things are self explanatory.
project
- app
- controllers
- newsController.php
- …
- etc
- schemas
- config.ini
- jobs
- models
- newsModel.php
- plugins
- templates
- news
- __form.html
- add.html
- edit.html
- list.html
- …
- news
- application.php
- controllers
- libs
- PEAR
- Smarty
- Zend
- …
- public_html
- css
- images
- js
- .htaccess
- bootstrap.php
- tests
- NewsTest.php
- tmp
- cache
- templates_c
The controllers/ directory
The controllers/ directory contains all the controllers for the application.
The etc/ directory
Configuration and database schema files will go here.
The jobs/ directory
Cron jobs, database schema migration scripts or import scripts to be written. These are run using the PHP CLI executable and are stored here.
The models/ directory
Holds model classes, some of which are derived from database abstraction layer, such as PEAR’s DB_DataObject.
The plugins/ directory
Since I am using Smarty, I will put my custom plugins here.
The templates/ directory
This contains a sub-folder for each controller (named after the controller) and also some layout template files. Within each sub-directory there is a template file named after the action and possibly some additional helper templates which I prefix with 2 underscores.
The application.php file
This file will contain all the different stages of the application, such as loading configuration data, setting up a database connection, etc.
The lib/ Directory
Any third party library is stored in here. Most of the time, this directory is maintained by svn:externals.
The public_html/ Directory
This one is pretty obvious I think …
The tests/ directory
Unit tests (mostly for models) will go here.
The tmp/ directory
This is the base folder for all sort of files that can be deleted! Anything transient is stored here.
Questions? Suggestions? Shoot!