Short answer
Run defaults write com.apple.dock persistent-others -array-add '{"tile-data"={"list-type"=1;}; "tile-type"="recents-tile";}'; killall Dock in Terminal. A Recent Applications stack appears by the Trash. Right click it to switch to Recent Documents, Recent Servers or Favourite Items.
macOS can show a few recent apps in the Dock (System Settings, then Desktop and Dock, then Show suggested and recent apps). But that only covers apps. For recent documents you need a recents stack.
Add a recents stack
defaults write com.apple.dock persistent-others -array-add '{"tile-data"={"list-type"=1;}; "tile-type"="recents-tile";}'; killall DockThe stack appears on the right side of the Dock, next to the Trash.
Change what it shows
Right click the stack and pick Recent Applications, Recent Documents, Recent Servers, Favourite Volumes or Favourite Items. You can also choose whether it opens as a fan, a grid or a list.
Remove it
Drag the stack out of the Dock, or right click it and choose Remove from Dock.
The catch
Recent Documents shows everything you opened, across all your work. If you code in the morning and design in the afternoon, both get mixed in one list.
DockAlly keeps a separate stack by the Trash for each Dock profile. In Coding it shows the projects you opened. In Designing it shows a grid of recent images you can drag straight out.