2. In ancient scriptures

According to Hindu Vedic Scriptures and Hindu Mythology, the world was created by Brahma, the Creator. Lord Bramha first created 16 Sons from various parts of his own body. Chitragupt, his 17th creation, is believed to be created from Lord Bramha's Mind & Soul.

Shree Chitraguptjee is divine incarnation in human form, and is called Kayastha since he is the only creation of Lord Bramha who was created in entirety (kaya) from the Lord's body, unlike the other 16 sons who were created only from various parts of the body. Shree Chitraguptjee (and hence the Kayastha's) were accorded a dual-caste status, namely Kshatriya (Warrior) and Brahmin (Learned). Shree Chitragupta Maharaj had two devoted wives- Devi Nandini and Devi Shobhavati. Devi Nandini was the daughter of Shradhadev Manu, Kshatriya, and Devi Shobhavati was the daughter of Susharma Rishi, a Brahmin. They had 12 divine sons who started the 12 clans of Chitraguptavanshi Kayastha.

"मषी भाजन सन्युक्तश्चरसि त्वं महीतले
लेखनी कटनी हस्त चित्रगुप्त नमोस्तुते
चित्रगुप्त नमस्तुभ्यम लेखाकक्षर दायाकम
कायस्थ जाति मा साद्य चित्रगुप्त नमोस्तुते"

The Kayastha trace their genealogy from Lord Chitragupta. It is said that after Lord Brahma had created the four Varnas (Brahmins, Kshatriyas, Vaishyas, and Shudras), Yama (Dharamraj) requested Lord Brahma to help him record the deeds, both good and evil, of men and to administer justice.

According to the scriptures, Lord Brahma went into meditation for 11,000 years and when he opened his eyes he saw a man holding a pen and ink-pot in his hands, as well as a sword girdled to his waist. Lord Brahma spoke: ``Thou hast been created from my body (Kaya); therefore, shall thy progeny be known as the Kayasthas. Thou hast been conceived in my mind (Chitra) and in secrecy (gupta); thy name shall also be Chitragupta. Brahma then enjoined him to dispense justice and punish those who violated the dharma. Thus, the Kayasthas were accorded a dual caste, Brahman/Kshatriya.

Ancient temple of Shree Chitraguptajee in Khajuraho

In the legends of Chitragupta as well as in the Vedas, he is referred to as the greatest king, while the rest are "Rajakas," or little kings.

चित्र इद राजा राजका इदन्यके यके सरस्वतीमनु ।
पर्जन्य इव ततनद धि वर्ष्ट्या सहस्रमयुता ददत ॥ RIG VEDA Book 8/ Hymn 21/ Stanza 18

In the Garud Purana, Chitragupta is hailed as the first man to give the script.

"Chitragupta namastubhyam vedaksaradatre" (Obeisance to Chitragupta, the giver of letters)

The Rig Veda mentions an invocation to be made to Chitragupta before offering sacrifice. There is also a special invocation to Chitragupta as Dharmraj (Lord of Justice) to be made at the performance of shradh or other rituals.
"Om tat purushaya vidmahe Chitragupta dhimahi tena lekha prachodayata."

The priests also pay reverence to Shri Chitragupta :

"Yamam Dharmarajya Chitraguptaya vain namah."