Fruit flies are plentiful when there is lots of refuse or garbage around your house.
Fruit flies are smaller than the average fly and are easy to spot because of their yellowish body tone and bright, red eyes. They breed in septic and sewer systems and places that have large piles of garbage or plant refuse. They also hover around the ripe and old fruit and veggies. Though fruit flies like to hover around old and rotted plants, they can also be attracted to growing plants and vegetables. Fruit not only feeds on plants but also grows eggs in the fruit. Imagine harvesting your favorite plants only to have maggots feasting on your favorite fruits and veggies from the inside.
To get rid of fruit flies, organic pesticides are known to eliminate all kinds of flies. Natural pesticides are best when getting rid of any pest to avoid harming plants and domestic animals. You can use various home remedies to eliminate grubs and larvae that turn into fruit flies. You can also keep the fruit fly population down by keeping your garden free of any leftover compost. Those who make large amounts of compost should not leave their compost out in the open to not attract unwanted insects and animals.
Fruit flies especially love to thrive in deep, rich rotting compost.
So if you do compose significant amounts of plant refuse, then cover it up with plastic wrap or find a way to eliminate any excess material to avoid fruit fly population growth. If you have a septic system, ensure that your tank is cleaned every month to prevent fruit fly infestation. You can use various powders to flush your toilet and break down debris build-up in your septic tank.
Source of Information on Fruit Flies
https://www.tnnursery.net