Where are the flakes source code

Hey,

where does the source code for the definition of flakes lie. Like what fields are allowed and how to interpret them. I’m especially interested in the templates part of flakes. I want to get a better understanding how things are done under the hood. I have skimmed through the libflake section in the nix repo without finding anything about templates. I also run ripgrep, searching for lines with “template” in it without finding anything of notice. Is there another repo or did I just missed it?

Found them in the nix subdir, not sure if this is the whole definition but the templates part seems to be their at least