The brain between battery, motor, throttle and display.
The controller is the box that takes battery power and meters it out to the motor based on what the throttle, pedal sensor, brake sensors and display are telling it. When it fails, the symptoms look like everything else failing at once: the bike powers on but will not move, the motor stutters or cuts out under load, or the display throws an error code. Controllers do die, usually from heat, water intrusion, or a short in the wiring, but they are also the part most often replaced unnecessarily, so it is worth confirming the diagnosis before you buy.
Matching a controller is a checklist, not a single spec. Battery voltage (36V, 48V, 52V, or a dual-rated unit) must match your pack. The controller's rated continuous and peak current must suit the motor; a 15A controller on a 750W motor will feel weak, and a 35A controller on a small geared hub can overheat it. Most modern hub-motor controllers are sine-wave units that need the motor's three phase wires and five hall-sensor wires connected correctly; some are square-wave or sensorless and behave differently. Then there are the small connectors for throttle, brake cutoffs, pedal-assist sensor, speed sensor and lights, which vary in pin count and wiring.
The part people miss is the display. The controller and display talk over a serial protocol that is specific to the maker and often the firmware version, so a KT controller generally needs a KT-compatible display, a Bafang controller needs a Bafang-protocol display, and generic units are usually sold as a controller-plus-display kit for exactly this reason. If you are replacing the controller on a stock bike, the safest path is the bike maker's own replacement. Mismatched electrical parts can damage a controller or battery; when you are not sure what you have, an E-Bike Assessment is the safe next step.