Externally routing cables on Trek Allant 7.4
Assuming you have no cable stops on the outside of the frame, you'll need to use full housing all the way from shifter to derailleur.  Simply run it alongside the top tube and down the right seat stay, and secure the housing to the frame with cable ties.
Its not the prettiest solution, but you're strapping on a motor, battery, controller, and wiring on anyway so looks are already going to suffer.
If cable ties aren't your thing, there used to be brackets for the top tube which would hold a rear brake cable on 80s style road bikes, or you could buy pairs of clamp-on cable stops of suitable size.