If it is a newly discovered substance, it will be more troublesome. In this respect, we can start with the structure of matter.
For example, if the substance is a polyketide (many secondary metabolites belong to polyketide), then the gene cluster that synthesizes the substance must contain PKS or NRPS gene, and then the corresponding PKS or NRPS gene can be found by genome comparison according to the conserved region of PKS or NRPS gene, and then several interference items can be eliminated by analyzing the functional domain of PKS or NRPS gene, and finally accurate location can be achieved by gene knockout or RNAi.
I heard the above example in the lecture, so I can only say it roughly.
There are many related documents. We can find several substances with the same structure, and then search for Chinese reviews, from which we can find the research progress of this substance.
I have an article about mevastatin here for your reference:
Research progress of mevastatin biosynthesis gene cluster