Biodiversity results from differentiation mechanisms that are largely influenced by the features of the landscape over which populations are distributed. Notably, landscape connectivity and habitat heterogeneity constrain the movement and survival of individuals, thereby promoting differentiation through drift and local adaptation. Nonetheless, the complex topology of landscapes can blur our understanding on how they regulate differentiation. Here, we construct from first principles a stochastic, individual based model where the landscape is explicitly represented as a graph. We investigate both analytically and with simulations how the graph topology and the underlying spatial habitat configuration affect differentiation at the population level. Differentiation emerges from differences in local populations’ phenotypes, which consist of neutral and adaptive traits that are co-evolving. Using a macroscopic description of the dynamics developed in ref.  we demonstrate that a simple quantity, the habitat assortativity of the graph, conditions local adaptation. This has non-trivial consequences on differentiation mechanisms, and we show that habitat assortativity can amplify or dampen neutral differentiation depending on the migration regime. The approach undertaken provides a rigorous framework to study macroscopic patterns emerging from microscopic processes developing over complex structures.