Image copyright Getty Images

Singapore had been a master class in how to handle the Covid-19 outbreak.

Before the disease even had a name, the country had stringent travel restrictions and an efficient contact-tracing operation which contained the virus's spread.

But in recent days, the number of confirmed cases has rocketed. Thursday brought the highest day of new infections to date at 287, up from 142 the day before.

Mostly, these are coming from densely-packed migrant worker accommodation.

Having avoided it for months, Singapore is now under a partial lockdown, with schools and non-essential businesses closed, and people urged to stay at home.

Experts say one of the world's wealthiest nations - which seemed to be doing everything right - has important lessons for poorer countries, and there's still time to put them in place.

What was going well in Singapore?

Singapore had its first case of the new coronavirus very early on. It was a Chinese tourist who arrived from Wuhan on 23 January, the same day the virus epicentre was put into a total lockdown.

By the time the disease caused by the virus got its official name - Covid-19 - it was already spreading among the population here. But a well-rehearsed response was in place.

In addition to health checks at airports, Singapore carried out extensive testing of every suspected case; tracked down anyone who'd come into contact with a confirmed case; and confined those contacts to their homes until they were cleared.

WHO chief Tedros Adhanom Ghebreyesus called it "a good example of an all-of-government approach".

Image copyright Getty Images Image caption Everyone who arrives in Singapore now has to quarantine in a government facility for 14 days

For weeks, Singapore managed to keep its numbers low and trackable, with only small, easily contained clusters, without any real restrictions to daily life.

But Prof Dale Fisher, chair of the WHO's Global Outbreak Alert and Response Network and a professor at the National University of Singapore, told the BBC that whenever he heard people say Singapore was doing well, he'd reply: "So far."

"This is a really hard disease to contain," he says.

When did things start to get worse?

The system worked until mid-March, says Prof Yik-Ying Teo, dean of the Saw Swee Hock School of Public Health in Singapore.

That's when, as the gravity of the situation became clear around the world, countries started urging their citizens to get home.

Thousands returned to Singapore from countries which had not been as proactive - among them more than 500 people who unwittingly brought the virus back with them.

It was by then mandatory for returnees to stay at home for two weeks. But other people in their household were told they could carry on with their lives, as long as no-one showed any symptoms.

While new cases had been increasing incrementally, by mid-March there were many dozens a day. The majority were imported or linked to imported cases, but for the first time, not all domestic cases could be easily traced.

Prof Teo says it's easy to say with hindsight that it was a mistake to not limit returnees' interactions. But the reality is "right now, we know a lot more about the disease compared to back in March".

"We now know that asymptomatic spread is entirely possible - it does happen and could be the main driver of transmission for Covid-19," says Prof Teo.

Precisely because Singapore has kept such detailed records of all cases, it's been able to learn from the domestic spread.

"The measures have evolved with the understanding of where the cases are coming from," says Prof Teo.

That means, he adds, that countries should be cautious of relying too much on information we have now - for example, believing that people who've recovered are immune from future infection, when it is still far from certain that's the case.

What does Singapore tell us about where the virus spreads?

The problem of importation is now being dealt with by all new arrivals being sent directly to government quarantine. With a tiny number of people now entering, the number of imported cases has dropped into single figures in recent days.

And on Tuesday evening, Singapore passed a new law, which - although it's not using the term - is effectively a partial national lockdown.

Image copyright Getty Images Image caption Singapore's famous hawker centres are off limits for all but takeaways now

Everyone is prohibited from leaving their homes except for essential activities and exercise, with fines of up to S$10,000 ($7,000; £5,600) or six months in prison.

Prof Teo says this will be effective, and stresses that while there may still be an increase in numbers in the short term, it "is a reflection of what happened in the past seven days - it doesn't mean the measures taken are not working".

But the alarming exponential rise in the last week has been around Singapore's migrant worker population - the hundreds of thousands of men from poorer countries employed in construction, shipping, and maintenance.

Singapore is utterly dependent on these workers to keep its economy operating, but they are jobs in which social distancing is all but impossible.

