[noun] + 同士 [noun] + 同士 + で [noun] + 同士 + の + [noun]
同士 goes straight after a noun for people and means "fellow", "among themselves": everyone involved shares that label, and what happens, happens between them. The noun names what they have in common – friends, Japanese people, rivals – or how they stand to each other, as in こいびとどうし恋人同士 and となりどうし隣同士.
With で, 同士 names who does something together, with no outsiders. With の, it describes something that happens between them: a fight, a talk, a match.
Both people have to fit the noun. ×先生と学生同士 does not work, because the teacher is not a student.
同士 also works with things of one kind, when they are paired or matched up with each other.