116

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.

10
  • 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 5, 2011 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 5, 2011 at 10:27
  • 1
    btw, could you add the clarifications in the comments to the question itself?
    – yannis
    Dec 5, 2011 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 5, 2011 at 10:41
  • 1
    You can touch things in /lib/, you can't touch things in /vendor/ Dec 1, 2013 at 12:51

4 Answers 4

71

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).

6
  • 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 5, 2011 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 5, 2011 at 11:15
  • 4
    What's better singular or plural? lib vs libs and vendor vs vendors ?
    – Quang
    Oct 17, 2012 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, 2012 at 19:25
  • @YannisRizos: what makes you think of OOP instead of procedural? Oct 27, 2014 at 18:22
23

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.

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.

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.

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