From wastewater treatment plants to decentralized resource factories