Web Development – How to Organize a Site’s File System Properly

file-systemshierarchyweb-applicationsweb-development

Doing some reading on Stack Overflow, I've found a lot of information suggesting that proper organization of a file system is crucial to a well-written web app. One of the key pieces of evidence is high-frequency references to "separation of concerns" in questions related to keeping programs organized.

Now, I've found some information on organizing file systems (Filesystem Hierarchy Standard) from 2004. It raises only two concerns: first, the standard's a bit dated, so I believe it may be possible to do better given the changes in technology over the past 8 years; second, and most important, my application is very small compared to an entire Linux distro. I think that the file system should be organized very differently because of that.

Here's what I'm looking at, currently:

/backup
/databases
/scripts
/www 
  /www/dev
    /www/dev/login.php
    /www/dev/router.php
    /www/dev/admin pages (php files)
    /www/dev/sites
      /www/dev/sites/content types (php/html files)
      /www/dev/sites/static pages (php/html files)
      /www/dev/sites/modules
        /www/dev/sites/modules/module-specific-media
      /www/dev/sites/includes
      /www/dev/sites/css
      /www/dev/sites/media
  /www/production
    /www/production/login.php
    /www/production/router.php
    /www/production/admin pages (php files)
    /www/production/sites 
      /www/production/sites/content types (php/html files; not a directory)
      /www/production/sites/static pages (php/html files; not a directory)
      /www/production/sites/modules
        /www/production/sites/modules/module-specific-media
      /www/production/sites/includes
      /www/production/sites/css
      /www/production/sites/media

Best Answer

There is no single structure which can fit all the cases. For example, if I compare the tree you quoted in your question with a web application I'm currently working on, it doesn't fit. For example, they separate static pages, while the separation between static and dynamic pages makes no sense in my context of my current app. They create a separate directory for CSS, while I have a single stylesheet which I put at the root and am happy to find it there. I don't have includes, but helpers and something comparable to partial views, etc.

If you create an application which stores and displays events, the logical structure would be by year, then by month, and finally by day.

If you create an application which has three logical parts in it, it should be reflected in the tree.

Also remember that actual file tree is only a tiny part of the project structure; for example, in ASP.NET MVC, nothing forbids you from creating your own virtual path provider and host data in a database rather than as files if it is more convenient and easy to understand for you and other developers who will work on your project later.

Sticking to a file structure some team invented to fit precisely their project needs is not a good idea in this regard.

Related Topic