In line with the other best-x-ever lines, I thought up this one. I'm not a huge fan of military myself, I prefer engineering my foes' doom. Weapon and cage traps are a good start, but for the best in defense, one needs halls and halls of traps, pitfalls, and mechanical constructs.
Probably my best one was a construction I like to call my labyrinth. It was a 3 tile wide road, connecting to the south-east corner of the map. it did indeed have an opening to my fort, but that was only to lure gobbos into it. None of them ever got through. The road twisted from east to west, winding back and forth across the map. Some parts of the walls had crossbow traps (there were access pathways so dwarves could reload them without ever being exposed to the gobbos) hidden behind fortifications, behind pits so no building destroyers could get to them. Some parts of the road had weapon traps, some had fatal drop pits, and I was working on mechanisms to flood the entire maze with both magma and water (not both at once obviously, digging the whole thing out would be a bastard.)
My two favorite parts though, had to be the access road, and the very end of the maze. At multiple points in the maze, there's a 3-long-2-wide pit (2 wide because I remember colossi having a bit of a reach) with a raised drawbridge on the other side... A lever inside the fort operated the drawbridges. Lowering the bridges revealed access ramps, so migrants, traders and carts could get to the upper level of the maze, which was pretty much a straight road into the fort.
The end of the maze was a very long series of bridges, hooked up to pressure plates. The plates would retract the bridges, dropping gobbos into a lower level road... which would lead back to the start of the maze! Gobbos would just keep looping through forever! Muaha!
... Then I tunneled straight into a heaping facefull of HFS. With no military. Hubris incarnate.
What's your best deadly, convoluted, confusing, or just plain dwarfy fort security system?
(edited for typos)