Refactor server to controllers