Heat the oven: Preheat to 350°F (175°C). Grease a 9x13-inch baking dish or similar casserole.
Boil the pasta: Cook spaghetti in well-salted water until just shy of al dente. Drain, then toss with a splash of olive oil so it doesn’t stick.
Brown the meat: In a large skillet over medium-high heat, warm olive oil.
Add onion with a pinch of salt and cook until soft. Stir in garlic for 30 seconds. Add the meat, breaking it up.
Cook until browned; drain excess fat if needed.
Build the sauce: Stir in marinara, Italian seasoning, red pepper flakes, and a few grinds of black pepper. Simmer 5–7 minutes so flavors come together. Taste and adjust salt.
Make the creamy layer: In a bowl, beat cream cheese with sour cream until smooth and spreadable.
Season with a pinch of salt and pepper. If it’s stiff, let it sit a few minutes or warm briefly to soften.
Combine pasta and some sauce: Toss the drained spaghetti with about 1 cup of the meat sauce, just enough to coat. This keeps the pasta from clumping and drying out.
Layer in the dish: Spread half the sauced spaghetti in the baking dish.
Dollop and gently spread half the cream cheese mixture over it. Add half of the remaining meat sauce, then sprinkle with half the mozzarella and Parmesan. Repeat the layers with the rest of the ingredients.
Bake: Cover loosely with foil and bake for 20 minutes.
Remove foil and bake another 10–15 minutes, until the top is bubbly and lightly golden.
Rest and serve: Let it rest 10 minutes so it sets and slices cleanly. Garnish with chopped basil or parsley. Serve warm.