Biofilms are ubiquitous in natural and engineered systems. They are characterized by a complex ecological and structural heterogeneity, where structural heterogeneity refers to morphological and mechanical properties. This dissertation explored the effects of structural heterogeneity on biofilm behavior in treatment systems, where the heterogeneity arose from biofilm growth, mechanical deformation, and detachment. In this study, three novel topics were addressed regarding biofilm heterogeneity: effects of morphological heterogeneity on counter-diffusional biofilms, the development of a biofilm model capable of predicting deformation and detachment, and the determination of spatial distribution of biofilm mechanical properties. Counter-diffusional biofilms are relevant to novel treatment processes, such as the membrane biofilm reactor (MBfR). This research used mathematical modeling and experiments to evaluate the effect of morphological heterogeneity and fluid dynamics in MBfR biofilms. Results showed that, unlike co-diffusional biofilms, conversion rates increased with morphological heterogeneity and were higher than for co-diffusional biofilms under similar conditions. A novel biofilm model was developed using an energetic variational approach and phase-field method to simulate biofilm mechanical response to fluid flow. The model simulated the viscoelastic behavior of biofilms and the heterogeneous distribution of biofilm components, allowing for the input of the mechanical properties of individual biofilm components. Using phase-field coupling and energy conservation, the model simulates biofilm deformation based on continuum mechanics, and also simulates detachment due to cohesive failure. The model predicted that higher extracellular polymeric substance (EPS) viscosity provided greater resistance to biofilm deformation. Higher EPS elasticity resulted in the formation of streamers with structures more prone to detachment. A novel energy-stable numerical scheme was developed to solve the model system efficiently. Applications of the model include streamer formation and the effect of biofilm disrupting agents on biofilm mechanical response. A noninvasive approach to map biofilm mechanics at the microscale was developed and applied. The distribution of mechanical properties and the effect of environmental conditions on biofilm mechanics were evaluated. Experiments revealed greater mechanical heterogeneity in biofilms grown under low flow shear, and more rigid properties when grown under higher flow shear or in presence of cross-linking agents.