To put it simply, a kasbah is an official fortified residence, often defended by armed people. It may be that of the sovereign (for example the Kasbah of Tunis, which has largely disappeared today), or that of the representative of power in the provinces. By extension, this word ended up designating the district adjoining this building.
So to speak, all the cities of the Maghreb have their kasbah. The use of it spread in the 12th century under the leadership of the Almohad dynasty installed in what is now Morocco. Over time, they were integrated into larger defensive works including fortifications and ramparts. This is the case, in particular, of the kasbah of Sfax, which today stands as a continuation of the urban wall as a monument flanked by two towers and an artillery bastion dating back to the 16th century.
The kasbah has undergone careful restoration which has restored it to its original majesty.