This question already has an answer here:
What is Dharma according to the sruti literature? How was Vedas composed? who is the first rishi? and how was it compiled? there seems to be 300 rishis who wrote mantras..how were they collected over time? Please explain it only from authority of sruti, not smriti.