refactor app to use an api first