Judge Dee, or Judge Di, is a semi-fictional character based on the historical figure Di Renjie, county magistrate and statesman of the Tang court. The character appeared in the 18th-century Chinese detective and gong'an crime novel Di Gong An. After Robert van Gulik came across it in an antiquarian book store in Tokyo, he translated the novel into English and then used the style and characters to write his own original Judge Dee historical mystery stories.
Judge Dee
The county magistrate or local magistrate, known by several Chinese names, was the official in charge of the xian ("county"), the lowest level of central government in Imperial and early Republican China. The magistrate was the official who had face-to-face relations with the people and administered all aspects of government on behalf of the emperor.
A magistrate holds court (late 19th century)
Ming dynasty magistrate.
The Kaifeng Court of Bao Zheng, a tourist attraction modeled after typical magistral office.
Yamen at Shaoxing Fu, Zhejiang Province, 1803.