Matter moves through an ecosystem through the recycling of energy and nutrients between different trophic levels. The first trophic level consists of primary producers like plants that can manufacture their own food through photosynthesis. Similarly, plants require nutrients like nitrogen to grow.
In turn, plants become the source of energy and nutrients for the primary consumers that eat them. The cycle continues up the different trophic levels, where consumers feed on consumers that are in trophic levels below them. In this manner, matter moves through the ecosystem as organisms in one trophic level provide nutrients for others.
This cycle also involves the work of decomposers like bacteria and fungi that decompose dead matter and waste material to convert them into nutrients for the soil. The cycle begins anew when plants use these nutrients like nitrogen to grow, while photosynthesis enables them to use energy to make food.