Detailed implementation information for install, upgrade and remove commands can be found on the Commands Implementation page.
Some info on package database can be found on the Package Database Implementation page.