This will start off as an extremely broad-brush discussion and we will see how specific it gets as I go along.
As one commenter has suggested Middle Earth does not - to my mind - lend itself to a medieval campaign. This is because of the overarching good vs evil backdrop of heroic fantasy in the setting. Medieval politics are far more grubby and, well human, than an endless struggle of ethos.
I subscribe to a certain geographic determinism in the development of human society. For a long, long view of this see Jared Diamond's 'Guns, Germs and Steel'.
With that stated, an independent city state needs a certain geographic isolation to maintain its independence. If you consider the surviving small states of Europe: San Marino, Monaco, Lichenstieln and to a lesser extent Denmark, the Benelux countries, Switzerland, Scotland and Wales, they have all had geographic features that allowed them to resist absorption by powerful neighbours.
Turning to the 19th century unifications of Germany and Italy, these were predicated on the forced amalgamation of small states by Napoleonic France. In the case of Germany over 300(!) states were reduced to 29.
France is an illustration of the opposite, the first modern state in Europe, it's heartland was a large plain around Paris and it spread through marriage and force into the more inaccessible parts of Normandy, Bordeaux and Provence.
The same argument could be mounted about the ancient city-states of Greece.
So, your city state should be reasonably secure from outside overt threats.
An overarching religious commonality can help too. Before the reformation, Europeans had the Catholic religion to unite them and maintain the status-quo. The thirty-years war was particularly vicious because it was a clash of religion.
So, your city state should have something in common with its near neighbours. A distant enemy (like Islam was to medieval Christendom) could be a good idea.
Look to economics to define your power structures. In a pre-technological society, economics means who controls the means of food production. How does magic impact on this?
Also, a campaign based on political intrigue means that there needs to be secrets, lots of them. How will divination magic play out?
As for sources, anything on medieval Italy (particularly anything about the Medici will be worth a look.