The payment formula
Principal and interest come from the standard amortization formula M = P x i / (1 - (1 + i)^-n), where P is the financed balance, i is the monthly interest rate and n is the number of monthly payments. The monthly mortgage insurance premium is estimated separately and added on top.
Because interest is charged on the remaining balance, the first payment goes almost entirely to interest. On a $343,661 financed balance - a $337,750 base loan ($350,000 with 3.5% down of $12,250) plus a $5,911 upfront premium - about $1,861 of the first payment is interest at 6.5%.