How to create a linux application like team viewer?

I wanna try to build a linux application to control my Raspberry Pi over the internet. I just wanna need the terminal of the Raspberry pi or desktop if possible. Now I have a cloud Django and I have build remote access with the help of subprocess command and command is stored in the cloud. So each time Raspberry pi contact the cloud, cloud will return with that command and then Raspberry pi will execute the command and the output of the command is transferred to cloud through post request. This is how I maid remote access.

But I wanna develop a more efficient access just like the team viewer, anydesk etc… I need to control the Raspberry pi from my website. That is, I need a application to run on my Raspberry Pi so it will communicate with my cloud.