On top of that, the workers are required by law to live in dormitories - privately-run facilities which house up to 12 men per room, with shared bathroom, cooking and social facilities.

It seems almost inevitable that these dorms would become clusters, and indeed they did. Close to 500 cases have now been confirmed in several dormitory clusters - one facility alone makes up 15% of all cases nationally.

Minister for National Development Lawrence Wong said on Thursday that if it had been known earlier how quickly the virus could spread "I would have done things differently", but that many workers continued at their jobs despite having symptoms.

The fear is that in the next week or so, these numbers will explode.

Prof Teo says what has happened in the dorms "is an indication of what will happen in some other countries, particularly the lower middle income, less well-resourced countries".

"All you have to do is look at many countries in South Asia, South East Asia, parts of Africa - there are many communities where the living conditions are very similar to dorms."

He says the need now is for all governments to look at their countries with "a frank and transparent lens" in terms of what they can do to "minimise the risk of an uncontrollable outbreak where people are living very closely packed together".

Prof Li Yang Hsu, also at SSH, says there is also a lesson going forward about social equality.

"The virus has been very efficient at highlighting to us the weaknesses of our societies - that's certainly the case for the migrant worker communities," he says.

The dorms exceed all international requirements for space per resident, says Prof Hsu, but a situation like this "just shows that they [the requirements] are inadequate".

"Perhaps a high income country like Singapore can do better to protect the health and improve the welfare of people that are so crucial to our society," he says.

Media playback is unsupported on your device Media caption The BBC visited a dormitory for 17,000 people in 2015

More than 24,000 workers are now confined to their dorms - on full pay and with meals provided. The government says it is also "aggressively" testing and has started moving some virus-free residents to empty properties or army camps to try to reduce the density.

Comparing the dorms to the cruise ships which have generated such large clusters around the world, advocacy group Transient Workers Count Too has called this "a risky strategy", saying the "infection rate in the dorm could increase dramatically" and has called for urgent action to provide better accommodation.

Manpower Minister Josephine Teo has committed to raising standards in dorms overall, calling it "the right thing to do".

Does Singapore show the virus cannot be contained?

Despite some accusations that it was too slow to bring about a partial lockdown, Prof Fisher says Singapore actually acted far earlier than other countries, while case numbers were still only just above 100 daily.

But for a lockdown to be effective, he says, three things need to happen. Firstly for transmission to stop - which will happen if everyone stays home. Then the healthcare system needs the time and space to recover - for beds to be freed up, and medical staff to be able to take time off.

"Third is to get all systems in place - all isolation facilities, quarantine capacity, laws, contact tracing.

"If you just do one and two and then you reopen, history is going to repeat," he warns.

Singapore is fortunate in this respect - unlike the UK and the US, for example, it has at no point seen its medical system overwhelmed.

It also has one completely dominant political party and a compliant media, but Prof Dale says even with "clear, crisp messaging to a community that trusts the government" he is concerned that "the average Singaporean still isn't quite grasping the importance of their individual role".

"They're probably saying yes Singapore should do this, but I am going to visit my mum."

Within the first two days of the new law, more than 10,000 warnings were issued for infractions like sitting down to eat in a food court instead of taking away, or socialising in public spaces.

For countries with bigger populations and more complex politics, it may be many weeks or months before they start to turn a corner.

All countries are looking for signs of hope, but the lesson from Singapore is that there is no room for complacency, and that all countries must be prepared to face a second - and possibly third or fourth - wave of infection.

Prof Teo says that if reported global coronavirus cases are a fair reflection of its real spread, "many countries still have a window of opportunity to really try to prepare", by ring-fencing their vulnerable or overcrowded communities and "trying to minimise anyone who has the disease interacting with communities".

"I can only say the world has to look at Singapore very clearly, particularly on the dormitory issue, and start exploring what is happening.

"We need to start preparing the world - even in Europe and America there are communities where people are living very closely packed together. What happens when Covid-19 enters?"