There is an FAQ
in this forum which discusses the details of the ePub format.
If you want to see how to program with ePub, you could consider looking at the Calibre source. I'm not sure how Kovid has it licensed, though. You will need to be careful if you're embarking on a commercial project.