How to build a backend that can return raw data (for testing) as well as html for templating

Have a look at:

i.e. create a UI independent OTP application that deals with the business logic and data which a Phoenix app can then use as a dependency - acting only as the web front end.