Question about relationship between notes in melody and the underlying chord

Hello dunno how active this place is but in case some one knows, I’m wondering how necessary it is that the notes in the melody match up with the notes in the underlying chord?

I forget which chapter it was but I remember in the first book the rule was that notes not in the chord shouldn’t occur on a strong beat and if they do then they must resolve on a note within the chord. However there are several examples that sound good but do not follow this rule, e.g. Undertale by Toby Fox Chords, Melody, and Music Theory Analysis - Hooktheory both the intro and the verse. Some measures match up totally but there are a handful of measures that do not.

So I’m wondering, how does one write compatible melodies for a given set of chords if this rule is in fact not that strict?

@icebuddha good question. Melody notes don’t have to (and typically will not always) line up with the chord tones. When melody notes do line up, it creates a sense of stability, and when they don’t it creates a sense of tension or instability, especially on a strong beat in a measure. It’s really up to you as a musician/songwriter to balance these two levers in creating a musical phrases that do what you want them to do.

Songs with melodies that are all “stable” sound very safe and somewhat unambitious, whereas songs with mostly “unstable” melody can sound edgy and even cacophonous. Usually the best melodies balance stable and unstable to inject a good amount of tension/resolution at the right times.