How to create Datarepository? Similary UserRepository

I’m trying to create something like the UserRepository of mezzio-authentication.
Let me explain, I want to have the possibility of creating adapters, so that the data of the module that I am developing, can be obtained from a flat file, from a database or even from a rest web service