How do you keep from being attacked, beef up your defenses like crazy?
pretty much make your self an unappealing target...if he'll lose more than he'll gain he won't bother.
once you get the tech in place start building up your defense..a good rule to follow is dump spare metal into missle launchers, yes they are small fry but they add up...someone will think twice about attacking a place with 100 or 150 missle launchers, build up your small lasers to high numbers as well.
there is a ratio for defenses (can't remember it off the top of my head)
the ratio for warships is...
10 light fighters per battleship
5 heavy fighters per battleship
1 cruiser per battleship
3 battleships per destroyer
my combat fleet so far
100 light fighters
50 heavy fighters
10 cruisers
10 battleships
I'm following the ratio exactly
you're all a long ways off from getting BB's I know, but it's something to keep in mind.
focus on getting small cargos, light fighters, and spy probes (spy probes are probably the most important ships in your fleet, and they're cheap too)