Documentation on how to write a custom Identity provider

Good afternoon. I’m trying to write a custom identity provider (for Keycloak 21.1.1) to integrate with another system that uses a custom protocol.
I sifted through the documentation but couldn’t find any tips / best practices on how to do it. I tried to use other projects on Github that did something similar but couldn’t make it work.
Does anyone know where I could find a “reference implementation” or something along that way? how will the jar have to be packaged to be recognized by keycloak? Thanks.