Spatial omics holds great potential to elucidate tissue architecture by dissecting underlying cell niches and cellular interactions. However, we lack an end-to-end computational framework that can effectively integrate different spatial omics tissue samples, quantitatively characterize cell niches based on biological knowledge of cell-cell communication and transcriptional regulation pathways, and discover spatial molecular programs of cells. We present NicheCompass, a graph deep learning method designed based on the principles of cellular communication. It utilizes existing knowledge of inter- and intracellular interaction pathways to learn an interpretable latent space of cells across multiple tissue samples, enabling the construction and querying of spatial reference atlases. NicheCompass learns the activity of an interaction pathway by modeling the process through the lens of cells receiving and processing signals from their tissue microenvironment, using a variety of mechanisms involving metabolic interactions, ligand-receptor interactions including downstream regulation, and regulons. In addition to leveraging existing knowledge, NicheCompass can learn novel spatially variable gene programs to model variation in the tissue. We showcase a comprehensive workflow encompassing data integration, niche identification, and functional interpretation, and demonstrate that NicheCompass outperforms existing approaches. NicheCompass is broadly applicable to spatial transcriptomics data, which we illustrate by mapping the architecture of diverse tissues during mouse embryonic development, and delineating basal (KRT14) and luminal (KRT8) tumor cell niches in human breast cancer. Moreover, we introduce fine-tuning-based spatial reference mapping, revealing an SPP1+ macrophage-dominated tumor microenvironment in non-small cell lung cancer patients. We further extend NicheCompass to multimodal spatial profiling of gene expression and chromatin accessibility, identifying distinct white matter niches in the mouse brain. Finally, we apply NicheCompass to a whole mouse brain spatial atlas with 8.4 million cells across 239 tissue sections from four mice, demonstrating its ability to build foundational, interpretable spatial representations for entire organs. Overall, NicheCompass provides a novel end-to-end workflow for analyzing large-scale spatial omics data.