Your question is super complex and multifaceted. It covers atleast 1400 years of history, more likely 6000 years. Competing politicized theories, competing nationalism, and lots of other complex behavior. If you limit your scope it will be easier to get an answer to your question
Which religion came there first
Hinduism developed in India and became the dominant religion there - it has been around for at least 4000 years, maybe more. Islam is around 1400 years old and started to make a significant impact in India between the 10th and 12th centuries (although there were small numbers of Muslim traders there previously).
do Muslims and Hindus have the same roots (ie difference in religion is mainly due to conversion) or did one religion come via migrants to the region at a later period?
India was invaded and conquered many times by Muslim armies between the 10th and 18th centuries - the (mostly Turkic/Iranian) male elites formed by this process were newcomers in population terms, although they often married Hindu women. The question of the split between migration / conversion among the non elite population is a controversial subject that is not settled. It is likely that the bulk was through conversion though.
Did they coexist peacefully?
The ruling Islamic dynasties of India varied in their policies towards Hindus. For example in the Mughal empire as an example, Akbar (late 16th century) was relatively tolerant towards Hindus, while Aurangzeb (late 17th century) was intolerant. While the ruling dynasties remained Islamic, Hindu elites were coopted into the regimes to form a syncretistic culture.
Sorry, we don't allow throughout history questions. These tend to produce threads which are collections of trivia, not the in-depth discussions about a particular topic we're looking for. If you have a specific question about a historical event or period or person, please feel free to re-compose your question and submit it again. Alternatively, questions of this type can be directed to more appropriate subreddits, such as /r/history or /r/askhistory.