[5.0] Use interfaces as typehints

Wherever possible, we should use the 

This is still work in progress. Some components (database, foundation, queue, routing) have not yet been reviewed. And some questions came up, which I'll have to tackle later.

I also want to see whether tests are now failing in some places.