Refactoring for app factory pattern

see http://flask.pocoo.org/docs/patterns/appfactories/

this will allow us to run api and frontend apps in parallel if necessary