How does flattening work?

I am a college student. The project I am currently working on is similar to the functional requirements on ProfilmOnline. I’m now very curious about how flatten works, and although I’ve implemented it myself, my overall approach still falls short. I would like to ask if you can provide the website implementation methods and ideas.