Depending on the language you are using, there are several libraries you can use to sign a pre-made raw transaction.
I use Python, so one that I found quite intuitive and easy to use is the old vButerin's Bitcoin tools. The code is no longer supported, but it could be helpful.
Moreover, I've personally developed some tools to help people understand how Bitcoin transactions are created, what are their parts in the transaction serialization and how can they be created from scratch. There are publicly available on GitHub also. The library is intended to teach, so maybe you could use the comments to understand how to do what you asked.