Spatial omics and multiplexed imaging technologies provide unprecedented spatial context to characterize molecular variation in complex tissues. Developing unsupervised computational pipeline in a discovery mode is of vital importance to interpret spatially resolved data and derive novel biological insights. We develop Stereo, a unified framework leveraging contrastive learning to jointly model molecular and spatial information in a self-supervised manner. Stereo consists of two modules, StereoCell for neighbor-aware cell identity inference and clustering on spatial transcriptomics data, and StereoNiche for biologically-relevant niche identification on spatial proteomics data. StereoCell uses graph attention to aggregate immediate neighborsβ content for each cell while StereoNiche exploits vision Transformer to explicitly relate position coordinates with marker readouts within certain receptive field. We validate StereoCellβs superior utility on both simulated and real transcriptomics datasets of brain tissues acquired by various technologies with different resolutions. StereoCell can operate on all genes, extract layer-specific signature genes at single-cell resolution and identify clear layer-wise structure with state-of-the-art performance. Applied on tumor tissue sections, StereoCell enables detailed characterization of intratumoral heterogeneity and reveals invasive or metastasis behaviors concordant with expert annotations. Evaluated on a multiplexed fluorescence imaging dataset for colorectal cancer (CRC) patients, StereoNiche refines niche assignments, recapitulates classical follicle structure, and validates enriched T cells-macrophages interdigitation. Via self-distillation operation, StereoNiche also enables extracting bounded layout of tertiary lymphoid structure with no supervision, representing classical Crohnβs-like reaction behavior. Local explanations are derived for a tree-based survival model to validate the clinical relevance of identified niches. For mass spectrometry profiled triple-negative breast cancer (TNBC) samples, StereoNiche recognizes differential tumor-immune interactions to separate compartmentalized from mixed pattern. In brief, Stereo is applicable to a variety of spatial technologies, serving as a powerful method to interrogate context-aware biological process and facilitate hierarchical signature discovery in neuroscience and computational pathology.