Robert Heinlein wrote about this (Public Board)
The amusing fascist world government of Starship Troopers solved the key problem of democracy which is exactly what you said - the mob votes for itself.
Basically, only enfranchise someone who serves the republic through military service or optional public service. Unless you served somehow, you can't vote.
So in the movie, you had all of these grizzled, one eyed, blind and/or amputee ex service members who pervaded society and who could vote.
