A songfic is a type of fanfiction.
There are two types of songfic. The least commonly used is the first type: fanfiction based on a poem or song. They will usually follow a certain format, alternating between a few lines of the song and then back to the fanfiction as if the audience were watching a music video. Unlike a music video though, fanfiction is not often in movie format and so the song's lyrics are put at intervals in the text to show where in the current action would appear if it were in a music video.
The more common use of the term "songfic" is to a fanfiction that is written as a musical, using the lyrics of songs for the characters' words.