I thought it would be fun to setup some sort of underground tower overlooking the entrance path. I did not expect it to work that good.
Normally when I deploy archers I have to be careful they don't go melee their opponents. But it looks if you make the path long enough archers will prefer to get new ammo instead of hammering with crossbows.
The setup I used was a winding road around a central room. This central area was only accessible from below. Every level the road went 1 down with ramps. Everything above the roads except for the first layer was carved out as well. Fortifications were carved on every side that overlooked the road. It is 8 stories high.
To prevent trolls sticking their arms in the wall was 2 thick. Downside is that it does not look great to carve fortifications on two sides and that all archers need to have lots of training before they shoot through double fortifications.
The archers were assigned to the top level fortifications using a burrow and a schedule to guard that burrow. On that burrow was the bolt stockpile. Using this setup I have only seen archers with not enough skill trying to get into melee.
If they decide to go the wrong way they would first have to climb all the stairs down in the central room and then the winding road around it up: plenty of time to kick them out of an archery squad and see them running back into safety.
If needed I'll add pictures but I hope this is enough info to make your defense positions in such a way they prevent some nasty game mechanics.
I do essentially the same thing but with minor modifications:
1. Instead of two fortifications I have only one line, and 4-5 tiles of empty space between the crossbow-dwarfs and the goblins and trolls. This makes the winding path longer. Also dwarfs can shoot at enemies at different z leves. Be careful! Some enemies will climb and jump inside of the tower with this setup so smooth things a bit and keep jumping distances large.
2. My tower is accessible from above. If I want to flood the whole entrance with water or magma as an emergency backup plan, that is much more convenient.
3. Add some ballistas for good measure.