Build Your Own Database From Scratch in C
it walks you through building SQLite from scratch. starts with a REPL, then adds a B-tree, then paging, then persistence to disk
by the end you understand why databases are structured the way they are. not just how to use them