Monemvasia: All this stuff just to protect from someone

It’s around mid of April 2022 and I’m doing some sightseeing in Monemvasia.

Essentially it’s a big rock and humans built a town in it. Yes, it’s more in than on it, I would say. It’s the first time on my journey, that I’m at a place where a lot of other people are around. Real, classic sightseeing at a pretty commercialized place. I’m walking through the small alleys, passing the souvenir shops and restaurants. They are cute but quickly I’m leaving the lower part and start climbing to the upper part of the big rock. From the above, I have a good overview and I’m thinking about how much effort it takes to build all this. And has there been a plan on how to build it or did they just start and over the centuries it came all together? And what had been their primary motivation? Did they build all this just to protect from someone?