Barracks are the first line of defense of a base.
They have 2 functions: to protect the base against any attack, and to produce Marines.
Each Barracks level will also give 10% more Marine production (build faster).
Some defense structures have the ability to fire on OR at any ship within the base System.
The defenses that allow these ranged attacks are: Laser, Missile, Pulse and and Drones.
So you probably want to have some of those in each base. Each attack on a nearby astro costs credits.
Deflection Shields add shielding to all ground batteries, from Barracks to Disruptors. Planetary Shields or Starbase Shields will add shielding to all on orbit ships (owner only).
Base your defenses on the Base Economy. Low economy doesn't need big guns.
Unshielded base defenses (barracks to pulse batteries) will help any of your alliance member in orbit, so is is recommended that you build a few laser and missile batteries to both allow you to fire on any ship within the system and to help protect your mates.
Command Centers add extra 5% per level to all ships armour and power in orbit, to yours and your allies.
Also to the speed universes Command Centers, the 5% boost includes all base defenses.
The bases defenses will only prevent the base to be occupied, the Owner Economy can be pillaged if you dont have ships protecting it