The Underworld Yamen
At death the soul is summoned first to the Chenghuang court, where its ledger is checked against the living registers. He is the magistrate's mirror — the same jurisdiction, one level below.

道法自然
城隍爺
Spiritual Magistrate of the City
Festival · Temple fairs vary by city

Spiritual Magistrate of the City
Every walled city had its own City God — a spiritual magistrate mirroring the human official, judging disputes, escorting souls, and protecting walls and people. The office was usually filled by a historical official famed for justice.
Festival · Temple fairs vary by city
History · 史记
Every Chinese walled city has its Chenghuang — god of the moat and wall — a shadow magistrate ruling the spirit side of the same jurisdiction. The Taiping Guangji preserves early tales of Chenghuang gods judging the dead; by the Song the cult was universal. In 1370 the founding Ming emperor Zhu Yuanzhang rationalized the pantheon the way he did the bureaucracy: he enfeoffed Chenghuang gods in three ranks — king, marquess, count — corresponding exactly to province, prefecture and county, complete with official robes and staffs.
His office mirrors the yamen: clerks, constables, ledgers of merits and demerits, and a night-tour on which he inspects his city in palanquin, escorted by paper guards.
At death the soul is summoned first to the Chenghuang court, where its ledger is checked against the living registers. He is the magistrate's mirror — the same jurisdiction, one level below.
The post is not hereditary but earned: upright officials and martyrs were believed to be appointed Chenghuang of their city after death — a second career in the spirit bureaucracy.
太平廣記
The Song encyclopedia of tales preserving the earliest records of Chenghuang gods judging the dead.
明實錄
Records the 1370 enfeoffment system that organized Chenghuang worship to mirror the imperial bureaucracy.