The software at a given layer is independent of the other layers. The programs at each layer on one machine are only concerned with the corresponding program on the other computer.
For example, an e-mail client sends a message directly to an e-mail server without worrying about how it will get there and whether or not it will have errors. It is not aware of lower level concerns.
Similarly, a TCP program can assume a segment will be delivered to the TCP program running on the machine it is temporarily connected to. Since both programs use the standard segment format, the receiving TCP program will have no problem unpacking the segment, and passing the application data to the correct application program (as determined by the destination port number).
The IP program on the sending router is only communicates with the IP program on the routers it is connected to. Since they both use the same, standard IP packet format, they have no trouble communicating.
Ethernet and other Data Link programs only need to be able to communicate with the Data Link software on the computer they communicating with.