When Russian forces closed in on Kyiv at the start of their invasion last year, the staff at Zavertailo, a popular bakery in the Ukrainian capital, shut up shop and began preparing free salads for the soldiers defending the city. Supplies dwindled as fighting raged around Kyiv, and the bakery’s finances collapsed as managers continued to pay staff salaries.

“Business completely came to a halt, and there were no revenues expected,” Anna Zavertailo, the bakery’s founder, said. “It took a lot of work to slowly restart the businesses.”

But it paid off. This spring, Zavertailo opened a second bakery in Kyiv, spurred by growing customer demand as life in the capital gradually adjusted to wartime conditions and returned to some semblance of routine. “New opportunities opened up to us,” Viktoriia Kolomiiets, Zavertailo’s chief operating officer, said.

The bakery’s expansion is part of a wider, albeit modest, economic recovery in Ukraine. Although Ukraine’s economic output is still considerably smaller than before the war — the economy shrank by one-third after Russia’s full-scale invasion last year — it will grow by an estimated 3.5 percent this year, the World Bank predicts. The expansion is driven by a pickup in domestic spending and underpinned by a steady flow of foreign financial aid.

Economists say it will take many years for Ukraine’s economy to return to prewar levels, and forecasts in a time of fierce fighting are bound to be uncertain. Enormous challenges lie ahead, including the costly rebuilding of the country’s devastated cities, a government deficit that will continue to balloon as the war drags on, and labor shortages caused by an exodus of Ukrainians fleeing the war and the mobilization of working-age citizens to fight it.

Still, local analysts and businesspeople say, a sense of resilience and relative stability has taken hold after nearly 20 months of war, improving confidence among consumers and investors.

“Ukraine’s economy is adapting to the war,” said Olena Bilan, chief economist at the Kyiv-based investment bank Dragon Capital. She added that people had moved from a “savings mode” to a situation where they now “feel more relaxed and start to spend more.”

The World Bank estimated in a recent report that private consumption in Ukraine would grow 5 percent this year, after contracting by more than a quarter last year. In cities like Kyiv and Dnipro, which are far from the combat zone but remain under threat from Russian air attacks, customers are returning to reopened restaurants and resuming shopping.

“Today, most Ukrainians understand that the war may be prolonged, and they need to continue living in these new circumstances,” said Andriy Cherukha, the founder of Etnodim, which produces vyshyvankas, the traditional embroidered Ukrainian shirts. He said sales in his shop had tripled this year compared with last, driven in part by a rise in patriotism.

Ukrainians, Mr. Cherukha added, “continue to work and purchase clothing and other items that may not be considered essential but are a way to maintain a sense of normalcy.”

Olga Kustenko, a co-owner of the First Point Espresso Bar in the trendy Podil neighborhood of Kyiv, said people needed routines to cope with the war. Customers have returned to her cafe, she said, because they look for a familiar place to spend time. She opened a second cafe this spring to meet growing demand.

The stronger-than-expected spending has prompted financial institutions to upgrade their economic forecasts. Last week, the International Monetary Fund predicted that the country’s total output would rise 2 percent this year, slightly less optimistic than the World Bank’s forecast but a significant upgrade from an initial forecast for a 3 percent decline.

To be sure, Ukraine’s economy is growing from a low base, after the first year of the war devastated the country’s main economic assets. The Azovstal steelworks, which accounted for one-fifth of Ukraine’s steel output, was destroyed in the fighting for Mariupol last year.

Growth rates can also be a poor indicator of a country’s economic health in wartime, as output is often inflated by military production, which is ordered up by the government. Ukraine’s government has devoted much of its budget to cover the army’s payroll and support arms production.

But economists say Ukraine’s ability to adapt to various wartime challenges, such as keeping the electricity flowing despite Moscow’s winter campaign against its energy infrastructure, has helped put the economy on a stabilizing path.

“We haven’t had any shortages of electricity since mid-February,” Ms. Bilan of Dragon Capital said. “That was the first positive factor that pushed output up.”

In another sign of resilience, Ukraine exported more than 110,000 megawatt-hours of electricity last month, a record volume for 2023, mostly produced at the country’s nuclear plants, although it remains a fraction of the country’s electricity exports before Russia started striking energy facilities.

Maria Repko, deputy director of the Kyiv-based Center for Economic Strategy, noted that the opening of new trade routes to circumvent Moscow’s efforts to block the Black Sea was also helping a rebound in agricultural exports, which made up the bulk of Ukraine’s prewar income.

The World Bank estimates that Ukraine’s overall exports will continue to shrink this year before growing 15 percent next year and 30 percent in 2025 — a potential economic lifeline if the war drags on.

Much like Russia’s, Ukraine’s economy is increasingly being restructured around war. More than half the government’s spending next year, roughly $46 billion, will be devoted to defense.

But with little tax revenue to finance this spending spree, Ukraine’s budget deficit will reach 21 percent of the country’s total output next year, the prime minister, Denys Shmyhal, said last week. He added that his government would need $42 billion in financial aid to cover this shortfall.

That sum may prove difficult to secure as support for Ukraine wanes in the United States, by far Kyiv’s biggest financial backer, and as the world’s attention is diverted by the war between Israel and Gaza. “The situation looks really worrisome,” Ms. Repko said.

Ukraine’s businesses are also facing labor shortages as men are drafted into the army, and as a result of the exodus of refugees after Russia’s invasion last year. More than six million Ukrainians — nearly 15 percent of the prewar population — remain outside the country, and nearly a quarter of them are uncertain whether they will return once the war is over, according to a recent United Nations survey.

At her bakery, Ms. Zavertailo said she was struggling to hire more staff, but months of war had taught her how to turn problems into opportunities.

Last year, the bakery asked customers to underwrite free coffee for soldiers — a way to support Ukraine’s fight while reviving its business. The program collected more than $40,000.

“We came up with several solutions that helped us stay afloat,” Ms. Zavertailo said, “providing us with the potential for further growth.”

Daria Mitiuk contributed reporting.