As someone who have one of the best defense systems, I'd like to add my two cents.
There are indeed many of clever thoughts I see here, but still there is something to be said.
It's theoretically possible to have a perfect defense, but, in practice, it's extremely hard to write. First of all, you need time for coding, and, more importantly, you need test cases for your code. On other words, you need someone to attack your rooms. The stronger the attack is, the better defense you can create.
I was lucky enough to be attacked by one of the most capable raiders (of course, in times of that battle I didn't see it this way, but now I do), but this is rare. And without a good attack on you, there are too many things you need to consider, too many things could go wrong... and you have no motivation to do it.
Terminals? Go ahead and overflow them all with some cheap mineral, it's extremely unlikely that anyone has a code to detect this kind of attack and create market orders to free his terminals. Be creative! As said before, an attacker have the advantage of being proactive, he is able to find a breach or uncovered case. Like, throw a nuke into a wall. Boosted repairers spawned? Ok, throw a nuke into labs block (not many people cover them with ramparts everywhere). Rampart construction sites didn't appear? Congrats, you just found a breach.
The game mechanics are deep. It's always possible to find a way to fool any defense, and the only way to have a perfect defense is to experience all kinds of attacks ever possible (and if a defender survived them all... he probably deserve to sleep well). The only perfect defense is a defense that being upgraded.