Let's say I've written a song with the chord progression I-IV-V in the key of A (just as an example). So, the chords I'm playing are A-D-E. When playing a lead over this rhythm, what notes do I need to stick to over each chord? That is, when playing an A chord, should I stick to the notes that compose the chord? Are there rules for which notes sound good over which chords? When I move to D, are there notes I should avoid or continue?

I'm asking because I have a melody I like and I'd like to back it with rhythm guitar, but I'm not sure how to choose chords (basically the other way around from how I asked the question, but I'd like to know both). I'm just starting to learn musical theory and I'm not sure the best way to phrase my question.