Traditional tempeh is made from mold fermented soybeans. Whole soybeans are soaked, dehulled, cooked, cooled, and fermented. Specialty tempeh may include other sources of starches such as beans or whole grains.

From a food safety perspective,
tempeh is analogous to the hazards of sushi rice.

Sushi rice is soaked and cooked with the intention of warm holding for an extended period. Tempeh is soaked and cooked with the intention of fermenting at 30C for 24-48 hours. In both, the cooking process eliminates vegetative pathogens. This leaves the three sporeforming pathogens as hazards.

Spore forming pathogen Possible Control Measures
C. botulinum pH ≤ 4.6; presence of oxygen, competitive microbial cultures
C. perfringens pH ≤ 5.3; presence of oxygen, competitive microbial cultures
B. cereus pH ≤ 4.3; competitive microbial cultures

Tempeh soybeans, beans, or grains are soaked to hydrate them from their dried state. Hydrating these starches also hydrates the bacterial and mold spores present. Therefore, it is safest to hydrate at refrigeration temperature. Alternatively, the soaking water can be acidified to pH ≤ 4.3 by adding a mild acidulant such as vinegar, lactic acid, or acetic acid. High acid levels inhibit the three spore-forming pathogens. Later, during fermentation high acid levels will favor mold growth over growth of spoilage microorganisms. This acidulation step is not traditional, but is analogous to food safety changes made to traditional preparations of sushi rice.

Once hydrated and dehulled, the starches are cooked. As noted above, cooking eliminates all of the vegetative pathogens, leaving just the three spore-forming pathogens a concern.

After cooking, the dehulled soybeans are spread thin to cool. Spreading the starches thinly exposes all of the surfaces to air. Oxygen will prevent Clostridium growth and may lead to lethality. It is noted that at the microcosm level, there will likely be anaerobic areas. Bacillus cereus is facultative. Acidulated starches will prevent growth of these pathogens regardless of the presence or absence of oxygen.

Historically, the competitive microbial culture in tempeh was a Rhizpus (R. oryzae or R. oligosporus) usually originating from a banana or plant leaf the cooked soybeans were wrapped in. Today, a tempeh culture can easily be purchased. Starter spores are sprinkled onto the surface. The tempeh is allowed to ferment at about 30C for 24-48 hours. If using a quality starter culture, the mold will grow rapidly in ≤ 4h (functioning as a competitive antimicrobial culture). After 24-48h the tempeh will be held together by white mold mycelium indicating a successful ferment.

from wikimedia white mycelium with black sporangiospores

After 48h the tempeh culture may sporulate producing dark or black spores. This is not harmful, but is considered a quality defect. Likewise, fermenting past 48h may develop ammonia byproducts reducing quality and increasing the pH. An increase in pH is less of a concern to food safety at this point, since an active (competitive inhibitory) mold culture is present.

Tempeh is best stored frozen.  If kept refrigerated it will over-ripen in about 2-3 days (black spores and ammonia).   If left at ambient temperature it will over-ripen in 12-24h.  An additional food safety hurdle is that most tempeh is fried or deep fried.

For some additional details on Tempeh consult The Book of Tempeh (Wm Shurtleff).