You may want to consider using a battery charger IC with the ability to seamlessly switch between DC inputInput and battery inputBattery Input. It isIts normally called dynamic power managementDynamic Power Management (DPM) and dynamic powerDynamic Power-path managementPath Management (DPPM.).
MPS have a nice primer page explaining some of the concepts
I'd highly recommend designing a circuit or using a module that implements the battery management and power path functionality as it'll make your life much easier as battery charging can be a pain to implement and you'll save yourself a lot of space with a more integrated solution which is something I think you'd find valuable being space constrained in your application.