Back in the late 1980s I worked for a company which made static transfer switches, for sensitive mainframe computers.
The key was that the UPS was always kept running (although unloaded) and it’s frequency and phase were locked to the mains via a CMOS PLL and logic gates.
It wasn’t a trivial circuit, quite the opposite, very challenging. A phase transfer error would result in a large BANG!
Nowadays it is done with FPGAs. Same principle, though. Hardware is way simpler, but do you know VHDL or Verilog programming?