The explosive proliferation of smart devices and cloud computing has ushered the era of Cyberphysical Systems (CPS), a congruence of physical dynamical systems with the cyberspace. The success of deploying an Internet of Things (IoT) interconnecting billions of devices relies heavily upon making the right choices in revisiting traditional architectures for networked control and information processing. Inspired by the concept of Software Defined Systems (SDSys), we propose a control architecture for cyberphysical systems and discuss its advantages in terms of scalability, robustness, security, flexibility, and interoperability. The proposed architecture explicitly leverages the fact that agents possess computational units that may be used for in-network processing and decentralized control actions. We integrate a set of components such as sensors, actuators, access points and coordinators and specify the communication flow, the data flow, and the control flow in a programmable fashion. Control is spread over multiple layers (self-controllers, coordinators, local area controllers, and super-controllers) that form a hierarchy with added autonomy for distributed and decentralized actions. A middleware layer is integrated into the proposed design with several services and units to account for real-time operations in highly dynamic environments. We proceed to identify a wide range of potential vulnerabilities to cyberattacks at all levels, and propose solutions for effective resilience, detection and recovery. The proposed architecture aims at a holistic view with increased adaptability, where the controllers efficiently collaborate to quickly capture and respond to abnormal situations in a self-adjusting manner.