Writing custom Arduino upload / programmer

I need to better understand how the Atmega processors as well as ESP32 are programmed. I have to write custom software outside of IDE so my end user can perform firmware updates on the hardware I’m designing:

ESP32 - I think I found an example of how to do this over WiFi. Any additional information to do so would be awesome. I’ll have to login through the web to flash the ESP32.

Atemga 368 - I will have to program this chip through the ESP32 / serial bluetooth. It’s been probably 20 years since college where I’ve written anything to program a microcontroller if ever. Anything to get started such as a Visual C# program I could write, something to get an idea how I might do this.

For ATmega processors, there are two main approaches: ISP programmer using the SPI protocal, or TTL-RS232 serial port bootloader.

Useful tutorial, with code, for using Arduino as an ISP programmer, to program another Arduino : https://www.gammon.com.au/bootloader

(in this case, to write the bootloader, but the approach is completely general)

And, of course the Arduino serial port bootloader is open source code.