You never put your defenses right on the border. You should place them strategically.
That’s why the Maginot and Siegfried lines worked at the beginning of World War II. At places the Siegfried was 5 or 10 miles back from the French border. The French invasion of Germany in 1939 quickly gained the territory in the border area to a depth of several miles, but stalled out when they got to the Siegfried despite an overwhelmingly superior force. The campaign devolved into a back and forth in the area in front of the Siegfried over the next month or so, but with no real threat to the area defended by the Siegfried.
“Fixed fortifications are a monument to man’s stupidity’’. - General George Patton.