You can use some of your bases defenses to attack any fleet within the base system
the defenses usable are laser, missile, phase and drones
each fire costs credits, need time to reload and time to hit the target based on the distance
fleets over its owner bases cannot be attacked
If a base get attacked, and its defenses damaged, that base production will not get the bonus from barracks if it is damaged.
And if the damage is above 50%, it will not possible to build marines at all until the damage is repaired bellow 50%.