There are three main techniques. For bulk supplements you typically start out with some sort of crop that is rich in what you want. And then you refine it by chemically separating it and keeping the part that you want. If the result does not require the highest purity this is a very cheap way to make bulk supplements and even medications. For example protein powder or morphine.
A lot of medications and such are fully synthesised. This includes melatonin. By combining various chemicals in certain conditions and filtering it properly we can create the organic compounds in a lab. For example a lot of amphetamines are made this way.
The third option is to take a genome, preferably from a human, and injecting it into a bacteria or yeast. You then grow this which produce the protein in the genome which is either the drug you wanted or will make the drug you wanted. By filtering out the bacteria you are left with the drug you needed.