This questions is similar to a question I asked about how to use walls, but since I think you have a more general focus- I'll give you a more general answer :) .Constructing a good defense is complicated. Arguably its the most challenging aspect of the game. It is hard to define a "best" defense, since attackers will use different counter-strategies, the defensive options available to you vary by level, and new strategies are evolving all the time. That said, here are some tips I find helpful.
Step 1 - Decide to protect trophies or resources
This is an easy decision if you don't have much of one or the other, but you will eventually have to choose. Protecting your resources will be important when you are saving up for the late game upgrades - some of which will require days or even weeks of stockpiling to afford. Protecting your trophies means protecting your town hall and minimizing collateral damage - so as to minimize or eliminate "cheap" one star victories for your opponents.
Step 2a - Protecting resources
The best protection for resources, is to spend them - but of course sometimes that is not an option. Given that, it is best to put your storage containers deep inside your base, ideally behind concentric walls. Put your most powerful defensive buildings close your your storage containers, and consider putting traps near them as well.
Also, and this may seem unintuitive - make your Town Hall vulnerable. It's up to you whether you want to leave it totally undefended, or with minimum defenses - but make sure its the target that attackers focus on. When it is destroyed you get an 8 hour shield for free. If it is well protected it is actually possible to get attacked over and over - resulting in massive resource losses, without ever getting a shield.
Note: as of the 10 December 2015 update, trophy farming has been massively nerfed. Town halls now contain much more loot which can be stolen easily if left outside your base. Also shields are no longer awarded on TH destruction. Hence it is highly recommended to keep your Town Hall inside your base.
Step 2b - Protecting trophies
If you are going this route, the most important thing is to keep your Town Hall well protected - using the same strategy mentioned in Step 2a for your storage containers. Opponents can also get a 1 star victory by destroying 50% of your buildings, so keep your buildings close together, and fit whatever you can behind walls. Since you are less focused on resources, it is also good to spend as much as you can on walls and simple upgrades, which will make you less of an attractive target.
Step 3 - General Tips
- Get a Clan Castle, and join a clan that is active enough to keep it filled. Units from the Clan Castle are free to you, and are a nice boost to defenses.
- Use "less valuable" buildings like Builder Huts and Barracks to distract attackers. Note that these buildings create a "keep out" which can be used to control where the enemy can drop troops - forcing a long walk under fire, as opposed to getting dropped right where they want. Decorations can also be used in this way - but note that they do not create a keepout (other than the space they occupy).
- The edge of the world is no protection. Don't use it like a wall. It is in fact better to build a little away from it - see previous point.
- Mortars have a close in "blind spot". Use walls and building to "fill" this blind spot so enemy units can't stand in it.
- Defensive buildings (cannons, mortars, archer towers, etc) should all overlap, to protect each other.
- Any time you upgrade defensive buildings, remember they are out of commission. Try to cover the "hole" they make with other defensive buildings, and avoid upgrading too many at the same time.