What type of contract would I need for a freelancer so that I own the codes and they can't compete with me ?
In my experience non-compete and IP rights agreements are absolutely useless and expensive to enforce, especially if you're hiring someone outside of your own country. I'm not saying that you shouldn't at least try this on your first project if you think it's necessary. In the end, what you need is an honest programmer. I use UpWork and only hire freelancers that have a decent amount of hours logged and positive feedback. Yes, you might end up paying more but finding someone who is professional and trustworthy is better than worrying about your idea getting poached by someone who comes in with a rock-bottom quote to create your code.