Refactor domain, api and controllers