I always saw Starfleet as being the official operations agency of the Federation government, but that it didn't preclude various civilian organizations and institutes from doing their own thing (presumably under Federation law). As stated upthread, we've seen instances in which Starfleet and these civilian groups have worked together for various projects (one could argue that most, if not all, Federation starship designs are a Starfleet & civilian co-production, with civilian contractors doing most of the building, IMO).
And as was also mentioned upthread, space is pretty big. You can have Starfleet doing research on this astronomical phenomena here, while a civilian institute could be doing research on another astronomical phenomena there. Depending on what the research is being used for, it could either be kept as separate or joint projects. Civilian companies may also handle the carrying of cargo and/or passengers across the Federation and beyond, with some maybe even doing occasional delivery jobs for Starfleet when it might be a matter of better logistics or expediency.