Whilst beneficial bacteria do live in the substrate and on plants, glass and other hard surfaces in the water, the vast majority lives in the filter because there is more water movement, oxygen and a really nice home called filter media. The filter is also dark (usually brown or black) and this reduces the light getting in. Filter bacteria don't really like light so a dark filter with a sponge is going to house a lot of beneficial bacteria than gravel that is exposed to light.
A lot of bad bacteria, fungus, protozoa and viruses live in biofilm on the glass and in the gunk in the gravel. They also grow rapidly in the water column. A well maintained filter will house plenty of beneficial bacteria, while regular gravel cleaning, water changes and wiping the inside of the tank down will go a long way to reducing the number of harmful pathogens in the aquarium.