Struvite crystals form when the concentration of ammonium, magnesium, and phosphate ions in the urine reaches a certain threshold. These components often become supersaturated in the presence of an alkaline pH, which can be induced by the activity of certain urease-producing bacteria such as Proteus mirabilis. These bacteria break down urea into ammonia and carbon dioxide, increasing the alkalinity of the urine and promoting crystal formation.