I'm writing this in Mogadishu, the capital of Somalia.

This, of course, is a place that for the last few decades has seen more than its fair share of political turmoil and war.

In 2011, at the height of Somalia's famine, Turkish Prime Minister Recep Tayyip Erdogan arrived here to a near hero's welcome.

"Soo dhawoow Turkey" –Welcome Turkey – proclaimed the slogans on the banners and flags of the crowds that turned out.

Some Somali mothers even promised to name their sons Tayyip and their daughters Istanbul in honour of the first non-African premier to visit beleaguered Somalia in 20 years.

"The tears that are now running from Somalia's golden sands into the Indian Ocean must stop," declared Mr Erdogan in the wake of his emotional visit. The plight of the Somali people and how the international community responded was a "litmus test for our modern lives," insisted the Turkish premier.

Over the last week or so, Mr Erdogan has been facing a political litmus test of his own much closer to home in the heart of Istanbul, Ankara and other Turkish cities, as mass protests against his government's policies have gripped the country.

Yesterday, as Mr Erdogan headed back to Turkey from yet another visit to Africa, the violent protests showed no signs of abating, with the death of a Turkish policeman in southern Adana Province and the organisation of yet more mass rallies.

But just how serious a threat do the current demonstrations pose for Mr Erdogan and his Justice and Development Party (AKP)?

What are the key factors worth watching as clues to the outcome of this political standoff, which has given European and US political leaders the jitters as they monitor a deteriorating situation in neighbouring Syria?

To begin with, there is no doubt that the rapid escalation of anti-government protests in Turkey has exposed a number of long-dormant fault lines in the country's complex political landscape.

Despite its traditionally secular ideology and its reputation as a model of Muslim democracy, many within the country fear a growing Islamisation.

Along with this there are concerns Mr Erdogan's rule has become increasingly autocratic. Dissent is rarely tolerated and coercive measures including arrests, investigations, tax fines and imprisonments have become more widespread.

While Turkey on many levels has prospered under Mr Erdogan and the AKP, both over the last decade have firmly established an informal, powerful coalition of party-affiliated businessmen and media outlets whose livelihoods depend on the political order Mr Erdogan has constructed.

As far as the challenges thrown down to this by the recent demonstrations go, they have certainly exposed the extent to which Mr Erdogan's future political ambitions are limited.

Currently he is trying to extract votes from a lethargic and extremely fragile peace process with the Kurdistan Workers' Party, to help him gain enough support for a constitutional referendum that would transform Turkey from a parliamentary system to a presidential one, thus enabling Mr Erdogan – whose term as prime minister expires in 2015 – to continue leading Turkey as president beyond 2014, when presidential elections are scheduled.

The problem with this ambition is that on the streets of Istanbul, Ankara and elsewhere, protesters from the pro-Kurdish Peace and Democracy Party (BDP) have been seen allying themselves with supporters of Turkey's main political opposition, the Republican People's Party.

Given this, it's doubtful Mr Erdogan can rely on securing Kurdish votes in the forthcoming constitutional referendum.

However, the Kurdish dimension is only one of the critical factors worth watching for clues as to where this standoff might lead.

The backlash from pro-Erdogan supporters; divisions within the demonstrators' ranks; the behaviour of the powerful business community and above all the Turkish Army are all critical. On Wednesday there were the first signs of clashes between pro- government and opposition groups in the Black Sea Port of Rize.

Also, while the 250,000-strong Confederation of Public Workers' Union became involved in the demonstrations calling for strikes this week, it is statements and actions from Turkey's influential business associations and other large unions in reaction to the protests that may bring even greater pressure on Mr Erdogan.

Despite such possible solidarity, there remain deep divisions across the opposition movement, from young environmentalists to older leftists and secular elites. There are even far-right ultra-nationalists within the opposition ranks from the Nationalist Movement Party, or MHP; and minority Alevis, whom Mr Erdogan has offended by naming the planned third Bosphorus bridge after Sultan Selim I, the Ottoman sultan responsible for massacring their Alevi ancestors. As ever, though, it is Turkey's all-powerful army that is worth watching most. So often in the past they have called the political shots.

According to US-based independent intelligence monitoring group Stratfor, there have been reports of military personnel distributing gas masks to protesters in Istanbul, and soldiers have taken in injured protesters at the military hospital near Taksim.

Signs the army is playing an increasingly active role in backing the protesters would be a significant development, but its more likely the Turkish military will try to avoid being put in a situation whereby Mr Erdogan calls on it to intervene.

All in all, this is far from being the "Turkish Spring" some have suggested. Some analysts have pointed out that recent events in Turkey remind them more of May 68 in France, with a conservative democratically elected leader simply out of touch with urban youth.

Mr Erdogan may ride out the storm, but serious challenges to his rule will remain.

Writing recently in the influential magazine Foreign Policy, Steven A Cook, a senior fellow for Middle Eastern Studies at the Council on Foreign Relations, says that while Turkey's current crisis will not bring down the Government, "it will reset Turkish politics in a new direction".

The crucial question, he says, is whether the AKP will learn some important lessons from the people in the streets or "continue to double down on the theory that elections confer upon the government the right to do anything it pleases".

While Mr Erdogan will continue to be seen by many as an autocrat at home, here in the Somali capital he and Turkey can do no wrong.

Not only is Turkish Airlines the first international airline to fly direct to Mogadishu, but Ankara is playing a major role in Somalia's reconstruction, rebuilding bomb- blasted streets, schools and hospitals from the ashes of war.

For the time being, Mr Erdogan can at least take some consolation from that.