Check out ttybus which lets you create virtual serial devices which can be attached to physical serial devices or TTYs, e.g. the TTY of your SSH session.
Alternatively, rewrite your program to work with stdin/stdout and connect it to serial devices, regular files or pipes using input redirection (program >/dev/ttyS0 <&1).
You cannot start a graphical program as a service the same way regular services are started: it will have no display to connect to, and if you somehow provide a display (by connecting to an X server during startup and setting the DISPLAY variable) it will likely complain there is no user session.
I suggest you install a torrent client with no GUI, e.g. ...
do you have a USB thumb drive?
flash raspberry pi lite version on USB thumb drive
create empty ssh file in first partition
remove SD card from Pi400
insert USB drive
ssh into pi400
insert SD card
Now do the following
sudo mount /dev/mmcblk0p1 /mnt
sudo touch /mnt/ssh
sudo umount /mnt
remove USB drive from pi400
now SSH will ...