Database backend

This isn't actually providing a database backend, just starting to factor things out from the command state into a protocol so one can be added cleanly.