Somalia is, rather interestingly, one of the more ethnically coherent states in Subsaharan Africa, with the overwhelming majority of its populace being Sunni Muslim Somalis who speak Somali and no politically important minority to speak of (there are some, but less than say France).
All neighbouring states have sizeable Somali minorities that made the case for of the few true African irredentist movement with a recognizable national basis.
On the other hand, the Somali people/nation is organized by tribes/clans, many of which still tied to their nomadic current or recently past lifestyle; lineages are quite important in defining one's identity and allegiances.
As a consequence of the above, Somalia has been unusually aggressively nationalist (as a bonus, they could frame their irredentist wars as both anti-colonial and anti-Communist, though for a while Barre himself had some vague pro-Soviet leaning). I don't have any figure, but I think that the Somali focus on the military was proportionally very high ever for African military dictatorship standars. And economy was a disaster even by African poor countries standards. After the defeat in the Ogaden war, things started to go down the toilet rather consistently.
Barre relied increasingly on tribal power as opposed to nationalist rethoric, and could afford to repress dissent with increasingly heavy hand with the West supporting him against pro-Soviet Ethiopia and South Yemen.
This pissed off a lot of tribes and regions, especially in the North, and then his regime collapsed and a seemingly "warlord interlude as usual" came forth, triggering a humanitarian crisis (again, as usual). But it was the end of the Cold war, there was some Islamist infiltration, the UN were unusually able to meddle, and the foreign intervention became a unholy mess that made any understanding between factions more difficult. The UN mission withdrew a little embarrassed, and the ensuing chaos was left to itself, except occasional Ethiopian/Kenyote/Jihadi islamist meddling, and of course, except everybody profited of the failed state situation to fish in the waters around Somalia. This in turn forced locals to shift to piracy.
An Islamist militia popped out, Taleban style, building upon general populace war-weariness to impose control and offer security (again, nothing unheard of elsewhere). They could have unified most of the country except maybe Somaliland in the North (which, united in its own identity by Barre's repression, managed to avoid the worst of the ensuing chaos). But it was after 9/11 and those guys were more than suspect in the eyes of the West, so the US supported an Ethiopian invasion that broke the back of the Islamist and put the squabbling mess of tribal factions that styles himself as Somali government, essentially a diplomatic construct, again in charge. That's the sort of things that seem to call for insurgency, and isurgency was.
All this time economy deteriorates, people lose any trust in the government, if they even know what such a thing could be, and foreign powers meddle at will.
That's my understanding of the situation in a nutshell.