Space might be vast, but HABITABLE planets are few and far in between said space. So, key ships are stationed as needed.

Not to mention, you have planetary defenses that are automated, as well as a number of fighter craft. Also, I think that while each planet in the Federation joins the Federation for mutual benefit, isn't it the case that each planet also maintains its own autonomy, and presumably its own military, as well?

For example, in TMP, you have Spock traveling in a Vulcan designed shuttle. We also know there was a Vulcan fleet, an Earth Fleet, and an Andorian fleet in Enterprise. Does the creation of the Federation and Starfleet necessarily mean those individual miltaries go away? Isn't it possible that each planet still maintains its own military ships within its on solar systems and colonies, external to Starfleet, or even as an auxiliary force to Starfleet (IE like Naval reserves, Nation Guard, etc)?