Search code examples
c++visual-studioprojects-and-solutions

Project solution structure


I'm planning a new project that I'll develop in C++. I need a good solution structure, for a quick project overview. My project is a tcp based server. This server is able to save files and text from client into a database or on the filesystem. The server can also send files and data from the database back to the client. My structure should look like:

Solution
- main.cpp
- DataAccess
--- Header
--- Source
- Business
--- Header
--- Source
- CrossCutting
--- Header
--- Source
- Server
--- Header
--- Source
--------------------------------
- External Dependencies
- Tests (Unit and Integration)
- Documentation

That's my idea. Here a little introduction for this folder structure:

DataAccess: Here is the connection between logic and data (database, io)

Business: Here is all the logic. Only the business has access to the data access layer

Server: This is my server layer. Client request will be processed there. Only the server layer has access to the business layer.

CrossCutting: This layer is a little bit specieal. Here are functions, classes, entites, etc., which will be needed in several layers.

I think the other folders should be clear. If not, let me know them. What do you think about this solution structure? Is this a good start or should I need rework?


Solution

  • What do you think about this solution structure? Is this a good start or should I need rework?

    It's a good start; it could use some rework :)

    This is fine if you are thinking of a single project. Ideally you should split this into multiple projects (as separate lib/dll projects) and have a main project that contains your main.cpp and launches the application/server/service.

    Advantages of splitting into multiple projects:

    • compartmentalization of dependencies, per project
    • improved testability of the code
    • separation of responsibilities is enforced (more than with a single project) and formalization of internal protocols is better (at least in theory - you will have to take care to formalize your internal protocols)

    I would consider the following changes:

    root // project root, source control root, etc

    • ExternalDependencies
    • Doc
    • Src
      • solution file [linking to the four projects below and Tests]
      • Tests
        • containing test projects in here [each in it's own directory]
        • -
      • Application [dir]
        • main.cpp
        • main project file (.vcxproj I think)
      • DataAccess
        • headers and sources, not split into separate directories (because this is the visual studio default and it will decrease mistakes caused by default settings in visual studio)
        • project file
      • Business [same structure as DataAccess] ...

    I would also define some common property pages near the solution file, where I would specify common build and temporary build directories, then inherit these property pages accross the projects; This would centralize build artifacts and binaries, and ease the editing of common settings.

    Note: I am currently working on a relatively large project (~180 projects in the solution), using this structure.