Preheat the oven to 400°F and grease a 9-by-13-inch baking dish.
Cook the spaghetti in salted water for two minutes less than the package directions recommend; drain well.
Brown the sausage or ground beef with the onion, breaking the meat into small pieces as it cooks.
Drain the excess grease, add the garlic, and cook for 30 seconds.
Stir in the tomato sauce and Italian seasoning.
Combine the cottage cheese or ricotta, egg, Parmesan, salt, and pepper in a separate bowl.
Layer the spaghetti, half of the meat sauce, the cheese filling, and the remaining meat sauce in the baking dish.
Sprinkle the mozzarella evenly over the top.
Bake uncovered for 30 to 40 minutes, until bubbling and golden brown.
Rest for 10 minutes and garnish with fresh parsley before serving, if desired.