Move business logic and serialization into models

The models are designed to have an API consistent with
ActiveRecord/ActiveModel.