Perform a topological sort. A common use is to show the dependency order of nodes in a directed acyclic graph. More information: https://www.gnu.org/software/coreutils/tsort.
tsort path/to/file
echo -e "UI Backend\nBackend Database\nDocs UI" | tsort