Reconfigurable Intelligent Surfaces (RIS) represent transformative technologies for next-generation wireless communications, offering advanced control over electromagnetic wave propagation. While RIS have been extensively studied, Stacked Intelligent Metasurfaces (SIM), which extend the RIS concept to multilayered systems, present significant modeling and optimization challenges. This work addresses these challenges by introducing an optimization framework for SIM that, unlike previous approaches, is based on a comprehensive model without relying on specific assumptions, allowing for broader applicability of the results. We first present a model based on multi-port network theory for characterizing a general electromagnetic collaborative object (ECO) and derive a general framework for ECO optimization. We then introduce the SIM as an ECO with a specific architecture, providing insights into SIM optimization for various architectures and discussing the complexity in each case. Finally, we analyze the impact of commonly used assumptions, demonstrating that employing a complete model-one that does not rely on the unilateral hypothesis and accounts for mutual coupling among SIM elements-can yield better performance, using the realization of a 2D DFT as a case study.