Precursors: In general, they can spawn anywhere that a ruin generates, although they do not generate for every ruin in my experience.
Per Steve dev post here, the requirements are >0.4G gravity and temperature in the range of 200 to 360 K for terrestrial-typed bodies (planets and moons only, as asteroids and comets cannot be terrestrial-typed bodies).
Star Swarm: I'm not sure there is any published documentation on this, but I believe they need to spawn in a system with sufficient mineral resources to support their initial fleet generation. Otherwise, no clue, they're so rare that I don't even have a good body of observations to speculate from.
Rakhas: See
Steve dev post here. The requirements are: a temperature in an unspecified ~100-degree band (I don't think the exact values are published but I would imagine somewhere in the 200-360 K range, as for ruins/Precursors), some oxygen, some minerals present, and no ruins. Note that Rakhas seem to cause errors when generating rather often which is one reason I always play with them turned off.