The Spacebase will be taken only after everything in space is destroyed. Ships appear from any of the 4 corners depending on the direction from which they come on the main map. When a player attacks you and wins, all of the defenses will be reset.
In most cases, the defenses in space will be useless because fleets have large hulls and large amounts of attack power. the best option for defense is a good offense with ships.
Four corners wall:
Build meteor stars, and particle cannons around each corner to prevent enemies from moving. This allows your fleet to go behind the wall and relieve the enemy of his ships. This is very effective because the enemy fleets will have to go through the wall first to get to your ships. (unless they are set to atk commanders or give highest atk)
Stack of cannons, Walled off starbase:
Make a huge section of particle cannons, thors and anti-air all in one place which will provide the most dmg while the enemy is near it. Most of your stars are surrounding your starbase in a huge box which blocks off 1 corner from the other. your ships go in here and will be moderately to highly protected from the enemy.
Randomly placed EVERYTHING:
One of the most effective measures to keep your enemies at bay is to plase every defense types all over the place and thors in key positions to waste the opponent's rounds. this can also make the enemy occupied with the defenses while your ships pick them off one-by-one.
Clustered starbase: (usual)
This is the most common countermeasure to enemy fleets, but also moderately effective in giving damage to the enemies. (If your defenses are high enough level) Just place high level defenses closest to spacebase and stars sorrounding it to wall the enemy off from all of your defenses. Most players start with this because they do not realize that most defenses are useless in most cases. Eventually, they will spread out.
Placing a box around your starbase that is around 5-7 in diameter lined with stars then particles will allow your fleets to fit inside and attack enemies without they themselves from being attacked. the Corners are the most likely attack target so thors should go in the middle of the entire box or in the middle of a side of the box.
Usually only used as a Pirate defences, this formation is obviously great against corp pirates. Place all defences in a fortress-like formation along one of the edges of your space base. Thors should be touching the edge, and surrounded by Particle cannons and Anti-aircraft cannons, with Meteor stars surrounding them all. It provides a good defence, and attack combination. Although space station defences arent a neccesity while defending from pirates, it does destroy some enemy ships. When doing pirates, all space station defences (excluding thors) should be lvl 7 or higher. All thors should be at least lvl 5, and you need to have at least 3 of them to provide maximum damage.
Block the entrances of your Space Base using stars and put defenses near those stars but make sure that their range reaches to the entrances. Place the thors, remaining stars, particle cannons, and anti-aircraft guns beside your space base to act as a contingency plan.