What happens at a low level when a directory from Finder is dragged to an app icon, such as TextMate? The directory that was dragged will then open in the application it was dragged to (if the app accepts the path). What happens at the low level?

How does the application know it can open that path?
How does Finder provide the application with the path to open?
At a low level, everything on the disk is a file. So a folder is a special file that contains directory information pointing to more files.

The application is told that the file should be opened - and it's up to the program to determine what type of file was passed and decide whether to recursively handle that file by reading the files contained in that folder or take some other action.

Similarly, you can select many items in Finder and drop them on an icon and the same sort of file open event is posted to the application so that it can process the files and do what needs to be done.