Well, there is no documentation really, because a plugin can be anything from a simple function to something really powerful like the patterns plugin. And also, as of now, there is no standardized way of creating a plugin.
As a starting point, check out existing plugins.
Also, see this topic.