Although I just posted comments saying the question can't be answered, it occurs to me that a portion of it can, with disclaimers.
It occurs to me that music must have some sort of rules about what sounds good (subjective), or bad (off key). where can I learn more about what that means from a mathematical / theoretical perspective?
do the patterns of music overlap across genres?
"Good"/"bad" are culturally constructed—the rules governing baroque European music were different than medieval, which were different from ancient Greek, all of which are different from classical Indian. But all of these had their own codes of procedures and explanations. So if you restrict your scope narrowly enough, you can find rule sets that are valid within that context.
Now, there's one music-culture that's had an outsized effect on others. The music of the so-called "common-practice period"—the system of tonal harmony that broadly dominated from late baroque through mid-Romantic eras—continues to be the foundation of a lot of contemporary music, and through cultural transmission, a lot of global music-cultures as well. In other words, the musical language of Mozart makes up 95% of the musical language of Taylor Swift. Other genres can be more intentionally distanced, like jazz, metal, or 20th-century serialism, but the predominance of this tonal language is the reason it gets studied so much. When we say the phrase "music theory," ideally we mean a discipline that can be applied to any musical artifact, including Schoenberg, acid jazz, and prog metal... BUT what we often mean is the study of this tonal harmony, as in "Music Theory 101."
So in short, try for an entry-level education in "music theory," i.e. tonal harmony.* But bear in mind that any "rules" you find are only applicable within certain cultural parameters. Because...
Do the patterns of music overlap across genres?
Not always. Sometimes the evolution of genres out of others, or cultural transmission, mean that some genres have shared traits. But nothing is universally guaranteed.
* And good luck turning these rules into a data set that's useful for computational composition! You're not the first person to have this idea, and might look into what others are doing rather than reinvent a wheel. I've seen experiments using generative AI to generate music for years now, long before people have gotten so excited lately.