The widely accepted theory of planet formation, the so-called planetesimal hypotheses, the Chamberlain–Moulton planetesimal hypothesis and that of Viktor Safronov, states that planets form out of cosmic dust grains that collide and stick to form larger and larger bodies.
The sun gives direct energy and sunlight to the producer. The producer will grow until it reaches adulthood. A consumer will come eat from that said producer and receive its energy.