A songwriter (or composer) writes the music (melody, harmony, structure). A lyricist writes the words. One person may fill both roles. In collaborative settings, credits are split (e.g., music by X, lyrics by Y).