What php files handles routing?

The parse_request method in the WP class parses the URL with the rules generated by the WP_Rewrite class. This process converts the request into a set of query variables that the WP class can then use to generate the main query.