You should always have frequent and regular backups. It is impossible to recover accidentally deleted data from an SSD. Plus an SSD can fail at any time without any warning signs. The easiest way would be to use the built-in Time Machine backup feature provided by macOS.
Once you have a backup, then you can perform a clean install of macOS by using these instructions:
https://support.apple.com/en-us/HT208496
Another option would be to clone the drive using Carbon Copy Cloner.
On first boot Setup Assistant will prompt you whether to migrate any data. Since you want to do a clean install I would only migrate the user folder(s). Or you could create a new user account and manually migrate your data back from the TM backup or clone.
I don't use Time Machine, but I believe this should work. May be another more knowledgeable contributor could chime in regarding Time Machine.
You can boot the Mac using Recovery Mode, Internet Recovery Mode, or from a bootable macOS USB installer.