I would say that there's no definitive way to write a song. It's very individual.
I know people that gets good results writing down the song in guitarpro first, and i know people that gets good results writing ideas down on paper.
The way i do it is that i play around on the guitar, and maybe i will get lucky and come up with something i like.
Then i record what i came up with asap and at the same time record some spontanous improv afterwards of what i think will fit. I dont care if i mess up or stop for a few seconds.
After that i analyse what i played and start constructing a song out of it. I split the track up and move the various sections around to make a basic layout. I might come up with more ideas in this process and i record them too at once.
I will also add basic drums and bass during this step.
Once i'm pleased with the layout i will start recording proper guitar-tracks and improve on the drums and bass programming. I might come up with more ideas in this step aswell.
But usually the finished result is 90% different from the initial idea i started recording
In most cases i will finish and be satisfied with the backingtrack before i add melodies and solos. But this might also differ if the inital idea was a solo.
That atleast how i do it.