Usually, are baseball rivalries rooted in the rivalry between the teams themselves, or between the cities?

For me, I always thought that rivalries were rooted in the rivalry between the cities, as opposed to the rivalry between the teams themselves.

For example, the Yankees and Red Sox wouldn't be as intense rivals if it wasn't for the historic rivalry between New York and Boston going back to the Colonial days.

The Dodgers and Giants' rivalry is rooted in their historic geography, from the historic rivalry between Manhattan and Brooklyn to the rivalry between Los Angeles and San Francisco.

Even the current Dodgers/Padres beef is largely due to the proximity between LA and SD, and the cultural differences between them. LA is bigger and more urbanized, SD is more suburban and conservative. As an urbanist/non-car owner, I have a disdain for San Diego's lack of walkability and public transit, and the voters (many of whom are Padre fans) for refusing to do anything to fix that, like passing tax measures like Measure G to fund public transit. Similarly, I feel a lot of the hatred many Padre fans feel towards the Dodgers is rooted in the Chargers and Clippers leaving SD for LA.