Law Enforcement in Medieval Towns
According to this website about Medieval Demographics:
A well-kept medieval city will have 1 law officer (guardsman, watchman, etc.) for every 150 citizens. Slack cities will have half this number. A few rare cities will have more.
Taken together with the wall info from Sarriesfan, this could give you a rough estimate of defenses.
Castle
The book "Castle" by David Macaulay could be a valuable resource to your project. In it, Macaulay describes how a castle's town would be attached to the castle:
The town wall was to be 20 feet high, 5.5 feet thick, and strengthened at intervals of 150 feet by projecting U-shaped towers.
A battlement walkway was planned for the entire top of the wall.
You can buy the book here on Amazon, and on the same page, you can click on the cover's "Look Inside" icon to read through some of the text, see an example of castle and attached town layout, as well as construction methods and materials.

Macaulay has a series of very informative books on all different types of building projects throughout history and from around the world, including: Roman town, Pyramid, Underground Subways, Mosque, Mill, Cathedral, etc.