Thank you very much for the help. but I would like to ask, why isn't it as simple as connecting the battery to the load and the battery to the charger?Vbat is the +ve end of the battery.
The screenshot with the TP4054 shows the battery being charged from Vbus. The TP4054 is an IC that controls the charging. It is supplied from Vbus and the output is connected to Vbat.
The charging is turned on and off by IO32, but I don't know what drives that.
D2 is a diode that lets Vbus power the 5 V rail. Q1 allows the battery to power the 5 V rail. Q1 is turned on when Vbus is low, and Q1 will basically have no voltage drop. A MOSFET (Q1) is used to get the most life from the battery by avoiding the voltage drop that would come from a diode.
The 5 V rail is regulated to 3.3 V by U2.
I suspect that the 5 V rail won't actually be at 5 V. The TP4054 charges a battery to 4.2 V, so it's likely that the battery will be about 4.2 V fully charged and 3.5 V when discharged. At 3.5 V, a diode drop would be a problem because the diode drop would reduce the voltage below 3.3 V.
So when running from the battery, the "5 V" connection will be between 3.5 V and 4.2 V
Vbus is probably the USB voltage of 5 V. Charging ICs like the TP4054 are designed to run from that. When Vbus is on, there will be a voltage drop of about 0.4 V through D2, so the "5V" connection will be about 4.6 V