Cyber-Physical Systems (CPS) applications are being increasingly used to provide services in domains such as health-care, transportation, and energy. Providing such services may require interactions between applications, some of which may be unpredictable. Understanding and mitigating such interactions require that CPSs be designed as open and composable systems. Composition has been studied extensively in the literature. To complement this work, this paper studies composition of cyber algorithms with user behaviors in a CPS. Traditional middleware algorithms have been designed by abstracting away the underlying system and providing users with high-level APIs to interact with the physical system. In a CPS, however, users may interact directly with the physical system and may perform actions that are part of the services provided. We find that by accounting for user interactions and including them as part of the solution, one can design algorithms that are more efficient, predictable and resilient. To accomplish this, we propose a framework to model both the physical and the cyber systems. This framework allows specification of both physical algorithms and cyber algorithms. We discuss how such specifications can be composed to design middleware that leverages user actions. We show that such composite solutions preserve invariants of the component algorithms such as those related to functional properties and fault-tolerance. Our future work involves developing a comprehensive framework that uses compositionality is a key feature to address interdependent behavior of CPSs.