A written roommate agreement feels awkward to propose and then quietly prevents every classic flatshare war, so push past the awkwardness.
Then the living rules that actually generate conflict: overnight guests and partners, since the unofficial third roommate who pays nothing is a legendary grievance; quiet hours and working-from-home expectations; a cleaning arrangement, whether a rota or a shared cleaner, with kitchens and bathrooms named specifically; fridge and food sharing boundaries; smoking and pets; and thermostat or utilities habits if bills are split evenly.
Finally, the exit mechanics people forget: how much notice someone gives before moving out, how a replacement gets found and approved, how the departing person's deposit share is returned, and what happens to jointly bought furniture.
It doesn't need to be a legal document; a shared page everyone signs or confirms in the group chat does the job.