At a burger restaurant, the body of a man and woman lie in a final embrace. As Kenyan soldiers launch their assault, pop music is still playing from loudspeakers.

The grisly consequences of an attack by al-Shabaab on Nairobi's Westgate shopping centre are still unfolding. As individual families mourn, Kenya is once again counting the cost of its point position as a regional bulwark against militant Islam. The country has been here before: in 1998 al-Qaida bombed the US embassy in the Kenyan capital; and in 2002 a terror attack against an Israeli-owned passenger aircraft and hotel took place in the coastal city of Mombasa. Westgate, too, is Israeli owned, but this may be less significant than it might appear.

More important, for the future of Kenya and the continent, are the two competing visions of Africa that the attacks project, a tension for which the crude shorthand is: "crime versus supermarkets". Al-Shabaab emerged from the tradition of the shifta, a word long applied in east Africa to common bandits, but also (less frequently, and depending who was speaking) to rebel groups. There is a continuity between the two usages that challenges the tendency to separate terrorism and criminality into discrete phenomena.

Al-Shabaab is responding, specifically, to Kenyan involvement in a joint African peacekeeping force (Amisom) in Somalia. But like al-Qaida before it (the two groups linked formally in 2011), al-Shabaab is really attacking the very idea of capitalism; not through any greatly developed sense of revolution, but through an inverted sense of what is good for Africa.

In Kenya crime and terrorism are deeply linked, not least by the failure of successive Kenyan governments to control either. Indeed, the Kenyan president, Uhuru Kenyatta (whose nephew has been killed in the attack), and the vice-president, William Ruto, both face charges of crimes against humanity in relation to their alleged role in co-ordinating election violence – Ruto's trial at The Hague has been adjourned for a week to allow him to come home to deal with the crisis.

These attacks are part of a spectrum of banditry, with corruption at one end, terrorism at the other, and regular robbery in the middle. Some Kenyans will feel that the conditions in which the attacks have happened have arisen because of economic growth in a vacuum of governance. Money that should have been spent on security and other aspects of national infrastructure has been disappearing for generations.

Corruption as well as geopolitics made possible a horrific situation in which Muslim shoppers in Westgate were apparently left alive and non-Muslims killed, in a ghoulish travesty of the mixed nature of Kenyan identity.

Ordinary Kenyans rightly want to be able to shop safely, and there is a long history of them doing just that, irrespective of their religion or that of the shop owner. An Ismaili Muslim from Kutch in India, the great Allidina Visram (1851-1916), more or less single-handedly invented the retail trade in Kenya. Muslims have been at the heart of Kenyan commerce for hundreds of years.

The past decade has seen rapid growth of the Kenyan and other African economies. This story of "Africa rising" is intrinsically tied up with the further development of an African middle class, which has brought confidence and investment. A lot of money has gone into commercial property, and particularly the building of supermarkets. But without governance it all looks very shaky.

You can gesture at the transnational problem of Islamist terrorism all you like, but it's just hot air unless you invest in proper security on the ground in your own country, with the right safeguards to civil liberties. For now Kenya must mourn its dead. But unless the corruption stops, and real investment is made in the social fabric, Kenya will once again be faced with systemic shocks it is hardly able to deal with.

Giles Foden is the author of Zanzibar, and The Last King of Scotland