I found this article that seems to be the closest to what I want, but they use small input voltages, not the 240V in my case of mains voltage.
I would suggest designing it for a low-voltage DC input that expects, for example, a regular sealed 19V laptop PSU, or any voltage between, say, 12V and 24V, or whatever, and use a buck (or a buck/boost) DC/DC converter module which are sold for next to nothing on AliExpress to produce whatever voltage you need to power your circuitry.
Designing for 240V AC input is one of those less pleasant affairs, especially considering all the safety issues, so why not solve this with an external readily available 3rd-party unit?
I designed and built a UPS for my WiFi router and some other stuff recently. It is powered by a 24V (really can be anything from 15V to ~30V that can provide the required output current) external PSU, which powers a DC/DC buck converter capable of CC/CV. CV is set to the battery buffer-mode voltage (13.5V for a 4s LiFePO4 battery, making it 3.375V per cell), CC is set to the desired battery charging current, but read below.
I did not bother to implement a circuit to switch between the sources: battery vs PSU (plus the DC/DC module). The battery-backed DC outputs are connected to the battery AND the DC/DC converter, aka the charger, at the same time (when external power is present, see below).
Converter's output current is shared between the battery and the load when charging. This essentially makes it an online UPS. There is zero switching time. However, the fact that the charging current is shared requires that the max load current does not exceed the max current set at the CC/CV DC/DC converter. The higher the load current, the less current is left for charging the battery. This is fine in my scenario, where the load current is relatively low (~0.5-0.8A @13.5V) compared to the max current provided by the DC/DC module (~3.5-4A, I fail to remember exact setting now).
I did not use an extra output voltage regulator, because all of my 12V load is happy to be powered with anywhere within the battery working voltage range (~11..13.5V). Most of these devices have switching DC/DC regulators inside anyway. YMMV though.
Now, another problem is that these DC/DC modules typically draw current flowing into their output terminals when the battery is connected to them and there is zero voltage at the input terminals. Mine draws ~14mA which is too much to leave it unattended.
The easy solution is to put a series (Schottky) diode at the output. The downside then is that the CV setting stops working as desired. The diode's voltage drop decreases as current decreases, so it becomes impossible to set a precise end-charge voltage.
Many will find this satisfactory. I did not, and added a relay to disconnect the charger from the battery when the external PSU does not supply voltage (a power loss situation). In this case, a diode is required at the charger's input to prevent the battery voltage backfeeding through the charger from output to input (yes it takes place) to the power-presence detecting circuit, essentially consisting of the relay coil. This is much less of a problem: due to the higher voltage at the input (considering a 24V PSU) the diode doesn't heat up as much and we don't care about the precise value of the voltage drop across it.
Pretty much the same switching logic can be used to switch between battery and external power, if an offline UPS scheme is preferred. In this case, however, I think, two DC/DC converters may be required: one to charge the battery, another to power the load, unless the PSU already outputs the voltage you want. I don't remember why I didn't use it. My design suffered a long evolution :).
Then, you need a cell voltage balancer for the battery. This can (and really should, trying to build it yourself is not usually worth the effort) be external and independent. Mine is external, it's one of those capacitor-based active balancers sold on AE. It has a "RUN" jumper which, being switched between shorted or open, can be used to turn it off when the battery discharges below the minimum allowed cell voltage to prevent further discharge. This jumper can be conveniently controlled by an open-collector optocoupler (first test for proper polarity on its terminals when open).
Then again, you also need a cell voltage monitoring system to prevent overdischarge (overcharge is less of a concern, since it's controlled by the combination of balancer and charger's CV setting, but is still nice to have). External inexpensive boards (BMS) are available on AliExpress as well.
EDA software that can do real-time interactive (accent being put on "interactive") simulation, such as Proteus, can be very helpful to verify and filter ideas, especially when it comes to relays and switches. Simply begin building something in it, and see new ideas come, test them and gain new knowledge.
Hope this helps.