Vitiligo is an autoimmune disorder marked by melanocyte destruction and skin depigmentation. To explore the molecular mechanisms underlying melanogenesis and their link to vitiligo. We analysed three vitiligo-related datasets, correcting for batch effects with ComBat. Key melanogenesis genes were pinpointed using LASSO and logistic regression, and a nomogram was developed. The immune microenvironment was evaluated by ssGSEA, and correlations between gene expression, melanogenesis pathways, and immune cell infiltration were examined. We identified 2,405 DEGs, with 960 up-regulated and 1,445 down-regulated genes in vitiligo samples. GSVA indicated significant disturbances in melanogenesis pathways. ssGSEA revealed reduced activity in REACTOME_MELANIN_BIOSYNTHESIS and KEGG_MELANOGENESIS pathways. Three key diagnostic genes (CALM2, KIT, OCA2) were found and used to build a highly accurate predictive nomogram. Immune cell analysis showed increased T helper and Th2 cells in vitiligo, correlating with both diagnostic genes and melanogenic pathways. This study identifies crucial melanogenesis-related genes and provides a predictive model for vitiligo risk. It underscores the relationship between impaired melanogenesis and immune cell infiltration, suggesting potential therapeutic targets.