While I agree with other answers that there are no hard and fast rules for composing unless you are working in a well known idiom that is well defined such as a Bach Fugue, or a Beethoven Symphony or 12 bar blues or Bebop or Swing Jazz.
I tend to think of music in visual terms such as background vs. foreground, colors, lines, shadows, reflections etc. Translate these into the musical elements of harmony, melody, timbre, dynamics, repetitions, rhythms, changes of tempo etc.
Where I start depends on the idea I have in mind. I think of it, then hear it, then I start to play it, then I "jam" with it, stretch it, shrink it, cut it up, turn it upside down, make it go backwards, grind it and mix it, find its opposite, find its complement, thus a relationship between myself and the piece is built by understanding the nature of the idea.
Then take the best parts of this exercise and begin to assemble in a manner that fits the idea. For instance if you are working on a texture based piece, consider that there are parts of the texture that are thin, parts that are heavy and thick, parts that are like silly putty that you can stretch and pull apart, and parts that are translucent. It's up to you to discover the most significant parts and figure out a way to connect them together in a whole that embodies the original idea.
Edit, edit, edit until you have it.
Let's explore this with a simple 12 bar blues (a kind of universal template for most Blues, much Rock and some Jazz). Having suggested a 12 bar blues we already have defined 12 bars as I (4 bars), IV (2 bars), I (2 bars), V (1 bar), IV (1 bar), 1 (bar), V (1 bar) then repeat for each verse and chorus or solo. So now all you need to do is to define the key, melody (usually a vocal with words), and tempo. The harmony is already there you just have to tweak for major or minor, add the rhythm section (bass line, drums, keys, guitar), solos that usually are close to or a slight variation of the melody, and you pretty much have a song down. This is the most common start of most jam sessions since everybody knows the frame work, not much composing here, mostly improvisation within this tight frame work.
However, let's say during the jam you happened to come up with an incredibly cool beat between the bass and the drums, or find a lead solo that blows you away--that's what a jam can do. Then take this and get it tight, everybody on board, and now you are approaching a finished, and somewhat original work.