Finance a car together?

I think there were already several problems, but I haven’t found the right Google search word combination yet to find an answer. I live with my friend and son for rent. Each of us works and we also earn about the same amount. Now my old car is already slowly scrapped after 15 years and we want to buy a new car. Theoretically I can finance this alone, but then I would have almost no “pocket money” left. So my friend would in 1/3 participate in the monthly rate (not in the deposit). But now the question is, what do we do in the event of a separation? We already had some ideas, but none of which was really satisfactory for both parties. On the Internet I also did not find much helpful, even when I extended the search to real estate (since many are facing the same problem). It might be worth going to the notary and setting up a contract, but with an aut o should hardly pay off. So how should we proceed to secure both of us? I am grateful for suggestions or further links.