The sun provides light to plants and algae, which make up the first trophic level of an ecosystem called the producers. The autotrophs are what heterotrophs consume, particularly herbivores, which make up the second trophic level. Now these herbivores are also consumed by other heterotrophs, those who are in the third trophic level.
It has to be in this order because members of the ecosystem rely on the existence of the other. Without the sun, there would be no autotrophs. Without autotrophs, there would be no heterotrophs. The trophic level represents how energy is transferred from one level to the other. The autotrophs get energy from the sun and the heterotrophs get part of that energy by consuming the autotrophs.