Base defense and base layout is an ever changing puzzle in WC:RA. There is a never ending battle going on between attackers and defenders. How much metal you are able to hold on to is partially about base defense and partially about how intimidating your base looks. There is absolutely no magic formula to protecting your base. There are players who can and will crack it. Your goal is to keep your base defense above 80% or so.
The best way to understand why you are losing base defenses is to watch replays. Take note of how the enemy made his line of approach. Where did they start with their units? Which turrets and buildings did they eliminate first? Is there a way you could have protected those better? Did they use units your base could not counter? You can also have a friend who is not in your alliance take screenshots of your base. This will show you where the enemy is able to deploy their units.
In general you will be more likely to successfully defend your base if your defensive buildings are able to get your defender units out. With that idea in mind your base layout should, in general, work around the idea of protecting your war factory, helicopter pad and barracks. Usually you can protect 2 of the 3 buildings well. You will usually see two types of platoons that make attacks on your base. The first is a ground assault with tanks backed up by dps ground units. The second is a more airborne assault with tank and dps helicopters. In general it's hard to construct a base that can counter everything but by giving thought into defender units that are good vs. one type of assault and turrets to protecting from the other you can start to construct a base that is a solid defender.
The war factory will pump out light vehicles and tanks for you along with M270s later. These vehicles are great against an attacking platoon that is mostly ground based. The sustained dps and aoe vehicles do little damage to helicopters however. Tanks do none. The building is primarily there to produce anti ground units. Consider protecting this building more if your turrets are focused on air defense (flak, machine guns, salvos)
The helicopter pad will produce helicopters. Until the introduction of snipers is was the most useful building for protection against ground assaults. A smart player will bring snipers or some other type of infantry to stop your helicopters. That doesn't mean it's not worth protecting. Again like the war factory this building it primarily useful against ground assaults. Consider giving it more protection if using primarily anti-air type turrets.
The barracks is the most flexible of the defensive building structures. There are a wide variety of units that can be placed in this structure. Machine gunners and snipers do great helping with anti air and against helicopters. Mortermen and later MAWS teams will rip up lightly armored ground units. Use the flexibility of the units you can put in the building to your advantage. If your base is already geared toward heavy ground defense consider putting some anti air in this structure. If already heavy on anti air consider some extra anti ground units.
Once you have your defensive structures and units located and filled it's time to look at turret placement and type. Ideally you want to use your turrets to protect your defensive buildings. This will all be covered in more detail in the turret placement section of the wiki.
Once turrets are placed walls and mines can then be added in to block lines of approach. Walls can also be used to protect turrets and defensive buildings from attacks from thunderbolts and raptors. If you place a wall directly in front of the common line of approach for a thunderbolt the wall will take some of the damage for your turret. Depending on the level of wall, turret platform and thunderbolt the turret may survive an attack because of the wall in front of it.
Contributor - Azragaul