There are so many theories behind it that in the end all you have is chaos. It can be summed up, though, by saying that if a 5 can substitute a 1, then theoretically that 5 becomes a 1 and can be substituted by its 5 and so on...so everything relates to everything, and it's usually held together by the melody.
That's just one of the substitution possibilities. Keep at it, and you'll learn more.
I find new bass lines by looking at the melody note and figuring out which chords I know that have that note in it somewhere, since I'm usually playing at least 2 notes with my left hand. I do the same thing to find chords. (I'm better at doing this with choir songs though)