The practice of erecting temples for the guardian deities of cities was common across civilizations in the ancient world. A well-known example was the goddess Athena as the protector of Athens. The practice continued with the advent of Christianity, often through the saints associated with a particular town and its place of worship. For China, whose civilization has been continuous for some 5,000 years, the practice continues to this day with Chinese folk religion honouring gods that often represent heroic figures that were deified after their death.
This is well illustrated by a temple dedicated to protecting modern Shanghai – China’s largest city (pop. 23 million). The Shanghai Temple of the Town God (Chenghuang Miao) is the best known Daoist temple in Shanghai.
"The City-God Temple of Shanghai: A protective presence,"
Culture Mandala: The Bulletin of the Centre for East-West Cultural and Economic Studies: Vol. 11
, Article 4.
Available at: https://epublications.bond.edu.au/cm/vol11/iss2/4