I'm trying to better understand the difference between IP fragments and TCP segments (https://www.shubhsblog.com/tech/difference-ip-fragmentation-tcp-segmentation.html) and there's one thing I'm not able to theoretically figure out. If the netowrk layer automatically breaks things up into fragments to accommodate network interfaces, why does TCP need to break up its messages into segments? Shouldn't all that be done at the network layer anyway?
IP packets have a size limitation (65,535 bytes), so a reassembled packet is limited, and the application would need to send chunks no larger than the theoretical IP packet payload size (total packet length minus the packet header for IPv4). On the other hand, TCP can handle an arbitrarily large (mega-, giga-, etc. bytes) data stream by segmenting it.
Also, IP fragmentation has fallen out of favor because of the resources used by the intermediate routers necessary to preform the fragmentation, and the possibility of fragment attacks on the destination hosts.