I can see a picture of the template hierarchy here, but where is the actual wordpress code which decides that it's a "category page" or an "archives page" or a "search page"?
wp-includes/template-loader.php is the file which is the template hierarchy. However, by the time that file executes, all the template decisions are already made since all that file does is check for boolean flags (defined in
So all the heavy-lifting and interesting code happens before that at
wp-settings.php line 225:
$wp_the_query = new WP_Query();
and it is definitely inside of the WP_Query class (starting with the constructor in
wp-includes/query.php line 2998) where all the interesting logic happens.