The terror attack on the Bardo Museum in Tunis, which cost more than 20 lives, has thrown Tunisias fragile security situation under the international spotlight.
The low-intensity violence along its borders with Algeria and Libya, the increasing visibility of extremist groups such as Ansar al-Sharia and the arms caches discovered by security forces were all signs of its deterioration.
Support and recruitment for extremist groups, although still small, is related to inequality and deprivation in the underdeveloped interior of Tunisia, and the city suburbs its desperate inhabitants migrate to.
Protests continue in these areas because economic conditions have deteriorated since the 2011 revolution. The interior is most affected by unemployment, which sat at 15.2 per cent nationwide in the first quarter of 2014, down from a peak of 18.9 per cent at the end of 2011. GDP growth flatlined after the revolution and only climbed back to 2.3 per cent by the third quarter of 2014. Inflation, meanwhile, is running at more than 5 per cent, according to the Tunisian National Institute of Statistics.
Tunisia is the only country affected by the regional uprisings to have arrived at a functioning democratically elected government, thanks to four years of negotiations and consensus deals. But the security situation and stagnant economy are challenges to Prime Minister Habib Essids unity government. The broad coalition, which includes Islamists, had raised hopes that it could push necessary legislation through parliament, but senior partner Nidaa Tounes has fallen into internal bickering.
It will also be a defining moment for President Beji Caid Essebsi, who has promised a war against terrorist groups and increased resources for the security services. But the risk on the other side is a slide into soft authoritarianism as rights are compromised in the name of counter-terrorism.
At the moment the Bardo attack began, the Assembly of Peoples Representatives (ARP), in a neighbouring building, was debating a terrorism and money-laundering law. Essid had already identified the law as his highest priority.
The Tunisian army is fighting a guerrilla war with extremist groups including the Okba bin Nafaa Brigades around Chaambi Mountain in western Tunisia. Armed clashes near the Libyan border and smuggling of everything from food to drugs to weapons has led authorities to periodically close the border. But this caused unrest in the southeast as livelihoods depend on this petty trade.
The biggest threat to Tunisian security is Libya, says William Lawrence, North Africa project director at the Belgium-headquartered International Crisis Group. The situation there hurts Tunisias security and budget, so it needs to invest politically and take a mediating role.
The Libyan Ansar al-Sharia militia has links with its Tunisian counterpart. Meanwhile, the allegiance of several Libyan militias to the jihadist group Islamic State in Iraq and Syria (Isis) brings the worrying possibility of their expansion across the porous border into Tunisia.
But it appears that most attacks in Tunisia are the work of local groups, with their base in remote areas and the poorest suburbs of large cities. Tunisia is also one of the largest sources of foreign fighters in Syria and Iraq.
Both the Tunisian Ansar al-Sharia (declared a terrorist organisation in 2013 following several riots and the assassinations of two opposition politicians) and the Okba bin Nafaa Brigades have publically aligned themselves to Isis, but it is unclear if there are operational links.
The steady stream of military casualties suggests the army is struggling to eradicate their presence around Chaambi Mountain. Border control and preventative operations have also failed to be very effective.
The security services conducted mass arrest campaigns targeting Islamists, says Firas Abi Ali, country risk analyst at the UKs IHS. However, these arrests seem to have been very broad and not based on specific intelligence. Without more effective intelligence capability, and given the policy of mass arrests of individuals with radical sympathies but who are not active in any attacks, the risk in Tunisia is likely to grow.
Essebsis commitment to increase resources for the security forces following the Bardo attack may improve their performance. His speech also emphasised democracy, but an increased focus on security and police powers brings the risk of a fall back into authoritarianism.
Finding the optimal balance between security and liberty, where you achieve security without giving up the few liberties Tunisia has gained in the past few years, is a challenge, says Wadia Haddaji, financial market specialist and member of the Tunisian Network of Experts for Successful Society (TUNESS) think-tank.
This will become more difficult as Tunisia desperately needs structural reform to reduce its spiralling public debt, which amounts to 52.9 per cent of GDP, and fiscal deficit of about 8 per cent of GDP, according to the IMF. The long-term reforms to subsidies, banking and investment laws necessary to achieve this will face resistance among the population.
Short-term macro-economic stability is a priority, so the three key areas are sustainable growth; the current account deficit, which is a major problem; and unemployment, which continues to rise, especially for youth and women, where rates reach 30-35 per cent, says Bechir Bouzid, economist and chairman of TUNESS. The biggest challenge is how to implement reforms, many of which will unfortunately imply significant budget cuts, while ensuring protection for the most vulnerable. Thats the dilemma the government faces.
There is a consensus that reforms to the subsidy system, banking, tax and investment laws are needed. Subsidies on food, fuel and utilities represent about 7 per cent of GDP, according to the IMF, but ensure the survival of the most vulnerable sectors of the population. A more targeted system is required, but is a sensitive issue.
The groundwork for the banking reforms was laid under Mehdi Jomaas interim government. Non-performing loans (NPLs) reached 21 per cent of banks loan portfolios, according to the IMF. The effect of the NPLs is to prevent banks from lending to businesses which in Tunisia is the only source of finance due to a lack of venture capitalism and stock markets and stifle the flow of capital through the economy.
Taxation reforms would improve the states fiscal base, as many businesses, especially in the large informal sector, pay no tax.
The light manufacturing sector, favoured in the era of former president Zine el-Abidine Ben Ali, relied on strong demand in Europe, so its malaise is forcing Tunisia towards diversifying its export market. Currently, the country relies heavily on tourism, which contributed 7.3 per cent of GDP in 2013, according to the UK-based World Travel & Tourism Council. A tentative rebound following the sectors post-revolution collapse will be severely affected by the Bardo attack.
The business environment, facing problems ranging from corruption to the investment code, needs overhauling to encourage both foreign and local investment. However, there are doubts about Nidaa Tounes willingness to tackle cronyism and corruption among business and political elites, given an important faction in the party is made up of figures from the Ben Ali regime, who could find their interests threatened.
They need to start creating an environment for entrepreneurship, an environment where our highly-educated youth can be innovative, but its a long-term project, says Haddaji. To lay the groundwork, we need strong institutions and laws to eliminate corruption, and to tackle trust issues around payment.
The strategic focus is likely to be on services and hi-tech industries, and attracting foreign companies to allow technology transfer. Tunisia has the advantage of a lower wage bill, although education reforms are needed to close the skills mismatch.
While these reforms should stimulate sustainable growth in the long term, more urgent measures need to be taken in infrastructure investment. This would ease unemployment, which remains stubbornly over 15 per cent, and stimulate economic growth.
For the unemployed, both young graduates and in the deprived interior, the conditions that provoked the revolution have only deteriorated since 2011. The most effective solution would be a massive investment in basic infrastructure, upgrading roads, water networks, schools and hospitals, with a focus on the interior. Decades of discriminatory development schemes have left a huge imbalance with the relatively prosperous coastal areas.
The only way for Tunisia to fund its economic recovery is to secure favourable loans from donor countries, whether Arab or Western. For this strategy to succeed, the government must formulate policies that satisfy both international financial institutions and the Tunisian population.
Tunisia needs direct budget support and loan guarantees to invest in development and infrastructure, says Lawrence. But donor countries are not providing the billions that Tunisia needs for the economy to recover and to keep the revolution on track.
Previous loans have been primarily spent on current expenses, namely subsidies and an inflated public wage bill, rather than capital investment, an issue that needs to be addressed before new loans are negotiated.
For the private sector, stability is a key concern.
Both international and domestic investors have a wait-and-see attitude and wont invest until they see the prospect of long-term stable governance, says Bouzid. Nothing can be achieved on the economic or political front without security.
Essids government will be judged on its ability to bring the security situation under control and kick-start the economy. Balancing the conflicting interests and priorities, internal and external, will be impossible without outside support and will require difficult, often unpopular decisions.
These challenges would be daunting for the strongest government, let alone one negotiated between competing factions and working in an untested political model. The possibility of its disintegration depends on the behaviour of Tunisias political classes.
Tunis needs to avoid a vicious circle of deteriorating security, which discourages investment, stifles economic growth and leads to more popular discontent.
All other variables depend on the countrys security, perhaps the most difficult challenge of all, given the instability across the region. In the short term, the response and international reactions to the Bardo attack will be pivotal.
These policies and measures are today more urgent to implement than at any time before, says Bouzid. The country is facing a critical moment and only honest political will and coordinated efforts involving internal and external parties can help Tunisia overcome the challenges and transition through this period.