SEO has little to do with the code and more to do with people staying on the site when they're presented with the site as a search result. The reason for the ranking is because of all of the social traffic associated with the site before. If you change those URLs regardless of how bad the code looks to you, it can cost the site dearly.
The best thing is to make the new site have the same directory structure as the old site. Google will see that you've made major changes to the code, so they will take time to go through and look at the code for snippets and content (you may disappear from the rankings temporarily), but they shouldn't have to map any new URLs if you're simply replacing an old site. Additionally, links in places like blogs and other sites will not cause bounced traffic or 404 errors because the pages can't be found. Remember Google not only tracks you with their search engines, but they also do it with mobile devices, browsers like Chrome, plug-ins in browsers, and places like links in g-mail. So they will find out about a 404 relatively quickly.
If for some reason you've changed the structure of the site or the folders, directories, etc, or if now you're using something like mod_rewrite
to process user requests, then you'll need to create a 301 redirect from the old pages to the new pages that specifically have to do with the old content. If old content is going away for some reason, do NOT try to redirect that traffic back to anything other than the homepage, in fact it's best to let the search engines know that the page is GONE. That way they can remove it from the rankings. If it looks like you're trying to link to unrelated content, it can damage the overall performance of your domain.
Google and other search engines expect a single page of content from your site, if you keep both sites live for any reason (especially on the same domain), the duplicate content can cost your old page rank a bit.