117

Regarding source folder hierarchy, there are always some common features, such as the src, doc or test folders, which have rather easy-to-understand contents.

However, I realized that big projects have both a lib and vendor folders, while I had always thought they were the same, as their names hint at including “third-party libraries from external vendors”. Though, seeing both in the same project means there is a difference.

I couldn't find any information nor on Google nor on sources such as the Filesystem Hierarchy Standard, even though this is actually a somehow common practice.


Here is a more detailed example with Symfony: once you create a project, you get a lib folder at the root of your project. In this folder, the following structure is found:

lib
+--filter
+--form
+--…
+--vendor
    +--simpletest
    +--symfony

Here, the symfony folder contains all Symfony's core.

MattiSG
  • 1,952
  • 2
  • 13
  • 16
  • 5
    @YannisRizos I know it's not in their source. Once you start working on a project and generate modules, though, you'll end up with lib/vendor and other directories along vendor. And they're not the only ones. “everyone can select any dir structure” Yeah well, thanks. Everyone can code however they want. If I want to call src “woudzigouga”, I can. I'm not asking whether I can but why others that are serious and well-known do something that looks like a good practice. – MattiSG Dec 05 '11 at 10:02
  • 2
    Other than the obvious, that lib holds core libraries (absolutely essential libraries OR libraries built from the same author as the framework) and vendor holds third party libraries, I don't think there's any other sane distinction. That distinction is somewhat important for a variety of reasons, and it makes sense as a generic practice. – yannis Dec 05 '11 at 10:27
  • 1
    btw, could you add the clarifications in the comments to the question itself? – yannis Dec 05 '11 at 10:30
  • @YannisRizos What clarifications? The Google Code search proving my question isn't totally bogus? It would actually be helpful if you could detail the “variety of reasons” for which the distinction is important, as well as explain how some included third-parties can be more essential than others — if they are included, there's a reason, unless the maintainers are incompetent and batch-include code. – MattiSG Dec 05 '11 at 10:41
  • The Google Code search proving my question isn't totally bogus? Mostly that. It backs your claim that both directories are common. You should always back your claims in questions. btw this isn't for me, I know both directories are common, but no reason not to add the search in the question. as well as explain how some included third-parties can be more essential than others Writing an answer, and that's not exactly what I wrote in the comment there's an OR there... – yannis Dec 05 '11 at 10:46
  • Unfortunately, in the Symfony example, the vendor folder actually contains the core library in the symfony folder... Well in this case the vendor are the symfony people, and lib is where you should put your libraries... – yannis Dec 05 '11 at 11:10
  • @MattiSG: Please don't comment on your own question. Your comments ("clarifications") should be added to the question. Ideally, you'll rewrite the question to include all the comments. It's hard to integrate all of the comments into one coherent question. – S.Lott Dec 05 '11 at 11:11
  • 1
    You can touch things in /lib/, you can't touch things in /vendor/ – Timo Huovinen Dec 01 '13 at 12:51
  • I presume this is Linux, or at least Unix-like systems, where we refer to these as "directories" not "folders" which is a Windows-ism. A folder is not the same thing as a directory which often, and should, contain an index file. – Rob Jun 28 '18 at 11:43
  • And which difference between a vendor and a thirdParty directory? – Sandburg Sep 20 '20 at 07:42

4 Answers4

73

When I see a lib or libraries directory, I think of:

  • Libraries, not plugins, modules, etc.
  • OOP instead of procedural, where that's applicable (i.e. PHP)

When I see a vendor directory, I think of:

  • Libraries, plugins, modules, components, etc. Not just libraries, but anything that's provided by a third party.
  • And stuff that's not code, like an icon set.

When I see lib and vendor directories, I think of a few distinctions:

  1. lib holds only libraries, vendor may hold anything really,
  2. lib is where I should put my libraries, vendor where I should put anything third party (including code by the original author),
  3. lib is where libraries by the original author of the project are located (if that's not me), whereas vendor is where the original author put third party anything.
  4. You can safely assume that whatever is in lib is licensed under the same license as the rest of the project.

Whichever one of the above applies, is reason enough to have different folders. AFAIK there is no generally accepted practice. Some communities have community wide common practices, but that's just about it.


As for the specific Symfony example: Symfony is a framework and I think what the developers are trying to say is that in a Symfony application the framework's core libraries are vendor code, i.e. coming from a third party and not from the original author of the application (you).

yannis
  • 39,597
  • 3
    “Stuff that's not code” would be in data or resources (or something more precise along the lines of img), IMHO. Moreover, in our Symfony example, vendor actually contains all Symfony core, so unless I don't get your “original author” denomination, I don't think that fits your points 2 and 3. – MattiSG Dec 05 '11 at 11:13
  • 1
    @MattiSG Ah, sorry, I'm not saying it should fit all four points. Just one. And "Stuff that's not code" should be in a resources or assets directory, but depending on the project it could make sense in a vendor directory (I prefer assets really). – yannis Dec 05 '11 at 11:15
  • 4
    What's better singular or plural? lib vs libs and vendor vs vendors ? – Quang Oct 17 '12 at 19:24
  • 5
    @Quang Most popular projects I've seen use singular, but I have no idea which one is better. – yannis Oct 17 '12 at 19:25
  • @YannisRizos: what makes you think of OOP instead of procedural? – tumultous_rooster Oct 27 '14 at 18:22
  • @Quang Just stick with lib because it's the convention. Other developers won't have to waste time changing their folder names if you bundle something with libs – f0ster Feb 24 '16 at 21:31
24

Generalizing @WayneM's answer but not daring to edit it so much.

So, it seems this structure can be observed in application frameworks (Rails and Symfony at least).

It is a way to keep the lib / src structure intact for application developers, while adding the other level of distance brought by the use of a framework: the vendor folder actually contains the framework's libraries, leaving the lib folder for the application's included libraries, and src for its source files.

It is a “more distant” lib, vital since without the framework, the application is useless, but not to be touched by the application's developer: it is the framework vendor's libraries.

MattiSG
  • 1,952
  • 2
  • 13
  • 16
10

In the case of something like Symfony, lib is the application code (i.e. written by the developers) and vendor is third-party code. Think of it like lib is what the src folder normally is, and vendor is lib. I normally see that style in PHP because you separate out the html templates from the actual classes.

Wayne Molina
  • 15,684
5

From the Rails Asset Pipeline guide:

  • app/assets is for assets that are owned by the application, such as custom images, JavaScript files or stylesheets.

  • lib/assets is for your own libraries' code that doesn't really fit into the scope of the application or those libraries which are shared across applications.

  • vendor/assets is for assets that are owned by outside entities, such as code for JavaScript plugins and CSS frameworks.

I know this is not a Rails-specific question, but the explanation is good and clear and probably extends to other frameworks/project structures.