If you want to file a patent you have to do
1. Legal research: make sure your work is patentable
2. Make sure you will not infringe other people's patents
3. Make sure once you file a patent, your patent is valid
and you will not be challenged
4. You want to make your claim as broad as possible but if you make your claim to broad, the examiner will probably reject your patent.
It's better to find a patent attorney or a patent agent to do it for you.