What is inside an EPUB file?
An EPUB is a ZIP archive with a fixed skeleton: a file called mimetype, a META-INF folder with container.xml in it, an OPF file that lists everything else, and the book itself as XHTML chapters with their CSS, images and fonts. The mimetype file is 20 bytes long and holds application/epub+zip and nothing more, not even a line break. The EPUB 3.3 standard says it must come first in the archive and must not be compressed, so every valid book shows the same bytes near its start: the PK that opens any ZIP, the name mimetype at byte 30 and the media type at byte 38, as the spec's media type registration lists them. A program can tell an EPUB from an ordinary ZIP without unpacking anything.
To see the rest, copy a book, change the ending to .zip and open it, or run unzip -l book.epub in a terminal. Only two names at the top level are reserved, mimetype and META-INF, and container.xml is the one file that META-INF must hold. Its job is small: a rootfile element gives the path of the OPF file. In the spec's worked example that's EPUB/As_You_Like_It.opf, but the folder can have any name. META-INF may also hold encryption.xml, which names any encrypted files and any embedded fonts whose first 1040 bytes have been scrambled so that they can't be lifted out and reused as they are; the standard calls this obfuscation and says plainly that it isn't encryption.
The OPF file does three jobs. Its metadata section must give a title, an identifier, a language and a dcterms:modified timestamp, and the spec makes everything else optional, the author included (the fields are covered in EPUB metadata and Dublin Core). The manifest lists every file the book uses, each with its media type. One item must carry properties="nav", and the cover picture can be flagged with cover-image. Then the spine puts manifest items in reading order. An entry marked linear="no" belongs to the book but sits outside the main run of text: the spec's examples are notes, descriptions and the answers to exercises, which a reader app may show in a pop-up or leave until the end.
Chapters are XHTML, which is HTML written with XML's stricter syntax, so every tag has to be closed. Next to them sit CSS style sheets, images and fonts, in whatever folders the maker chose. The navigation document is one more XHTML page, and it must contain exactly one nav element of type toc: that's the table of contents. Books made for EPUB 2 used an NCX file for this instead, and EPUB 3 still allows one as a legacy feature, so a book can carry both. Readwyn's reader builds its contents panel from whichever of the two the book has.
A book that you've unpacked and edited has to go back together by the same rules: mimetype first and uncompressed, and every other file either stored or compressed with Deflate, the only two methods the spec allows. The standard itself names EPUBCheck as the checker the publishing industry relies on (how to run it).