scitools.com

← Architecture catalog

Directory Structure is one of Understand's built-in architectures — automatic ways to group a codebase (by directory, git history, language, …) for graphs, metrics, and dependency analysis.

Directory Structure

Languages: Any
Organize file entities by their path in the file system.

Each file is grouped by the directory that contains it, so the architecture mirrors the project's folder tree. The paths are relative to the deepest folder every project file shares, and they always keep at least one folder name - so when a file sits directly in that shared folder, the shared folder itself becomes the top of the tree.

For example, a project with these files

demo/top.py
demo/scripts/build.py
demo/src/main.cpp
demo/src/util/log.cpp
demo/src/util/log.h

builds this architecture, where each group holds the files in that one directory:

Directory Structure
  demo              top.py
    scripts         build.py
    src             main.cpp
      util          log.cpp, log.h

Every project has a Directory Structure architecture, and it is the default Clusters choice for cluster dependency graphs, which is why those graphs group by folder until you pick a different architecture.

Two options leave files out, which is what makes this architecture a quick way to get one that dependency rules fit. A rule like "src/api can't depend on src/ui" is natural to state against folders, but the test files under those folders reference both sides and report violations of a design that isn't actually broken. Excluding the test directories, or the test file names, gives you an architecture the rule holds on without laying one out by hand:

Excluded files are left out of the architecture instead of being grouped elsewhere, so a rule written against it never sees them. Since the architecture that every project starts with covers all of the files, an architecture you add with exclusions gets a name of its own (Directory Structure 2 by default), and both views stay available.

See also the Language and Calendar architectures, which group by language and by modification date and then mirror the directory tree inside each group, and the File Categorizer architecture, which sorts C/C++ files into groups like test, example, and generated code by file name pattern.