All condo/townhouse/planned unit developments basically handle HOA maintenance the same way. As defects are discovered by owners, those defects are presented in writing, (typically via contractor bids or inspection reports), and then the HOA board decides if and when to have those items corrected. Part of the HOA payment goes towards a Reserve account. This account is used for paying commons-area maintenance and repairs. If the Reserve account does not have enough money to cover a needed repair, then either a Special Assessment is charged to the owners or the HOA dues are raised to pad the Reserve account to pay for the repair in the future.

Hypothetical example for an established (not brand new, first sale builder units) complex: A 6-plex needs a new roof and that roof costs $60k:
* If the Reserve account has over $60k available in it, (this Reserve account accrues like a standard savings account since each month all owners pay their HOA dues a portion of those dues – usually called Mgmt on RMLS under the field of what the HOA includes – will go into Reserves), then the repair is scheduled and the roofer is paid by the HOA.
* If there is only $20k in the Reserve account and the repair cannot wait until the Reserve account accrues to $60k, then each of the 6 owners will have to pay a Special Assessment for the $40k needed – $40k divided by 6 = $6,667/owner. This money can be paid by each owner in one lump sum or in monthly payments determined by the HOA, as the HOA might need to get a loan for the balance.
* If the repair is necessary but not needed immediately – say the current roof will last another 5 years – then the HOA could decide to pad the Reserve account in anticipation of the repair. So they could increase the HOA dues for all owners immediately so that in 5 years the Reserve account will completely cover the cost.
Almost all HOA’s pay for a detailed inspection report every 10 years to assess the condition of the property and determine and plan for upcoming repairs. This keeps owners from being blind-sided by big ticket items and allows for a gradual padding of the Reserve account if the account balance is too low to pay for future maintenance/repairs.
For brand new, never-before occupied complexes, the roof, and all other elements are new. If defects are found they would be covered by either the builder’s warranty or the manufacturer’s warranty. Things that would not be covered by the HOA would be owner-caused issues or issues inside the units. All HOA’s have an exterior insurance policy. Each owner will also get insurance but this will be for the interior 4 walls of your particular unit.
Caveat: There have of course been instances where huge construction defects have been found in new developments. In these cases, the HOA files a lawsuit against the builder. These typically resolve with the builder’s insurance covering the damage, but they take years to settle and have sometimes not covered the full extent of the needed repairs. Owner special assessments come into play to pay the difference if this happens.
All of these potential issues exist in a SFR too, including brand new homes. But on those homes, the individual owner is responsible for paying for the repair entirely or using the warranty or going after the builder themselves. In a complex, the HOA divides up these costs amongst all owners and/or takes care of seeking remedies via the warranty or builder on behalf of all of the owners.