Modularity plays a key role in many engineering systems, allowing for plug-and-play integration of components, enhancing flexibility and adaptability, and facilitating standardization. In the control of diabetes, i.e., the so-called "artificial pancreas," modularity allows for the step-wise introduction of (and regulatory approval for) algorithmic components, starting with subsystems for assured patient safety and followed by higher layer components that serve to modify the patient's basal rate in real time. In this paper, we introduce a three-layer modular architecture for the control of diabetes, consisting in a sensor/pump interface module (IM), a continuous safety module (CSM), and a real-time control module (RTCM), which separates the functions of insulin recommendation (postmeal insulin for mitigating hyperglycemia) and safety (prevention of hypoglycemia). In addition, we provide details of instances of all three layers of the architecture: the APS© serving as the IM, the safety supervision module (SSM) serving as the CSM, and the range correction module (RCM) serving as the RTCM. We evaluate the performance of the integrated system via in silico preclinical trials, demonstrating 1) the ability of the SSM to reduce the incidence of hypoglycemia under nonideal operating conditions and 2) the ability of the RCM to reduce glycemic variability.