API refactoring - DO NOT PULL

Refactor the API so that it does not have any references to FE code.
Also moved a few classes to the API - see diff.
This is to settle #762 .
**DO NOT ACCEPT THIS PR UNTIL FURTHER NOTICE**