The kidneys act like a filter to pull things out of the blood for disposal in the urine. When some minerals/compounds get too concentrated, they can actually crystallize, forming stones (just like if you add too much sugar to a glass of water — it can no longer stay dissolved).
Although the same compound that causes gout by crystallizing in joints (uric acid) can also form stones, the most common stone is made of calcium and oxalate. When you pass a stone, the doctor will test it to see what it’s made of (they may have you urinate through a strainer to catch the stone).
General Diet Advice
Calcium ok, tea and coffee not
Eating food with calcium does NOT increase your risk of these stones (it may actually lower it), but foods that create oxalate can (e.g., tea, coffee, beans, chocolate). Before stopping these, do the other treatments. Only stop these foods if the stones come back after treatment.
Stay well hydrated! The more dilute your urine, the less likely it is that things will crystallize out.
Magnesium and vitamin B6
Taking magnesium and vitamin B6 has been shown to decrease the production of calcium stones by over 90% in repeated studies. Taking a good multi-nutrient powder is a good way to get these. Consider adding an additional 200 mg of magnesium at dinner to modestly increase its effectiveness, as magnesium's effectiveness at preventing stones may increase if it is taken with a meal.