Biodiversity results from differentiation mechanisms developing within biological populations. Such mechanisms are influenced by the properties of the landscape over which individuals interact, disperse and evolve. Notably, landscape connectivity and habitat heterogeneity constrain the movement and survival of individuals, thereby promoting differentiation through drift and local adaptation. Nevertheless, the complexity of landscape features can blur our understanding of how they drive differentiation. Here, we formulate a stochastic, eco-evolutionary model where individuals are structured over a graph that captures complex connectivity patterns and accounts for habitat heterogeneity. Individuals possess neutral and adaptive traits, whose divergence results in differentiation at the population level. The modelling framework enables an analytical underpinning of emerging macroscopic properties, which we complement with numerical simulations to investigate how the graph topology and the spatial habitat distribution affect differentiation. We show that in the absence of selection, graphs with high characteristic length and high heterogeneity in degree promote neutral differentiation. Habitat assortativity, a metric that captures habitat spatial auto-correlation in graphs, additionally drives differentiation patterns under habitat-dependent selection. While assortativity systematically amplifies adaptive differentiation, it can foster or depress neutral differentiation depending on the migration regime. By formalising the eco-evolutionary and spatial dynamics of biological populations in complex landscapes, our study establishes the link between landscape features and the emergence of diversification, contributing to a fundamental understanding of the origin of biodiversity gradients.