Heat the olive oil in a large skillet over medium heat. Add the diced onion and sauté until translucent, about 5–7 minutes.
Add the minced garlic and cook for 1 minute, until fragrant.
Add the ground meat along with the Italian seasoning, red chili flakes, salt, and black pepper. Brown the meat, breaking it up as it cooks, for 8–10 minutes.
Pour in the marinara sauce. Stir well, cover, and let simmer for 10 minutes.
Meanwhile, cook the spaghetti according to package instructions until al dente. Drain and set aside.
Mix the cooked pasta and sauce until well combined, then layer into a baking dish and top with the cheese mixture.
Cover the dish with foil and bake for 25–30 minutes. In the last few minutes, remove the foil so the cheese can melt and bubble on top.
Let rest for at least 5 minutes before serving — or up to 15 minutes if you want clean, sliceable portions like a casserole.