The impressive 16th-century metropolis was ingeniously conceived to give its defences an advantage against would-be invaders.