This paper investigates the natural convection and heat transfer behavior of a water-based nanofluid containing \(Ag, MgO,\) and \(F{e}_{3}{O}_{4}\) nanoparticles within a rectangular cavity. The cavity has dimensions \(L\) (length) and \(H\) (height), with horizontal walls divided into seven sections. Hot slits at temperature \({T}_{h}\) are located in the second and sixth sections of the top wall and the fourth section of the bottom wall, while cool slits at temperature \({T}_{c}\) are positioned in the fourth section of the top wall and the second and sixth sections of the bottom wall. The remaining sections of the horizontal and vertical walls are adiabatic. The study focuses on unsteady, laminar, two-dimensional, incompressible fluid flow, and explores the effects of heat sources, heat sinks, viscous dissipation, and a transverse magnetic field on heat transfer. The results provide insights into the influence of magnetic fields, viscous dissipation, and porous media resistance on heat transfer and fluid dynamics in ternary nanofluid-based systems. The system of partial differential equations governing the flow and heat transfer is solved using the Marker and Cell (MAC) method. The behavior of \(Ag, MgO,\) and \(F{e}_{3}{O}_{4}\) -water nanofluids within a rectangular cavity is influenced by various parameters, including the Rayleigh number \((Ra),\) heat source and sink parameters \((Q),\) Eckert number \((Ec),\) Prandtl number \((Pr),\) Darcy number \((Da),\) and Hartmann number \((Ha).\) These parameters are investigated graphically, with the streamlines and isotherms contours obtained using MATLAB software. Additionally, the effect on the average Nusselt number is also analyzed. The findings reveal that increasing Ra enhances heat transfer through stronger convection, while magnetic fields and porous resistance suppress thermal flow. Heat sources, sinks, and viscous dissipation further modify thermal gradients, influencing the Nusselt number. These results provide useful guidance for thermal system design in applications such as electronic device cooling, energy storage systems, and solar thermal management using nanofluid technology.