The Internet of Things (IoT) is envisioned as a ubiquitous computing infrastructure in which everything becomes connected, enabling gigantic information exchange among Things and people. These connected smart Things generate an enormous amount of data which need to be efficiently managed to form a unified global IoT. Unfortunately, due to the lack of acceptable open standards, communication protocols, and support for device/service discovery, the recent IoT deployments in smart environments (e.g., smart home, smart building, smart city) are posing imperative challenges related to interoperability, discovery, and the configuration of deployed objects, since the number of objects is expected to grow over time. Therefore, it is of utmost importance to provide open and scalable solutions for the discovery of devices (i.e., Things), their configuration, and data management. This paper introduces an open and scalable IoT platform by adopting the modular characteristics of edge computing for smart environments. This paper: (i) performs a systematic literature review of IoT-based infrastructures and analyzes the scalability requirements; (ii) proposes a layered IoT platform for smart environments that fosters heterogeneity, interoperability, discovery, and scalability; and (iii) demonstrates the applicability of the proposed solution by relying on a comprehensive study of a Väre smart building use case at Aalto University.