A ribat was originally a fortified structure, organized around a courtyard, with a double story perimeter of rooms. Typically, a ribat be used by religious warriors as an outpost. Its architectural organization is similar to that of a caravanserai, with storage rooms and stables on the ground floor and sleeping quarters on the upper level. As such, the ribat typology lends itself to adaptation for use as a caravanserai.
It is not clear whether the Ribat-i Mahi originally had a militant function, but it did function as a caravanserai, providing lodging for travelers along a trade route. Located along the ancient trade route between Tus (near present-day Mashad) and Sarakhs, the Ribat-i Mahi is known to be the oldest extant example of a ribat. It was built in 1019-1020 by Sultan Gazneli Mahmut in memory of Firdwasi, the author of the Persian epic, the Shahname.