Typically, depending on location:
building and equipment are bought on bank loan that should get paid back within 2 years or at least the building space is on rent/lease
the coffee is bought in bulk for cheaper and they upsell by at least 70%. So if your cup of coffee costs 3$US, it probably took them 1$US-1.50$US worth of beans to make.
Same for pastries.
Once the food is paid off through sales, everything else is profit, minus rent and loan payback. It's not easy, but possible.