There are two different strategies fo defending your city, and those two are depending on how much time your are on line.
If you are online everyday at least 1 hour it is easy to defend and your can allways predinct an atack.
Fist of all you must evaluate your neighbors around your city for at least 10 miles distance:
1.If your neighbors are strong and active(check their prestige) expect to be plundered a lot so consider the possibility of moving (teleport).
2.If you intend to stay and fight build your army to defend: forget about traps build Archer Tower as many as you can at least 12k.You also must have 30k archers minimum.
Do not build swordsmen there are useless and costly.If you have enough food you can also train 2-5k of cataphract and 3k balistas.
Always remember that an attack can have a maximum army of 120k limited by the rally point, but if he is close to you he can do multiple attacks.
Don’t let resources to be plundered when you are online invest all the resources in army and wall defences.The rest of resources put it on the market at very high prices, the can not be plundered.The main problem is with the money but you can buy resources.
IMPORTANT:If an attacker do not intend to take your city he will think twice before atacking if it is worthy or not.If he will lose more than he can gain he will not atack.
Another problem of defending your city is to chose if you will keep the gates open or not.This subject I will develop in a latter article.
If your are not to much online there is no way of defending .If you are online 1hour in 3 days you better quit, becaouse you will end up as a farm.