How to group tasks from subfolders under one heading together with tasks from parent folder?

My folder structures for projects are like in this screenshot:

project folder

Is it possible to write a Dataview query (or even using Tasks) to group all tasks belonging to the same project under a shared heading?

Doing something based on folder paths is one thing I’ve tried, another is to use the Project property I have in every project related file, which links back to the main project document. I think doing the grouping based on folders would be better, since I know I always but files where they belong, but sometimes forget to add the metadata. But if it’s better to do it based on YAML, I’ll set up a Dataview query for “quality control”.