The setting is the rural, pre-civil war American South in St. Petersburg, Missouri.
Mark Twain grew up in Hannibal, Missouri. His childhood is likely a big inspiration for The Adventures of Tom Sawyer. Twain himself was a mixture of Tom and Huck Finn as a child. In the small town where Tom lives, everyone knows everyone else. There is not much to the town. It is made up of a few houses, a church and school, and other municipal buildings.
The locust trees were in bloom and the fragrance of the blossoms filled the air. Cardiff Hill, beyond the village and above it, was green with vegetation, and it lay just far enough away to seem a Delectable Land, dreamy, reposeful, and inviting. (ch 2)
Tom pretty much has the run of the “poor little shabby village of St. Petersburg” (ch 1), and his adventures are specific to the time period. For example, since it is pre-civil war, there are slaves (influencing The Adventures of Huckleberry Finn). Also, the rural location makes it possible for Tom to get into adventures exploring rivers and caves.