-1

I was looking for a dictionary where are described the meanings and purposes of each directory name used in softwares file trees.
I can't find anything except for the Linux FHS, but that is restricted to GNU/Linux OS.

So I would like to ask you something to understand the meaning of the following folders:

/controllers
/models
/vendor
/src


This is what I've understood so far:

  • /controllers is where I should put the files that have the purpose of control other files. For example in controllers I could have a PHP file that load a file to call MySQL queries, then one that parse the queries to structure an array, and then one that calls the template manager.

  • /models I've no idea of what is intended for...

  • /vendor is where are located external dependencies needed by the software.

  • /src is where the source files are located.


My doubts are:

  1. What is the /models folder?

  2. If for example I include in my project, Mustache.php, I will have Mustache located in /src/Mustache.
    But it also adds some dependencies in the /vendor folder.
    The problem is, in my project, even Mustache is a "vendor" thing (I guess), so shouldn't it moved to /vendor?

  3. If I'm writing in PHP, HTML, JS and CSS. Every file I use for the production will be also the source file, so why shouldn't I put everything in the /src folder and keep out maybe only the minified .js, .css and .html?

5

Where exactly did you find these folders? Details of such a structure often depend on the project, programming language and web framework in use. This one looks like a rather typical MVC structure (model, view, controller) as often used in web projects. Though missing the view part (unless this is /src). In any case this has nothing to do with the Linux FSH which only defines the OS level and not single projects.

You should start reading a bit about the MVC model. The controller should normally just take an incoming request for some specific URL and the get data from the model that is needed by the view to render the response. So the controller should do as less work as possible.

The model is where all database and business logic resides.

Vendor should in most cases hold external plugins and libraries you include in your project. If you write plugins yourself then you may put them there too. Other frameworks will have a dedicated /lib folder for such things (Maybe that's /src in your case?)

I don't know exactly what /src should be for. Obviously this should mean source, but I come from a Ruby on Rails background.

For /lib: you often need some additional libraries you write for some tasks that do not exactly fit the mvc model, say you need some helper classes that do things like converting data to XML or generate statistical data and graphs or some database driver for some specific database your framework doesn't support natively. All such things would go into the /lib folder. But you are free to add more like Rails for example has folders like /script, /helpers, /mailers, /config and many more. And of course subfolders, like you would most of the time want to keep .js, .html and .css separated, since these become a lot of files in larger projects (again Rails as example would in most cases keep the views html files in subfolders named similar to the controllers, since there often is a direct relation between controllers and the views they render, so your customers controller will need all the html files used to render a customers information)

As said, all depends on your tools. Especially web frameworks often define very clear structures and depend on the right files being in the right place. So if you don't use pure PHP but a framework like CodeIgniter you should consult the frameworks documentation.

  • Yes I'm writing an MVC web application, I've not talked about views because I've already clear what is its purpose. – Fez Vrasta Dec 2 '13 at 10:39
  • May you explain more clearly the part about the /lib and /src folders please? – Fez Vrasta Dec 2 '13 at 10:40
  • Thank you, I use plan PHP without frameworks so I can structure everything as I prefer, I wanted just to learn more to be sure to use correct names for the folders. – Fez Vrasta Dec 2 '13 at 11:13
  • 2
    @FezVrasta in this case it may still be a good idea to have a look at the documentation of one or another framework, since their folder structures are often well thought and reflect many years of experience. – thorsten müller Dec 2 '13 at 11:17
2

When developing a project, I think two main principles can be applied to naming folders/directories:

  • Choose semantically correct and descriptive name
  • Choose a popular/established name used for a directory with certain purpose

There are many established naming conventions. From the examples you brought, I've met src used in Java projects for naming the head directory containing source code. models and controllers are commonly used in MVC (model-view-controller) pattern.

That said, to understand the names you need to understand the context they're used in _ language, framework, type of project, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.