The dwarfs of Degelkol, Galleywheels, don't think much of military prowess. Consequently, they have no standing military and in fact no citizens with significant military skill.
That doesn't mean they are pacifists. Their wealth has attracted many goblins and other hostile creatures. To keep themselves safe, the people of Galleywheels have built many traps. However, the items found in the "traps" folder are generally only the backup plan, goblins are mashed by various other contraptions.
N.B. Both Galleywheels and Blamelesscloister are .34.11 forts. I've tested the concepts in .40.24 and they still work, although the exact efficiency may have changed in some cases. Hard to say with un-co-operative goblins who rarely bother to show up.
Exhibit one: automated Atomsmasher.
Two 3x10 bridges that must be travelled lengthwise. The two doors in the middle enclose one tile of water (pond, filled from above). Whenever a door is opened, water spreads off the tile, the pressure plate in it (responds to 0-5 water) fires and indirectly triggers a 200-step repeater that controls both bridges. Bridges change state roughly every 105 steps. Creatures on the bridges while they raise are thrown around (unless they're on the wall tile, where they get crushed right away), stunning them, often breaking bones and effectively preventing them from moving forward. Creatures in the corridor while the bridges come down are crushed, destroyed with no remains. Very convenient, since it cuts out all the goblinite hauling. Since it's triggered by an opening door, trapavoiders are caught, too. On the downside, it also crushes merchants, diplomats and citizens when allowed.
Between uses, the water cell must be refilled via pond order. That's visible to the right - it's the level above. The traps are the backup in case some flyer gets through the pond opening. The connection between the smasher and the fort is through a raisable control bridge. For added safety, a citizen-triggered pressure plate frequently hinders dwarfs from commiting suicide by bridge - it opens a hatch cover in their path. If the control bridge is up, invaders will not path into the crusher.
To prevent mis-crushes, the repeater is triggered indirectly:

The hatch to the left responds to the trigger, but the cart can only enter the proper activation loop when the hatch in the southeast (orthoclase) is also open. That hatch is controlled by a dedicated "arm bridge" lever.
This was our first defensive machine, and it's been the go-to device when dealing with goblin/troll siege forces. No hauling, little mess, very efficient. It can't be used when an invasion force includes large animals and is useless against semi- and megabeasts (bridges break when trying to lift or crush something too big).
For the big stuff, our recourse was
Exhibit two: spike corridor. Once again, pretty simple:

Doesn't look like much, but these fifteen spike assemblies took out numerous large war beasts, a few titans, a roc and a dragon and two demons. It's run off a minecart repeater tuned to optimum period of 82 steps per full spike cycle. It takes four pressure plates to achieve this, which isn't optimal.
To the north and below, the corridor continues through several weapon traps, which in fact took care of a few particularly nimble victims.
The spike corridor gets triggered by lever-pull and can be selectively shut to the outside world or the fort.
Since the entrance to the spike corridor is rather exposed, we built an extra door just for diplomats (originally also for migrants):

A spider-web of underground tunnels, leading to a bridge-lock, guarded by a few weapon traps and a war dog. Since the entire surface is set to "restricted" pathing, it safely channelled migrants through the underground passages when we still got migrants. Dog and traps take care of ambushes and thieves that try to sneak in with the diplomat.
The caverns under Galleywheels were home to several massive beasts. While it's entirely possible to lure them with an artefact piece of furniture and poke them with spikes, we decided to try out some minecart applications:
with impulse ramps and/or the checkpoint effect, carts can be set to perpetual motion. A sufficiently heavy cart can deliver quite a punch, and with ramps, it can keep giving additional punches after the first one. The first design was a simple accelerator coil, tried out against goblins:
Exhibit 3a - goblin exploder

Cart circulates counter-clockwise in the six-ramp cycle, reaching maximum ramp speed. When the door to the south is opened, the cart exits, at bone-breaking speed. Anything not substantially heavier than the (metal) cart will be blown apart, but it seems to only hit one opponent at once. The cart is re-cycled by an impulse ramp on the collision spot, sent around the southwestern loop over a hole in the floor (so even if a crowd wants to enter, everyone tries the door instead of going around).
Not fully satisfactory, since with large opposing forces, the cart can get stopped on a flat tile. I think this test device failed half-way through an ambush.
Thus, improvement:
Exhibit 3, high-speed minecart grinder

A twelve-ramp loop. To get the cart around corners without losing ramp acceleration, corners go up a level. On the level above, there's another impulse ramp sending the cart back down on the other side. No matter where the cart collides with a target, it cannot be fully stopped. I built two grinders in a row, in case something got through the first one, and a lockable door and spike array, in case something got through the second. Nothing got through the first so far. Actually, we seem to have run out of forgotten beasts. Yes, that design has killed three forgotten beasts (not at the same time).
The design works against goblins, too:

And against trolls

To make the whole thing start- and stoppable at will, carts are first deposited on mechanically operated hatches. However, those hatches attract trolls (and forgotten beasts). They have to stand inside the grinder to destroy the hatches, so that's actually still useful, but once the hatch is gone, there'd be no more way to stop the cart. So we _also_ installed one 1x1 retractable bridge in a corner of each grinder cell.
Large crowds can clog the grinders. It seems that a cart can only push one creature per tile, and large/heavy creatures, especially when there are several in one tile (like trolls while taking a hatch apart), can block a cart's movement into their tile.
So, not perfect, but adequate. Can deal with normal sieges.
It's also possible to build grinders with much less floor space - two ramps per cart are enough:
Exhibit 3b - chain of tiny grinders

The trolls got to grinder Nr. four out of nine. Once again, trolls clump together to take down hatches, blocking the cart until they spread out again. The grinder chain took out 26 units of a siege, which broke the morale of the rest.
Each grinder cell consists of two straight ramps, nothing more. Since they touch each other, they "lean" in opposite directions. A cart will keep bouncing between these ramps at substantial speed forever, or until offered an exit (above). That's what that mess of doors and hatches is for - it allows extracting the carts from their cells and in fact deposits them back onto their hatches, ready for operation at the flick of a lever. The nice thing about this design is that every tile of path goes straight through minecart-occupied ramps, there's no way to sidestep them.
There's another way of crushing things with minecarts: by dropping from above. Due to a rather weird bug, minecarts deliver collision damage through solid floors to creatures directly below. Out of curiosity, we tried this out against forgotten beasts, as well:
Exhibit four: minecart percussion corridor

A row of rollers pushing west, a tile of floor and a pit. Looks quite unassuming. Carts touch the rollers and get pushed west. Carts coming from floor do not enter downward ramps at all, they always jump. Carts jump past the pit, smack into the wall and fall down.

Into a simple double-ramp pit. After hitting the floor, the carts climb out east, towards the roller that throws them back in.
And on the level below that, through unbroken floor:

Those were six forgotten beasts, of various materials up to gemstone. Ten copper minecarts regularly punching from above >> forgotten beaasts.
I've tried the design against HFS, and it works quite well. Very beefy types can take quite a lot of punishment, but if you manage to keep them under the carts for long enough, they should succumb eventually. Haven't tried it against goblins, feels like overkill. Percussive minecarts can be had without power, too.
Something i haven't built in Galleywheels, but which also works remarkably well:
Exhibit 5: powered minecart grinder

The six roller pairs in the centre-south are the grinder. Each roller pair tosses a heavy, massively loaded cart back and forth when powered. Nothing gets through. This simple setup has taken out 444 units (mostly hostile) so far. It's backed up with traps and coupled with bridges to offer an alternative path and/or block path through a busy grinder - to keep traders alive. It's built in a glacier with practically no planning, thus the spaghetti pathing.
The main downside of automated defences is that they're largely static. The best magmacannon does nothing for you when the goblins aren't in the target zone. Waiting for the enemy to enter your prepared crusher/spike corridor/trap field can become quite boring. Fortunately, most creatures with legal path _will_ move at some point. And if they just won't, you can always flood the area with magma.
