I'm working on a dependency managemen solution for a JavaScript.  I'm trying to find the best pattern for grouping similar items in a graph into their own 'modules'.Given a dependency tree like shown below, I have a 'main' module ( app ), that has 5 children ( login, dashboard, form, builder, users ).  These children might share some common deps amongst them.I'd like to create a function that would find the commons and group them upwards or in some cases where the overlap would out weight the benefit, creating a new module between them.In a perfect world, would create a graph like this.  Obviously given a big enough tree, it could over-optimize creating too many child trees so probably stopping at level-3 would be ideal.In this example: d1 was shared 90% of the time, lets move it into the main module.  d6 was used in 3 of the 5 modules, lets create a separate module for that combo.  - d5 was used in 2 of the 5 modules, lets create a separate module for that combination.d3 was used in 2 of the 5 modules, lets create a separate module for that combo.
Finding and Grouping like children
graphs;search algorithms;search trees