This article documents my own journey into understanding music through writing code and taking a first-principles approach. This enabled me to understand things like why there are 12 notes and why notes in the same key sound good. Hopefully, if you are in a similar position to me, this will give you a foundational understanding of music that you can reason about instead of memorising.
Disclosure: I built RunJS, and this is on its blog. It gets a mention in the last paragraph and nowhere else.