Preheat oven to 350°F (175°C). Grease a 9x13-inch baking dish.
Cook spaghetti in salted water for 2-3 minutes less than package directions. Reserve 1/2 cup pasta water, then drain.
Return pasta to pot, add butter and toss until melted. Add beaten egg and toss quickly to coat without scrambling.
Brown ground beef and sausage in a large skillet over medium-high heat, breaking into crumbles. Add onion and garlic and cook until soft, about 8-10 minutes.
Drain excess fat, then add Italian seasoning, garlic powder, onion powder, and red pepper flakes (if using). Cook 1 minute until fragrant.
Pour in both jars of marinara sauce and stir. Simmer on low for 10-15 minutes. Season with salt and pepper.
Mix softened cream cheese, ricotta, and 1/4 cup Parmesan in a bowl with salt and pepper until smooth and lump-free.
Toss the buttered spaghetti with 1/2 cup of the meat sauce. Spread half of the spaghetti evenly in the prepared baking dish.
Dollop the entire cream cheese and ricotta mixture over the pasta and spread evenly. Sprinkle with 1/2 cup mozzarella.
Top with remaining spaghetti, then the remaining meat sauce. Sprinkle with remaining 2 1/2 cups mozzarella and 1/4 cup Parmesan.
Cover loosely with foil and bake for 30 minutes. Remove foil and bake uncovered for 15-20 minutes until golden and bubbly.
Let rest for 10-15 minutes before serving. Garnish with fresh basil or parsley.