I've been reading Invisible Armies by Max Boot. It has a chapter on American Revolution and the rise of Ku Klux Klan. There he mentions that for some time KKK basically served as a sort of militant wing for the Democratic party. In the meantime the Republican party was founded by anti-slavery activists and had Lincoln as the first Republican president. Who played a large part in abolishing slavery and served as commander in chief for the Union side.
Now these days the Republican party seems to be the conservative one, and Democratic party is the more liberal one, which seems to be the polar opposite of how things were a 100 years ago. The Democratic party had massive support in the South, that consistently vote Republican now. There is also a racial divide between party supporters: Democratic is the party that the minorities vote for the most, despite the fact that they basically created KKK. While the Republicans are somewhat notorious for attracting various breeds of racists. So how come there was such a dramatic switcheroo between the two parties?
One good book on an important part of this process is "The Disruption of the Solid South" by the late American historian George B. Tindall. The book was published in 1972, when that "disruption" was still underway, so it doesn't cover the post-Nixon continuation of that process, but it's an excellent explanation of how it began and how Nixon gave it an important push.