Yesterday I was playing an older save, where there were five solar systems but only one really large one (The map was one of those huge maps), and I had eventually overrun every CPU in the system (I usually start out by allying myself with them then stab them in the back), but then one of the unfair CPU's came in from another star system, and pirates eventually ground my two huge fleets to dust. Now i only have 2 planets and an asteroid.
A moderate starbase or a few turrets should be enough to take care of any pirate raids... I think it's much easier to fight the pirates with static defenses, especially if you're on single-player, where the pirates have a tendency to attack the same planets - and frigates are much more fragile than combat structures.
So I decided to try and modify my strategy. I have been equally building up three fleets, because usually I just make two and eventually I tend to merge them. These are small, they have a lot of repair ships, one capitol, and a lot of strike craft and kodak ships.
This could be part of the problem... having three small fleets probably means that any of them could be relatively easily run over by an enemy player's main fleet, or maybe even the pirates. If you merge your ships together and keep them together you'll lose many fewer ships in whatever battles you fight.
As Darvin mentioned, a good composition is a lot of carriers/bombers (not fighters), along with a moderate number of Hoshikos and a few flak. Earlier in the game before massed carriers are a possibility, 40 or so LRM can work wonders against all but the toughest AIs.
I am also paying more attention to planet development and I have put a lot of points into industry, however that has caused me to neglect my warfare stuff. This has allowed me to make a LOT of credits, gold, and crystal.
If you want to economize, the best idea is to build as many trade ports as you can on as many planets as possible, once your fleet is big enough to fight off aggressors... after 30 minutes or so that should give you a huge income advantage, allowing you to build basically whatever you want and still win. Pervasive Economy, though expensive, can also help out a ton in those sorts of larger games.
usually as I get bigger I will take over the star system, and the star by anchoring four starbases plus a large fleet at the sun. I've found the pluses and minuses, especially when you divert the fleet.
Try relying on a fleet instead of on a starbase (or 4).