Making chocolate is a complicated process, and it varies depending on the company and how the chocolate will be used. But it always starts with the beans. Some companies rely on a single source for their beans or only buy them from a certain region. Others may use up to 12 different sub-varieties of bean to create a single chocolate blend. The mix of cacao beans is usually a big company secret, and no two brands use the same one.
When the beans show up at the factory (usually in huge, jute bags), it's time to roast them. Roasting is a necessary step for a couple of reasons. First, it kills any bacteria or mold that may be lingering. While the traditional method is to roast the whole bean, some manufacturers follow an alternative method because they're concerned about uneven roasting when using beans of different sizes, or they just think that roasting in the hull makes the chocolate bitter. They may pre-treat the bean with just enough heat (via steam or infrared radiation) to kill the bacteria and crack the hull. Then the nibs are actually roasted or even ground first into chocolate liquor before roasting.
The roasting process both removes bitterness and develops flavor. The bean gets mellower when some of the acids, such as ethanoic acid, evaporate. Roasting also creates a chemical reaction called non-enzymatic browning, or the Maillard reaction (which is responsible for flavors in lots of other foods, too). It's a complex process that happens when the sugars and amino acids in cacao react with each other in the presence of heat, creating that distinctive chocolaty flavor and smell. It's different with each roasting method and with each type of cacao bean.
The grinding process is done by a machine called a melangeur, which has huge granite rollers that mash the cacao nibs into a paste called mass. The mass goes into a powerful press, which splits the cacao into its two components: powder and butter. The powder is a dry circle called presscake, and if it's going to be used to make drinking chocolate or cocoa powder, that's pulverized into a fine powder. If the company is making solid chocolate, they may make it straight from the mass or start with cocoa powder and add back in cocoa butter (plus some extra if it's really good chocolate or vegetable oil if it's not). Now's the time they'll also add in sugar, an emulsifier like lecithin and other flavorings.
The next two steps, conching and tempering, are so complicated and mysterious that they deserve their own section. And you thought that the roasting process was science-y ...