Refactor the prototype

This change includes:
* Reorganize modules and sort out dependencies
* Clean up topology sort
* Add package name trie (prefix tree)