To me, James Madison's main role in creating a virtuous republic came from the fact that he was the main author of the Constitution. To the extent that we have a virtuous republic, it is the system of government set up in the Constitution that makes us able to have this positive kind of government.
Basically speaking, the ideas of limited government with separation of powers and checks and balances are the main foundations of our government. These ideas are what make it possible for our government to avoid becoming tyrannical. Madison played a huge role in writing the Constitution that embodied these ideas and which made it possible for us to have a republican form of government that would not infringe on our rights.