The ancient tribes living around the northern territory of modern Nepal seem to have been less influenced by the fourfold
Varna system of Hinduism. Instead, nature worship, shamanism and ancestor worship was more common in sync with Tibetan spirituality among the Sino-Tibetan groups. Even
Khas/Parbatiyas who are today overwhelmingly consolidated into the four
Varna structure, have been following Masto tradition since ancient times whereby Masta tutelary deities known as
bange-masta, bahiramasta, thado-masta, bahra-masta, athahra-masta are invoked and worshipped. This form of Masto worship among the
Khasas is apparently not related to any Vedic scriptures and tradition of the Gangetic plains of India, and seems more closer to pre-Buddhist Shamanistic
Bon practice of
Tibet. The earliest detailed record of the caste system in Nepal has been found in
Kathmandu Valley from the 5th century CE during the
Licchavi period (400-750 CE) with mentions of the presence of Brahmans (Vedic priests) and
Chandala (untouchables). The existing caste structure as introduced by the Lichhavis was later fundamentally restructured during the reign of King
Jayasthiti Malla (1380-1394). This restructuring was a result of over a millennia of newer Aryan immigrants from the plains since the time of the Lichchavis. Series of Aryan migration to Kathmandu led to increased population and formation of a complex urban and caste-based society. Jayasthiti Malla's restructuring also converted celibate Buddhist monks to householder status and inside the hierarchic fold for the first time to form the caste of
Vajracharya and
Shakya. It also solidified the supremacy of
Kanyakubja Brahmin descendants like the
Rajopadhyaya Brahmins over other priests like Maithil Brahmins. Karmacharyas and
Joshis were all-together stripped off their Brahmin status by these new and arguably more well-read Brahmins, and assimilated them in the Kshatriya/Chathariya. The restructuring also yielded power to newly formed Malla aristocracy of the Chathariya Shrestha who formed the new powerful aristocratic caste of the Malla kingdom. Hence, the present Newar society's foundation firmly stands on this restructuring by Malla as Newar society continues to comprise the 4 varna and 64 different caste groups which were hierarchically allotted in Jayasthiti Malla's time according to the classical and religious Hindu scriptures like the Manusmriti.
Gorkha king of the
Chaubisi principality,
Ram Shah (1609-1636) is noted to have introduced some rules and regulations about relations between different groups of people in the Gorkha kingdom too. As the Shah rulers conquered more territories and people, the concept of caste hierarchy more firmly applied as an organizing principle to consolidate diverse people under their authority. In 1854, early in the period of Rana rule, a National Legal Code (Muluki Ain) was proclaimed that laid out detailed codes for inter-caste behavior and specified punishments for their infringement. ==Traditional caste system==