Conventional stun guns have a fairly simple design. They are about the size of a flashlight, and they work on ordinary 9-volt batteries.
The batteries supply electricity to a circuit consisting of various electrical components. The circuitry includes multiple transformers, components that boost the voltage in the circuit, typically to between 20,000 and 150,000 volts, and reduce the amperage. It also includes a oscillator, a component that fluctuates current to produce a specific pulse pattern of electricity. This current charges a capacitor. The capacitor builds up a charge, and releases it to the electrodes, the "business end" of the circuit.
The electrodes are simply two plates of conducting metal positioned in the circuit with a gap between them. Since the electrodes are positioned along the circuit, they have a high voltage difference between them. If you fill this gap with a conductor (say, the attacker's body), the electrical pulses will try to move from one electrode the other, dumping electricity into the attacker's nervous system.