If you want to completely stop others from attacking your village, you simply can’t. But, you can minimize the chances of getting attacked by following the pillow mentioned tricks:
Use shields and the Rhino pet
Play game without connecting your account to your Facebook
Block your friends so that they cannot attack you
Build a village when you make tons of coins to upgrade defenses