If you are interested in how Scratch works you can look directly at the code. It's organized into several open-source repositories which you can find on Github:
https://github.com/LLK/scratch-www
https://github.com/LLK/scratch-gui
https://github.com/LLK/scratch-vm
https://github.com/LLK/scratch-render
https://github.com/LLK/scratch-blocks
For ScratchJr: https://github.com/LLK/scratchjr
If you're interested in contributing to Scratch, check out our contributor guidelines: https://github.com/LLK/scratch-www/blob/develop/.github/CONTRIBUTING.md