Autotrophs are called producers, which can produce their own food by harnessing the light energy from the sun. The energy stored in them moves through ecosystem via food chain.
Heterotrophs are the organisms that cannot produce their own food. Instead they eat the producers to obtain the energy, for their survival. The heterotrophs are of five types. They are herbivores, carnivores, omnivores, detritivores, and decomposers.
Producer plants produce food. Herbivores eat such producers. Carnivores eat herbivores. Omnivores can eat both, producers and consumers. When an organism dies it is acted upon by the detritivores organism and decomposed by the decomposers.
Thus, the energy flow in an unidirectional pattern in the ecosystem.