I agree with KiddingMe speak to the police and find out exactly what level of harassment triggers police or a judges action.
Since you have gained support and openess on this forum I am going to recommend another site that is specific to this situation with your ex(?) boyfriend.
https://www.7cups.com/member/connect/conversation.php?c=Sophia It's similar to this forum , no fees, private password protected, people willing to offer verbal help. The purpose is therapy especially with relationships that have come apart. Check it out.
For the present he needs to understand that he is not to “call, text, or show up where I am.” Each time he does that he is interrupting the healing time you need at this point.
He is your friend. You are his friend. He knows that there is a strong bond and unfortunately he has used it to manipulate you to a point that makes it difficult for you to even imagine a life with someone else. So he really needs to stop calling and/or texting or showing up where you live and work.