Refactor application structure.

Mostly I wanted to pull the app out into a modular Sinatra app, which allows more complex mounting options than a classic app (as well as making it easier to configure), but I also took the opportunity to pull a few things out into the models to slim it down a bit.

It passes all the tests and also still works for my own feature set but you're probably going to want to cast a more through eye over this ;)