Before I begin, I should mention that many people on these forums, myself included, argue that starbase defenses are too weak to properly defend any starbase for the long term. Long story short, don't expect your starbase to survive anything with Doom Rays.
You're going to need ships and fleets if you want to keep them alive.
________________
You can install weapons and defenses onto a starbase by upgrading the starbase. To upgrade a starbase, you need a constructor (like the kind you use to make the starbase in the first place) and send it to the starbase. Once the constructor moves onto the same tile (called a parsec) the starbase is on, you should get a popup screen asking you if you want to install something (there should be an option that changes this). From there, click yes, and then you select the part you want to install.
Please note, some starbase modules require money (a positive amount) to install. Otherwise, it will say you can't install.
Also, you will likely want to have "Space Weapons" researched as it unlocks a starbase module, called "Battle Stations", that serves a prerequite for most combat starbase modules. You *will* need it at some point if you are serious about developing your starbase's weapons and defenses.