Mechanical reliability is a critical issue in all forms of energy conversion, storage, and harvesting. In Li-ion batteries, mechanical degradation caused by the repetitive swelling and shrinking of electrodes upon lithiation cycles is now well recognized; however, the impact of mechanical stresses on Li transport and hence the capacity of batteries is less obvious and underestimated. In particular, the stress field within the heterogeneous electrodes is complex, making the characterization of the chemomechanical behaviors of electrodes a challenging task. We develop a finite element program that computes the coupled Li diffusion and stresses in three-dimensional composite electrodes. We employ the reconstructed models of both cathode and anode materials to investigate the mechanical interactions of the constituents and their influence on the accessible capacity. The state of charge in the percolated particles is highly inhomogeneous regulated by the stress field. An ample space of design is open for the optimization of the capacity and mechanical performance of electrodes by tuning the size, shape, and pattern of active particles, as well as the properties of the inactive matrix.