Goal-based Interaction with Smart Environments: A Unified Distributed System Architecture