I was looking for a dictionary where are described the meanings and purposes of
ID: 651917 • Letter: I
Question
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:
What is the /models folder?
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?
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?
Explanation / Answer
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.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.