Arduino IDE, Underlying Code and Libraries
Just check the source code. Specifically look at Arduino.h, main.cpp and wiring*.

These files should also be present in the Arduino application folder somewhere, but you'll have to go through quite a few subfolders to find them.

The different boards have different .h file that will specify the pin-numbers and other chip specific data.

The "auto detect" functionality is done by keywords.txt files. At least for libraries. That way if you install a new library with keywords.txt file, the library functions-names are recognized. 

The processes of taking all these files, and the users code, and compile it all whole story on it's own.