That's interesting about the real-life NASA stuff. So it's sort of a hybrid agency? Civilian leadership but with occasional military employees/missions?
No, it's a government agency that does whatever the hell the government tells it to do. The only reason they have to include military personnel on military missions is a legal technicality that bars civilians from participating in those kinds of operations (UCMJ and the Geneva Conventions, among others).
I figure Starfleet works more or less the same way, except the Federation has a different legal framework pertaining to the use of deadly force. In OUR system, for example, only military personnel empowered through an act of congress can legally use deadly force against foreign nationals, and they cannot use it AT ALL against our own citizens. Neither of those restrictions apply to Starfleet; we've seen them operating in a law enforcement capacity numerous times in Federation space (even on Earth, in fact) and they are fully empowered to use deadly force against Federation citizens for all the usual reasons. At the same time, they are ALSO empowered to engage in combat with alien forces for any reason they see fit, and in that regard are limited only by the Prime Directive.
I would even speculate that the Federation's definition of "war" is merely a declaration that the Prime Directive no longer applies to a particular government or a region of space. IOW, a letter to Starfleet Command saying "A Klingon fleet has conquered Organia; you are hereby authorized to interfere with the internal politics and development of Organia. Go interfere the fuck out of them."