There is, of course, something Starfleet can do to have more ships capable of defending the borders that we didn't do in the quest timeline. It's been repeated frequently enough in quest:
Don't spend significant amounts of Starfleet's shipbuilding resources on ships that can't fight.
People just don't like that answer.
This classic rejoiner also politely doesn't mention that ships that have more military parts have less ability to acquire more strategic resources. More torpedoes equals to more cost as well as less space for facilities like labs and so forth that prospect for more strategic resources, leading to less ships that are also each less capable in research and like.
Trade-offs exist! It's why we have voting choices!
Then there's the whole 'expansion of the member fleets, hell yeah' while also ignoring that if resources were used to expand the member fleets, Starfleet is necessarily smaller. This usually goes hand in hand with complaining about the existence of piracy problems et cetera, I have not kept track of exact posters but like - If Starfleet is smaller, wouldn't the piracy problems necessarily be worse?
It's all very frustrating. It's why my posts have been 'Sayle should just make us win forever', because tradeoffs and bad things happening are an important part of quests.
Here is the fundamental issue: For the Federation to have advanced technology, they need a culture that values science over other factors, hence science ships with weapon space dedicated to labs. For the Federation to have an impressive economy it must have a culture that values economy over other factors, hence engineering ships with lesser combat capability. For the Federation to have an open hand to the many cultures in the galaxy, it must have an inclusive diplomatic posture that necessarily is naive on some level.
edit:
An example right here is that by adding Aft Torpedoes, we have increased the cost of the ship by about 7%, with the 1 less module representing 1/6 = ~16.6% less effectiveness in science were this ship to have used that module for science (at 1 module = 2 science). The Darwin is in exchange a menace in combat. A trade-off was involved! 66% more torpedoes per ship (1.66x0.93 = 54% more torpedoes for the same cost) and 0.93x0.8333 = 77% of the science done for the same cost. Was it worth it? Quite possibly, yes. But the trade-off
existed. You can't argue that it doesn't exist.
edit 2:
This then raises the question of optimizing ships to fit in the valueset of [Military, Economic/Engineering, Economy/Science]. In my view, what we probably want is like, heavily-armed giant engineering vessels plus minimally armed economical science vessels. Why? Because labs go obsolete. Obsolete science ships are minimally good, obsolete engineering ships are 'merely' less good. So in the progress of time, we can expect engineering ships to stick around a long while and science ships to have runs that scrap much faster than an engineering vessel.
That means what we'd like is to produce as much science/research in the limited time period that a science vessel is useful - before the very technological advancement that they drive obsoletes them and we stop building or possibly even maintaining them. That suggests being frugal on their weaponry (especially torpedoes) is the way forward. More space, less cost. Engineering ships can be expected to stick around much longer so can justify being heavily armed. Plus engineering capabilities is much more useful than science capabilities in warfare most of the time, so it's actually quite a natural combination to be had.
Edit^3: Fixed science phrasing. Oops.