Directory structure

How do you structure your directories for projects? The natural way to think is probably:

productA/
  subsystemB/
  subsystemC/
...

Then productB comes along. One approach is to create a common repo and each product adds that back in as Git submodules or something.

productA/
  common/ (submodule)
    subsystemB/
    subsystemC/
productB/
  common/ (submodule)
    ...

However, this soon gets awkward if the product and common code are changing a lot. Changes/pull requests are hard to review when they are in different repos, etc. As much as I love Git submodules, I don’t think they are always the best solution.

What if we invert the directory structure?

product/
  productA/
  productB/
subsystemB/
subsystemC/

Then the most common/general things are at the top, and the deeper you get into the tree, the more specific things become. A product or application is really a specific subset of technology a company or project has created.

It turns out this is a popular pattern. The cmd/<app>/main.go pattern is very common in Go repositories. The Linux kernel source also follows the this pattern. Monorepos is probably where you should start, and this pattern works well there.

General to specific is a good pattern to follow in directory structure, but also in variable/type names. It takes less effort to visually process, and sorting just works. This is one reason I’ve always been puzzled why dates in the format of 12-15-21 are preferred over 2021-12-15. Even to this day, KDE defaults to the “Short” date format.

image

over the ISO date format:

image

At least it gives the option :slight_smile: