I mean music theory, here. It is funny that what goes by the name music theory would be, in literature, the equivalent of prosody and plot construction, not "theory" as it is known to literature folks. (And not in the third sense of a scientific theory meaning a strong and empirically testable explanation that accounts for a set of phenomena in the natural world.) Although classical performers study theory in conservatory, many of them find it unexciting. To write or improvise music, though, you are always thinking about what the chords are. I am constantly making duh discoveries, like the fact that the pentatonic minor scale will have the same notes as the pentatonic major scale of the relative major. It seem kind of obvious, but I just discovered this this week. I also discovered that I was using pentatonic scales in melodies without knowing what it is I was doing.
I like working in Dflat (five flats) for some reason. I think it is because it has chords unrelated to C, so that if I combine those two keys, then I have about 20 chords under my fingers, if I include modulations to other keys related to these two keys, tritone substitutions, secondary dominants... I don't have to learn 12 keys really well; I can have about 3 or 4 I know pretty well and I have most if it covered.
Someone was asking how to memorize all the chords. You don't memorize them, you learn them in relationships to other chords and keys. You know them. If you tried to memorize them by rote out of all context it would be much harder. A harmonic context distant from C major is simply a different context, where things have a different meaning, but where the relationships are completely commensurate.
A musical composition has to make sense to me, melodic, rhythmic, structural, and harmonic. I have to work on it until it all fits together. The surprising thing is that I know how to do this, that I knew how from my first song, and that more sophisticated harmonies do not make my songs necessarily any better. They are just fun to compose in their own way.
Everyone who listens to music knows what melody is and can recognize one or have one stuck in the head. There is no actual criterion for what a good melody is except for one that someone responds to subjectively as a melody. We can say objectively that some music is more complexly organized or longer, but can we say that the Beatles's "Michelle" is better or worse than some other melody that a lot of people like as much? There are melodies from Bach I don't think are great, and others that are.