Replacing the controller involves
removing the right hand cover to gain access to the controller.
Before you disconnect any wires, you need to either take some
detailed photographs, or draw a detailed diagram, showing the existing wiring colours and all the soldered connections onto the controller so you know where they all go.
Then you will need to carefully unsolder all of the wires from the controller.
With the wires disconnected, you can then undo the Allen bolts holding the semicircular heat sink plate onto the stator and carefully lift the old controller/heatsink assembly away.
The new controllers usually come already mounted on a heatsink, so there should be no need to remove the old controller from the old heatsink.
Carefully slip the new controller and heatsink assembly onto the stator making sure that
all the wires are in the correct position and are not trapped between the heatsink and the stator, and then bolt it in place.
Solder the wires to the new controller in the same positions as the old one
(refer to your photo or diagram to ensure the wires are all correctly connected).
Refit the motor side cover and carefully tighten the cover bolts making sure the cover is properly centred and tightened down evenly.
I usually test the motor at this stage to make sure it works correctly before refitting the wheel to the bike.
Alan