I gazed out the window onto a series of yellow, mud-brick cottages built on a slope, surrounded by verdant hills engulfed in a blanket of swirling fog. In the village of Masouleh, nestled deep in northern Iran’s Alborz Mountains, every view is a rooftop view.

Masouleh was built partway up a steep mountainside to keep the village safe from floods in the valley below and protect it from frigid winds that whip the summit above. But to conform to the steep incline caused by a 100m elevation change, residents had to find creative ways of optimising space. Indeed, the architecture of this roughly 1,000-year-old village is such that the front garden of each house – as well as restaurants, outdoor cafes and even parts of a bazaar – sits on the rooftop of the house below it.

You may also be interested in:

• A 10,000-year-old cave village

• Spain’s medieval clifftop skyscrapers

• Where houses are made out of diamonds

For centuries, the roofs of these houses, constructed from clay, stone and wood, have had to not only endure the wet climate (the region sees around 150cm of rain and snow each year), but also the weight of constant foot traffic – women hanging clothes to dry and merchants selling colourful scarves and handmade dolls from small stands along the alleyways. The guesthouse where I was staying, like many other homes in Masouleh, had a large window that spanned the front wall of the room to let in sunlight and warmth – one of the traditional techniques to contend with cold winters. (Many of the older Masouleh homes also have a winter room at the back of the building, insulated by the thick, clay walls.)

With a cup of tea in hand, I peered down into the slender passageways formed by the interconnected rooftops. I spotted a man carrying groceries from the bazaar up a winding staircase between two houses to his house in the upper levels.

“One never gets tired of this view,” my host, Mr Safayee, said as he joined me by the window.

Every view is a rooftop view

Masouleh has long been a trading hub; for centuries, people came from all around the region to sell their wares. And in the early 20th Century, the village was used as a stronghold by the Jangali Movement, which opposed the occupation of Iran by Ottoman, British and Russian forces. But while we sipped our tea, Mr Safayee lamented the gradual emigration of villagers to Iran’s more urban areas.

“When I was a kid, there used to be an elementary school here. We never had a large population, but we were all very close,” he told me. “Now, young people leave the village to other cities for work. Now we don’t even have the elementary school.”

Those who remain have profited from tourism. “It allowed us to have a good living, and to repair our old houses to the way they were,” Mr Safayee said.

With the rise of Masouleh as a popular tourism destination in Iran, the narrow streets can sometimes feel more reminiscent of a large city than a tranquil village. With the larger hotels located at the lower levels near the village entrance, many tourists seem content to stay near the bazaar, which is surrounded by rooftop cafes and restaurants. However, the higher levels tend to be more tranquil.

I finished my tea and set out to explore Masouleh. As I made my way up towards the top of the village, I glanced down to the valley, where a tour bus was slowly making its way up the inclined road to the base of the village, the point at which visitors would have to walk, as Masouleh’s alleyways do not support vehicle traffic.

Away from the crowds, I walked along the Barf-Andaz area, meaning ‘place to throw snow’. “Here in Masouleh, we shovel our snow onto the rooftop of the neighbour below us,” Mr Safayee had told me earlier that day, chuckling at my surprise. Because it is closest to the slope of the mountain, the 1-2m area at the back of each roof is the strongest part of the structure. This is where the shovelled snow is stored in the winter, thus minimising the chance of a roof collapse.

I made my way back down into the village towards the bazaar, a compact alley filled with shops selling handcrafted knives, mountain goat horns and an assortment of bracelets. Tourists perused the wares while locals went about their evening grocery shopping, stopping at vendors offering baked goods, dried fruit, homemade jam and mountain herbs such as chamomile and mint. I passed an elderly lady, who was winding yarn into the shape of a doll to add to the colourful bundle next to her.

“Would you like a doll?” she asked as her fingers expertly twisted the yarn to form the shape of a head. She told me that after her daughters had moved to the city of Rasht 70km away, she now makes the dolls that she once made for her daughters for visitors. I politely declined, and she bid me farewell.

I followed a stairway to the level above the bazaar, took a seat at a restaurant patio and ordered mirzah ghasemi, a flavourful Persian dish of squash, aubergine, garlic and egg served together like a stew. Here, I enjoyed an early dinner while the evening fog rolled in once more, permeating the streets and shrouding the village in mist.

Join more than three million BBC Travel fans by liking us on Facebook, or follow us on Twitter and Instagram.

If you liked this story, sign up for the weekly bbc.com features newsletter called "If You Only Read 6 Things This Week". A handpicked selection of stories from BBC Future, Earth, Culture, Capital and Travel, delivered to your inbox every Friday.