That is a very good question, for me it is one of those topics where it just falls into place. You could figure out a brand name before you even start your project, or it could come towards the end.
It took me weeks to figure out a good brand-able name and the way i did it was through elimination. I make a good list of about 10 or so domains and continue eliminating from there. I will use domain searches until i find ones that aren't registered.
I have also had luck finding domains for sale under $100 on godaddy market before that I ended up purchasing as well. A lot of domains here are let go by people who forget to renew them.