How does piwik.js work, how is information sent to the database?

I am curious as to how the piwik.js tracking code works as I am now starting to use Piwik. I am really good at PHP development but find myself lacking when it comes to javascript and I am curious as to how tracking information is sent from the piwik.js file to the database as a visitor visits a site with the implemented tracking code.

I have looked at the documentation but only find references to information about adding events/goals/conversions, nothing about how the javascript actually works.

Thanks for your help!

How about you look at the code of the JS: matomo/piwik.js at master · matomo-org/matomo · GitHub