Castle walls contribute to the wall bonus soldiers stationed on the wall have. There are 5 levels of castle wall. All outposts and castles start at level 1 walls and will need to be upgraded. In order to build higher level towers and gates the castle wall must first be upgraded. However, not all towers must be upgraded to upgrade the wall. For example, in order to build a level 3 tower, the level 3 wall upgrade must first be purchased. However, in order to upgrade your wall to level 4, it is not necessary that all towers are fully upgraded to level 3. You can also buy, make, win, or be gifted wall tools to increase the wall protection.
The moat is the first line of defense. It is unlockable after level 37. Much like the walls, there are additional defensive tools to use on it. The strongest tool is called the fire moat, which increases moat protection by 110%. It is purchasable from the armorer for 86 rubies. You can also buy the castle moat for Rubies. Both also have a second level once you reach Legendary Level 250. You can also buy, make, win, or be gifted wall tools to increase the moat protection.
Moats can be purchased for 12,500 rubies. It gives a 20% extra defensive bonus and can be a bigger bonus if tools are used.
You can also build a Castle Gate, that increases gate protection by 20% a level, with an L5 Gate at 100%. You can also buy, make, win, or be gifted wall tools to increase the gate protection.