It is quite true that the early Republican party attracted all sorts of leftwing radical trouble-makers in the early days, which is unfortunate because I believe that the cause of preserving the Union to have been a just one. Lincoln started out as a sensible Republican who increasingly had to curry favor with the party's radical factions to prevent a political splinter during the war.
As a case in point, Karl Marx was an international correspondent for the New York Daily Tribune, and he was 100% behind the radical abolitionists and the radical reconstructionists, as were most left wing radicals of the time. It's unfortunate that the union cause became wedded to radical abolitionism and reconstruction, though fortunately the saner elements of the party ultimately prevailed by the 20th century.
The Democratic Party had its origins in Jeffersonian (and Jacksonian) Agrarianism. It only started to resemble anything recognizable to today's liberals and leftists with William Jennings Bryan's candidacy in 1896 and 1900 (despite his religious fundamentalism, Bryan was the economic "progressive" of his day). By the time Wilson was President, northern Democrats at least tended to be solidly progressive, though the South remained the stronghold of conservative Bourbon Democrats for decades to come.
The GOP connection to Karl Marx began with Charles Dana, Horace Greeley’s top aide and managing editor of the New York Tribune. The Tribune was the largest circulation newspaper in the country, and the defacto house organ of the Whig and Republican Party.
Charles Dana was a 19th century leftwing hippie who had lived on the Brook Farm commune and then trotted off to Europe to enjoy the 1848 revolutionary movements. That’s when he became pals with Karl Marx which led to the OG commie becoming a foreign correspondent for the Tribune.
1848 is of course the year that Marx wrote his Manifesto, so it’s not like he was keeping his ideas hidden. But alas the 1848 Revolutions failed so a whole bunch of revolutionaries and socialists and communists headed for the hills.
Marx landed in London, but a good many of his comrades landed in Wisconsin and Illinois and Missouri. These are the now forgotten ‘48ers, who played a role in the early Republican party. Lincoln purchased a German language ‘48er newspaper, the Illinois Staats-Anzeiger, and the resulting support he gained from the German ‘48er community is often credited with gaining him the 1860 Republican nomination.
It’s an interesting history, largely unknown today because the Civil War steals all the attention. As EK mentions Marx was a staunch abolitionist. And he while Marx supported Lincoln and the war he also criticized him for making preserving the Union the primary goal, with abolition being a distant second. If you ever run across Marx’s writing on the Civil War and slavery you will be startled at how his opinions are virtually identical to modern American ones. Everybody is channeling that old commie.