Two-patch compartment models have been explored to understand the spatial processes that promote species coexistence. However, a phenomenological definition of the inter-patch ‘dispersal rate’ has limited the quantitative predictability of these models to community dynamics in spatially continuous habitats. Here, we mechanistically rederived a two-patch Lotka–Volterra competition model for a spatially continuous reaction-diffusion system where a narrow corridor connects two large habitats. We provide a mathematical formula of the dispersal rate appearing in the two-patch compartment model as a function of habitat size, corridor shape (ratio of its width to its length), and organism diffusion coefficients. For most reasonable settings, the two-patch compartment model successfully approximated not only the steady states, but also the transient dynamics of the reaction–diffusion model. Further numerical simulations indicated the general applicability of our formula to other types of community dynamics, e.g. driven by resource-competition, in spatially homogeneous and heterogeneous environments. Our results suggest that the spatial configuration of habitats plays a central role in community dynamics in space. Furthermore, our new framework will help to improve experimental designs for quantitative test of metacommunity theories and reduce the gaps among modeling, empirical studies, and their application to landscape management.