(CNN) — Space and silence are rare commodities amid the sweaty souks of Morocco's tourist magnet Fes.
But Morocco's historic madrasas -- religious schools -- have for centuries provided an oasis of contemplative calm amid the chaos of their teeming towns.
Sitting in the quiet of a shaded courtyard and soaking in the culture, just as students of the Koran and Islamic law did for centuries in this very same space, I admire the stunning architecture of Bou Inania Madrasa, one of Morocco's ancient Islamic law colleges.
Marble floors give way to mosaic tile walls, immaculate plasterwork, cedar lattice and intricately carved wooden eaves and awnings.
Embellished by linear motifs, geometric patterns and Islamic calligraphy, Bou Inania is remarkable.
Layers of history
Where some architecture pleases with its simplicity, Morocco's historic madrasas beguile with layer upon layer of complex design. They are among the most alluring structures in the country.
Many of the original madrasas are no longer centers of education and are open to travelers looking to venture beyond Morocco's heavily touristed souks and palaces.
Their significance extends far beyond beauty.
Madrasas were key institutions of higher education in Morocco for hundreds of years, after proliferating in Arab countries from the 12th century.
Bou Inania was founded in the 14th century by Abu Inan Faris.
Ronan O'Connell, CNN
Their curricula focused on the central Islamic text, the Koran.
CNN's James Williams explores the Moroccan city's aesthetic traditions and contemporary design.
In a country where about 99% of the population are Muslim, madrasas were revered colleges where young men memorized the Koran and were taught the intricacies of Islamic law.
Arabic literature, logic and mathematics were also studied by students, who typically sat together in the gorgeous central courtyard of the madrasa.
Funded by charitable endowments, madrasas offered their students free tuition, as well as lodgings, which were typically on the upper floors of the building.
It wasn't until the 20th century that madrasas lost their prestige in Morocco and other Islamic nations as western-style universities -- which unlike madrasas permitted women to study -- gained favor.
Learning amid the labyrinth
In Morocco, I visited three of the country's most important ancient madrasas -- Bou Inania in Fes, Ben Youssef in Marrakech and Abu-al Hassan in Sale.
Each madrasa was founded in the 1300s during the time of the Marinid, a Sunni Muslim dynasty which ruled Morocco and other parts of northern Africa between the 13th and 15th century.
The Marinids made Fes their capital in 1248 and just over a century later Bou Inania was constructed.
It was built at great expense in the Fes medina, an ancient maze-like neighborhood lined with timeworn madrasas, palaces, mosques and mansions.
A UNESCO World Heritage site, Fes medina is one of Morocco's biggest tourist attractions.
The meticulously-restored Bou Inania is a haven amid the medina, which can be overcrowded with visitors and persistent hawkers.
Walking through the madrasa's enormous brass entrance doors, I felt a welcome sense of calm.
Two couples sat quietly in its central courtyard, which is flanked by a prayer room and overlooked by the second floor of former student lodgings.
Abu-al Hassan is an overlooked treasure in the city of Sale.
Ronan O'Connell, CNN
Among Morocco's finest examples of Marinid construction, Bou Inania, Ben Youssef and Abu-al Hassan each borrow heavily from the Moorish school of architecture.
Cross the desert, rest in opulent gardens and follow the tracks of Yves Saint Laurent and Winston Churchill in the Moroccan city.
Their walls are splashed with the motifs and decorative tiles synonymous with Moorish architecture.
There seems to be barely an inch of each madrasa which is denied decoration. Every pillar, wall, door, floor, window, arch and ceiling is a work of art.
It seems extraordinary that I have such opulence all to myself as I walk into Abu-al Hassan in Sale to find it empty, apart from an elderly man controlling the front door.
Compared with Bou Inania and Ben Youssef, which are located in the center of heavily touristed cities, this madrasa is isolated and largely overlooked by travelers.
The old walled city of Sale is perched on the edge of the Atlantic Ocean, separated from the national capital Rabat only by the Bou Regreg river. Tucked away at the end of a narrow alley, behind a school and a mosque, Abu-al Hassan is considerably smaller than Ben Youssef and Bou Inania, but is scarcely less grand.
As I tilt my head towards its ceiling, light pours down through the second-floor windows, reflecting off the colorful glazed tiles which adorn the madrasa's floor and forest of pillars.
I don't have the same luxury of solitude when I visit Ben Youssef, the most famous and most visited of Morocco's madrasas.
CNN's James Williams rides a camel, savors the slow food and enjoys the Marrakech International Film Festival.
There must be at least a hundred people swarming through this madrasa when I find it at the end of a winding alley in the noisy, touristy medina of Marrakech.
The hustle and bustle, however, fades as soon as I step foot into its central courtyard.
It's among the most magnificent man-made spaces I have ever seen. The level of craftsmanship in the courtyard and throughout the madrasa's more than 100 rooms is so phenomenal that it is distracting.
All around me visitors are awed into silence as they inspect the structure from close quarters, running their fingers across its surfaces and marveling at its complicated designs.
It can't have been easy for the former students of Ben Youssef to concentrate amid such grandeur.
Many decades after the classes have finished, Morroco's madrasas continue to be a place of study. Except now the curriculum is beauty.