What is a Republic?
Generally, any kind of state is a republic. Starting in the 15th century, a republic became differentiated from a monarchy by having power ultimately reside with the people.
In the ancient world, a republic meant any kind of state. The historical root of republic is poplicus, meaning "pertaining to the people". Republic is formed by the combination of res + publica: affairs or things related to the public. This usage was preserved in middle French throughout the 15th century.
Beyond etymology, the usage of this concept is clear in the works of ancient authors. In The Republic Plato describes five different kinds of republics (aristocracy, timocracy, oligarchy, democracy, and tyranny). Aristotle has six, based on the number of rulers and whether they govern for the common good or their own personal good. Generally, a republic could have one ruler (monarchy and tyranny), a few rulers (aristocracy and oligarchy), or common rule (polity and democracy). This kind of typology would be common up until the rise of republican authors in the 15th century.
In the 15th century, a group of republican authors created a new, more focused, usage of the word, motivated by their political climate. If a "republic" is what the people have in common, they reasoned that monarchies could not properly be called republics. Their monarchies were ruling in the private interest of the royal family and aristocracy, indifferent (or hostile) to the interests of the people.
Probably the most famous republican is Machiavelli. In Discourses on Livy he argues for a state in which power is shared between the people and a strong executive, and in which there are a variety of factions competing for power [Short summary of Machiavelli's republican views here]
. Other examples include John Locke, who devoted much of his Second Treatise to rebutting paternalism (an argument supporting monarchy) and contrasting it with his view of democracy.
In layman's terms a republic sometimes seems to mean a representative government (for example, one of the definitions on Merriam-Webster). However, this usage is not developed in political theory or political science.
What is a Democracy?
A democracy is a kind of government in which relatively-equal citizens are empowered to make meaningful contributions to a group decision-making process.
That's a pretty general (and I hope, common) view of democracy, so I won't spend much time on it. The Stanford Encyclopedia of Philosophy has a lengthy article from a more general-philosophy perspective, while Oxford Bibliographies can point you to some decent further reading.
This leaves open the possibility that citizens either contribute directly or through elected representatives.
How do they differ?
In the ancients' usages of "republic", a democracy is a kind of republic. A republic is kind a state, and democracy is one way to organize a state. This is how both Plato and Aristotle did it.
In the writings of the republican authors, republics and democracy are the same. If ultimate power resides with the people (that is, if X is a republic), they can exercise that power in the decision-making process (then X is a democracy). The reverse is true: if you have the people involved in making important decisions (if X is a democracy) then it is true that the people have power (then X is a republic).
Being Greek, Plato doesn't use the words 'res publica' (which are Latin). He instead uses the word 'politeia', which means 'citizens' or 'cities'. This is the root of our English word 'politics' - the meaningful political unit of ancient Greece was the city-state, which connects the concept of 'citizen' to 'city', as well as our current usage.
For an excellent discussion on the nuances that separate 'politeia' and 'res publica' see this summary.