PKHeX is open source, read the source code or step through with a debugger if you must understand how it works. There's way too much to describe to waste time writing guides and wikis for every single file format and interaction.
X/Y's format is described here, for both the raw save archive and main:
https://projectpokemon.org/home/docs/gen-6/xy-save-structure-r82/