PKHeX doesn't do full deserialization of the pkm/sav files, it only gets/sets data on demand.
PKM.cs is the base abstraction of the PK* format, with multiple different formats of storing the data across generations (ie PK1/PK2...PK7...).
SaveFile.cs is the base abstraction of save files, with multiple different formats of storing the data across generations (ie SAV1/SAV2...SAV7...).
PKHeX.Core.dll is the class library the GUI uses to power most of the pkm/sav data manipulation. If you add it as a reference to a (.NET language) project, you can use its api to automate your edits. PKHeX also offers plugin capability, where you can program your own toolkit and launch various operations.