It is unclear how different diets may affect human brain development and if genetic and environmental factors play a part. We investigated diet effects in the UK Biobank data from 18,879 healthy adults and discovered anticorrelated brain-wide gray matter volume (GMV)-association patterns between coffee and cereal intake, coincidence with their anticorrelated genetic constructs. The Mendelian randomization approach further indicated a causal effect of higher coffee intake on reduced total GMV, which is likely through regulating the expression of genes responsible for synaptic development in the brain. The identified genetic factors may further affect people's lifestyle habits and body/blood fat levels through the mediation of cereal/coffee intake, and the brain-wide expression pattern of gene CPLX3, a dedicated marker of subplate neurons that regulate cortical development and plasticity, may underlie the shared GMV-association patterns among the coffee/cereal intake and cognitive functions. All the main findings were successfully replicated. Our findings thus revealed that high-cereal and low-coffee diets shared similar brain and genetic constructs, leading to long-term beneficial associations regarding cognitive, body mass index (BMI), and other metabolic measures. This study has important implications for public health, especially during the pandemic, given the poorer outcomes of COVID-19 patients with greater BMIs.