I'm currently trying to adapt Domain-driven-design principles to my development practices. And I have stuck on how to define an aggregate root for data that are organized in hierarchies.
Let's take for instance folder structure - each folder can have 0..N sub-folders, and sub-folder 0..N can also have 0..N sub-folders and so on.
I have invariants on a folder and all it's direct and indirect subfolders - deleting folder should result in deleting all of it's sub-folders
Would that be DDD valid approach to have let's say Aggregate root "Folder hierarchy", that contains 1 "Folder" entity (that would be "header" folder for that folder hierarchy) and each Folder entity has 0..N Folder entities (sub-folders)
Would that be a valid DDD? Would that be effective? Since I have read that DDD advocates to have small Aggregates, but this "Folder Hierarchy" would potentially be a huge aggregate...
Is Aggregate Root with Deep Hierarchy appropriate in DDD?
Effective Aggregate Design by Vaughn Vernon
Any advice how to make this both DDD valid and effective?
EDIT
Let's have a bit different example of objects that have tree-like structure. Let's say I need to develop a task tracking system and this system needs tasks to have sub-tasks non-fixed levels deep - all tasks are from functionality/behaviour perspective the same - each task can have 0..1 parent task and 0..N child tasks.
Having Task
as an aggregate root (with all it's child-task hierarchy) would not follow DDD recommendation's to have small Aggregates - right?
What would be a good design for Task
according to DDD principles? And how to implement invariants on a Task
(with all it's child-task hierarchy) if Task
(with it's hierarchy) is not an aggegate?