this ravenspiralguide tells it in a few words, or sides (about 80)
it has to do very much about a little bit of knowledge about music-theory. and this guide is really a good place to start with.
in the second place, it depends on your taste, and (much more) you HEART
if you know the whole thing about theory, fine,
but if you cannot "translate" it into your melody - that doesn`t help you at all.
and there we come back to:
try and try once more.
play the bass and drumlines over and over again, use a synth to play some notes, just a few in the beginning, and HEAR how it FEELS.
then, go from there ....
that gives me the best result.
that way i find out if a harmony (the result of the bassline and the tones of my melody) "tastes" good with that track, that groove i have.
that way you create tension, that way you create a certain MOOD.
i love music, and therefore i love to try what i can make out of a combination of groove and harmony,
and while i am trying, i learn every day more and more about