Projects Folder Structures Best Practices

mattqafouri

Matt Ghafouri

Posted on August 7, 2021

Projects Folder Structures Best Practices

Structuring a solution’s folder is one of the first steps toward starting any software project. If you want to have a good structure with a good separation of tasks, you should be familiar with best practices.
For this purpose, one of the good references which can be used is Github's good projects’ repositories.

Why does folder structure matter?

1- It makes it easier to understand the structure of the project, especially for new developers when they join a new team.

2- It helps to separate deployment from application codes ( test codes vs application codes)

3- defining different categories for different objects(DTOs, Contracts, Filters, etc)

4- defining categories for various assets which can be set access permission or applying some other concerns on them for better management.

Well, so far we understand the importance of the folder structure of software project solutions.
Important to keep in mind, in a microservice architecture, we may have different folder structures because according to the size of the project or other concerns (framework, language, etc), we may see different structures. but in most cases, you could use this structure for your projects.

Let’s check an example
Here We are going to define a folder structure from scratch. In this example, I am going to use Microsoft Visual Studio as IDE, but the concept is the same if you want to use different IDE or languages.

First of all, create a repository on Github with the showed properties

github repo

As you create your repository, the next step is to clone the project on your local system. Open Visual Studio, select Clone repository from the File menu in the opened window, paste the Git URI and click on the Clone button.

you will see the existing items in the solution explorer panel

solution

As you can see in the below image, select Project… from the File menu, then select ASP.NET Core Empty project type.(obviously, you can select your own project type)

folder structure

In the Configuration window, set the properties and click on the Next button
visual studio

Now, I want to use a Git command to create a .sln file for our solution, if you haven’t installed GitBash on your local system, use this link to install.

Git is a set of command line utility programs that are designed to execute on a
Unix style command-line environment. ReadMore

Open the cloned folder in the FileExplorer.
ww

As the next step, in the opened Window highlight the address bar and type CMD, then hit enter; The Command Prompt will be shown, type the command in order to create a .sln file

dotnet new sln

gitbash

To open with the Visual Studio, double click on the newly created solution file. You would have a solution with this structure if you have followed the previous steps.

ssss

Open the root folder and create two folders besides the solution file (src and test)

structure

From now on every project which related to this solution should locate inside the src folder and all the test project should locate inside the test folder.

Here you can add all other projects according to your needs (If you use Visual Studio as IDE, take into consideration that the creation of a folder in Visual Studio won't create a physical folder, and you need to create it manually.)

visual project

You also may need to add other folders besides your project like:
docs, tools, releases
conclusion

Conclusion
Structuring folders in a solution is one of the most important steps in software project implementation.
A good beginning makes a good ending

Follow me on Medium

Maybe you like :
Writing logs into Elastic with NLog , ELK and .Net 5.0

💖 💪 🙅 🚩
mattqafouri
Matt Ghafouri

Posted on August 7, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related