This thesis presents several new insights on the interface between mathematics and theoretical physics, with a central role for Riemann surfaces. First of all, the duality between Vafa-Witten theory and WZW models is embedded in string theory. Secondly, this model is generalized to a web of dualities connecting topological string theory and N=2 supersymmetric gauge theories to a configuration of D-branes that intersect over a Riemann surface. This description yields a new perspective on topological string theory in terms of a KP integrable system based on a quantum curve. Thirdly, this thesis describes a geometric analysis of wall-crossing in N=4 string theory. And lastly, it offers a novel approach to constuct metastable vacua in type IIB string theory.