I've done this, albeit it was on income properties.
We spoke with various lawyers, and eventually we ended up with a VERY detailed document, that you might say is similar to a co-habitation agreement.
It states what will happen in every event imaginable.
I view it as an insurance policy.
The biggest factor in our policy is to put the same, and take the same.
If I put $100 in repairs, he needs to put $100 in repairs, and so on.
Sometimes easier said than done.