An ecosystem is a community of lifeforms and their environments connected to each other. In an ecosystem, the living and non-living things interact by exchanging energy and recycling nutrients.
An ecosystem might encompass a contained area like the Millennium Gate, (VOY: "11:59") or an ecosystem might be an entire celestial body. The Mikhal Traveler Nakahn claimed to have landed his ship on a living creature so massive it supported its own ecosystem. (VOY: "Darkling")
Ecosystems could be damaged by internal factors such as pollution, (TNG: "True Q") or by external factors like on Penthara IV, which was struck by an asteroid. (TNG: "A Matter Of Time") Metagenic weapons were designed to destroy entire planetary ecosystems. (TNG: "Chain Of Command, Part I") The Nacene accidentally caused the destruction of the ecosystem of the planet Ocampa. In 2356, a metreon cascade wrecked Rinax's ecosystem, resulting in an endless frigid winter and the deaths of approximately 300,000 Talaxians. (VOY: "Jetrel", "Friendship One")