I've been writing my own general-purpose PHP library for a while and I'm thinking about how to organize the directory structure, but I wanted to get people's ideas before I formalized the directory structure for the library.

Here is what I have so far: https://github.com/homer6/altumo/tree/master/source/php

I was thinking I could either do it "By Topic" or "By Category". So far, I can only think of one example that I like of the "By Category": Boost http://www.boost.org/doc/libs/1_46_1/?view=categorized

Also, Qt is organized by module, but I think it's a bit messy because everything is kinda stuffed into QtCore http://doc.trolltech.com/latest/modules.html

Any ideas?

Thanks in advance.


I think you mean "directory structure" rather than "file system". ext3 is a file system.

Written by Frank Farmer

Thank you, that's clearer. Updated.

Written by Homer6

is your library MVC based?

Written by emaillenin

Excellent question, and great answers so far. I'll just add that since chances are your class naming will correspond to the directory structure, this is an added motive to having directories/subdirectories make sense: $req = new YourLib_HTTP_Request();

Written by Fanis

I've answered that on another question asking the same already: Directory layouts are completely uninteresting. Make sure your autoloader can find the files. That's all there is to it.

Written by Gordon

I'd take a look at Zend and its naming convention and layout. I think its one of the best organized PHP frameworks / libs.

Written by Mr-sk

Accepted Answer

First of all, the chosen structure is a compromise decision, that means that you'll have to deal and prioritize some aspects over others depending on your purpose. There are some grouping criterias you could follow, such as:

  • Functional Cohesion, I think that should be the strongest one in your design. Classes/files/resources with the same or similar functionality should be together
  • Component Hierarchy, Depending on the granularity level you choose, that means if you prefer fine-grained components vs coarse-grained, you would have more or less files/resources in one folder. This can be controlled using folder hierarchy and nesting.
  • Change, Some files are more likely to be changed than others, you have to keep this in mind in order to provide a folder hierarchy depending on the probability to be modified.
  • Extensibility, For a framework to be useful and adaptable to almost any scenario you have to provide the possibility to extend components and functions. Adding a folder for extensions (aka plugins) is a good idea.

There are lot of criterias you should use, but always keep in mind the KISS Principle. You can search for package management in books like The Unified Software Development Process (Ivar Jacobson et al.), I hope this could be helpful.

This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki