With some exceptions, the US-Canada border is mostly determined by the 49th parallel from Vancouver Island to Lake Superior in the West and then by the Great Lakes in the Midwest. The border then follows the St. Lawrence out of Lake Ontario for about 100 miles before cutting across the 45th parallel for about 150 miles until it follows Halls Stream north for a bit. It then seems to be quite random, thought perhaps it runs along a ridge, as steams look to start on either side of the border on google maps. The border then runs with the St. John River for about 30 miles, breaks for 80 miles for some long straight borders on the north side of Maine, follows the St. John River again for 100 miles, has another straight 80 miles before following the St. Croix River the the Atlantic.
I'm terribly curious about how the elements of the US-Canada border formed east of the Great Lakes. The St. Lawrence looks like the obvious border, but I'm sure there's a story as to why it didn't form that way.
A very brief answer can come from looking at patterns of European colonialism. The Mississippi river, the St. Lawrence, the Columbia, the Fraser, all these are rivers that when they reach the ocean they come out in the middle of a political unit rather than as a boundary. This is largely because while rivers can represent borders, they more commonly represent the center of a drainage system, whose inhabitants move back and forth, and colonial powers tend to compete for control of the mouth of these systems, and to develop settlement around them.
In the case of the St. Lawrence, this meant that France brought settlers to the river, who settled it on both sides up the river, forming a political unit, and while later an international border was created along a portion of the river, it was largely undeveloped land further upstream than these communities that was able to be divided in such a way. This portion of the boundary was determined in 1783 at the treaty of Paris.