The source tree layout should reflect the architecture; as a corollary, a well-structured architecture can lead to a well-structured source tree layout. I suggest reading up on the POSA1 Layers pattern, attempting to fit your architecture into a layered structure, then naming each of the resulting layers, and using that as a basis for your source hierarchy. Taking a common three-tier architecture as a baseline:

  • presentation/webService (present a web-service interface to our business logic)
  • logic/* (business logic modules go in here)
  • storage/sql (back-end storage APIs here - this uses a SQL interface to store to a database)
  • util/* (utility code - usable by all other layers, but that does not refer outside util, goes here)

Note that the layers do not contain code directly, but rather are strictly used to organize modules.

Within a module, I use the following sort of layout:

  • <module> (path to module directly; defines modular interface)
  • <module>/impl/<implName> (a specific implementation of the modular interface)
  • <module>/doc (Documentation for using the module)
  • <module>/tb (unit-test code for the module)

where the <module> is located in the repository according to the layer to which it belongs.

Answer from Aidan Cully on Stack Exchange
Top answer
1 of 11
27

The source tree layout should reflect the architecture; as a corollary, a well-structured architecture can lead to a well-structured source tree layout. I suggest reading up on the POSA1 Layers pattern, attempting to fit your architecture into a layered structure, then naming each of the resulting layers, and using that as a basis for your source hierarchy. Taking a common three-tier architecture as a baseline:

  • presentation/webService (present a web-service interface to our business logic)
  • logic/* (business logic modules go in here)
  • storage/sql (back-end storage APIs here - this uses a SQL interface to store to a database)
  • util/* (utility code - usable by all other layers, but that does not refer outside util, goes here)

Note that the layers do not contain code directly, but rather are strictly used to organize modules.

Within a module, I use the following sort of layout:

  • <module> (path to module directly; defines modular interface)
  • <module>/impl/<implName> (a specific implementation of the modular interface)
  • <module>/doc (Documentation for using the module)
  • <module>/tb (unit-test code for the module)

where the <module> is located in the repository according to the layer to which it belongs.

2 of 11
63

I can't really give you much advice related to webprojects, but here's how I structure my tree in a programming project (mainly from a C/C++ perspective):

  • /
    • src — Source files written by myself
    • ext — Contains third-party libraries
      • libname-1.2.8
        • include — Headers
        • lib — Compiled lib files
        • Donwload.txt — Contains link to download the version used
    • ide — I store project files in here
      • vc10 — I arrange project files depending on the IDE
    • bin — Compiled exe goes here
    • build — The compiler's build files
    • doc — Documentation of any kind
    • README
    • INSTALL
    • COPYING

A few notes:

  1. If I'm writing a library (and I'm using C/C++) I'm going to organize my source files first in two folders called "include" and "src" and then by module. If it's an application, then I'm going to organize them just by module (headers and sources will go in the same folder).

  2. Files and directories that I listed above in italics I won't add to the code repository.

🌐
GitHub
github.com › microsoft › vscode › wiki › source-code-organization
Source Code Organization · microsoft/vscode Wiki
October 11, 2025 - Inside each layer the code is organised by the target runtime environment. This ensures that only the runtime specific APIs are used. In the code we distinguish between the following target environments: common: Source code that only requires basic JavaScript APIs and run in all the other target environments
Author   microsoft
🌐
DEV Community
dev.to › nickjj › how-do-you-organize-source-code-on-your-computer-i49
How do you organize source code on your computer? - DEV Community
July 10, 2018 - I'd like to say I'm organised but I'm actually quite scrappy. I'll go so far as to make a directory called work or something, but that's about it. One thing you do I don't understand is have a directory called github. I wouldn't do that unless I was working on the code for github :) Other than that, everything I do is version controlled and I don't care what company provides remotes for it.
🌐
Cedesk
cedesk.github.io › code-structure
Source Code Structure
ParameterModel - class to represent model parameters. Members: nature, unit, value, value source, exported; optional: value link (another parameter model), export reference (a target within an external model).
🌐
Javaperspective
javaperspective.com › source-code-organization.html
JavaPerspective.com - 5.4. Source code organization
February 1, 2013 - Source code organization is important for the readability and maintainability of an application. The readability and maintainability depend on how you organize packages, how you distribute classes among them, how the code within the classes is written and how you use Javadoc and comments.
🌐
University of Pittsburgh Computer Science
people.cs.pitt.edu › ~chang › 231 › seminars › S06template › templates › design-src-org.html
Source Code Organization and Build System
It roughly follows the standard proposed in the Tomcat documentation and is very similar to the organization used on many open source projects at the Apache Software Foundation. What are the ranked goals of this source code organization and build system?
🌐
Kennyballou
kennyballou.com › blog › 2020 › 08 › organizing-source › index.html
Organizing Source
With Golang projects, it was no longer possible to ensure all source belonging to a particular organization was under a single tree. Similarly, related to the homogeneous folder structures was the encoding of the source repository in the dependency or code base, e.g., projects from GitHub were found in the folder path ${GOPATH}/src/github.com/.
🌐
Wisc
ece353.engr.wisc.edu › home › c programming language basics › c code organization
C Code Organization
This allows us to separate functionally distinct pieces of code into files that can be shared between multiple projects. We will look at how to use header files and corresponding source files can be organized to form a functional library that can be called from other functions within an application.
Find elsewhere
🌐
GitHub
github.com › microsoft › vscode › wiki › Source-Code-Organization › b99eb8a107bcb78d61fd9de2ec2996a39cfb0662
Source Code Organization
Inside each layer the code is organized by the target runtime environment. This ensures that only the runtime specific APIs are used. In the code we distinguish between the following target environments: common: Source code that only requires basic JavaScript APIs and run in all the other target environments
Author   microsoft
🌐
Medium
medium.com › @msandin › strategies-for-organizing-code-2c9d690b6f33
Four Strategies for Organizing Code | by Martin Sandin | Medium
April 27, 2016 - Four Strategies for Organizing Code This article outlines four different strategies for organizing code: by component, by toolbox, by layer, and by kind. I think these four form a kind of hierarchy …
🌐
Medium
medium.com › @longkai › a-neat-way-to-organize-your-source-code-cb51e7f05b89
A neat way to organize your source code | by 小龙同学 | Medium
February 5, 2016 - However, if you don’t want to open source, just keep it there and no publish proceeding. Same, suppose the author or the community called Bob, puts it into ~/src/github.com/Bob/{project}. After you build a project from ~/src and outputs executeable file(s), resident it to ~/bin if you have no other good reasons. The same goes for the var, usr, pkg, lib, etc. . Be a good citizen in *Nix world. If you write Go code, set GOPATH to ~/src, all your build artifacts would be seen in ~/bin, it’s fine, isn’t it?
🌐
LOC
loc.gov › standards › sourcelist › organization.html
Organization Code Source Codes: Source Codes for Vocabularies, Rules, and Schemes (Network Development and MARC Standards Office, Library of Congress)
Organization Code Source Codes: Source Codes for Vocabularies, Rules, and Schemes (Network Development and MARC Standards Office, Library of Congress)
🌐
Nopcommerce
docs.nopcommerce.com › en › developer › tutorials › source-code-organization.html
Source Code Organization
The Nop.Data library helps separate data-access logic from your business objects. nopCommerce uses the Linq2DB Code-First approach. Code-First allows a developer to define entities in the source code (all core entities are defined in the Nop.Core project), and then use Linq2DB and FluentMigrator to generate the database from the C# classes.
🌐
GitHub
github.com › microsoft › vscode-wiki › blob › main › Source-Code-Organization.md
vscode-wiki/Source-Code-Organization.md at main · microsoft/vscode-wiki
A repository to make changes to the vscode Wiki on GitHub - vscode-wiki/Source-Code-Organization.md at main · microsoft/vscode-wiki
Author   microsoft
🌐
Iterators
iteratorshq.com › home › articles › a comprehensive guide on project codebase organization
A Comprehensive Guide on Project Codebase Organization | Iterators
February 5, 2026 - Logically, these files are created based on the functionality they hold, like the source code files (the raw code), test files, and configuration files. Then by using modules and scripts, you can add functionalities to the code. Remember you can also create separate directories if it makes sense to you. Just like in the real world, an English speaker and a Japanese speaker will have completely difficult syntaxes and dialogue organization.
🌐
Sonar
sonarsource.com › resources › library › source-code
Source Code Complete Guide | Examples, Types, & Tools | Sonar | Sonar
October 20, 2025 - A source code repository (or “repo”) is a central, organized digital storage for software code, acting as a project's hub to track changes, manage versions. It enables developers to collaborate efficiently by sharing, editing, and reviewing ...
🌐
Turing
turing.com › blog › source-code-management-tools-best-practices
Source Code Management, Tools, and Best Practices in 2024 | Turing
February 21, 2025 - A source code repository is a storage location for code and other software development assets, which includes documentation, tests, and scripts. It is often used to manage and organize a software project’s codebase and collaborate with other ...
🌐
DEV Community
dev.to › fullstackchris › advanced-code-organization-patterns-the-case-for-one-file-per-function-1ngc
Advanced Code Organization Patterns: The Case For One File Per Function - DEV Community
March 16, 2022 - It's easier to grok the organization of your code base by being immediately able to understand where the function is based on the import statement alone. With option 1., the add function is in its own self-named file, as is subtract, and so on. With option 2., There is an extra mental leap required to go from thinking "ok...
🌐
Apache
tomcat.apache.org › tomcat-9.0-doc › appdev › source.html
Application Developer's Guide (9.0.119) - Source Organization
1 month ago - As mentioned earlier, it is highly recommended that you place all of the source files that comprise your application under the management of a source code control system. If you elect to do this, every directory and file in the source hierarchy should be registered and saved -- but none of ...