Preheat Oven: Preheat your oven to 350°F (175°C). Grease a 9x9 inch or shallow 2-quart casserole dish.
Prepare Sauce: Melt butter in a skillet over medium heat. Add chopped onion and cook until soft. Add minced garlic and cook for 1 minute. Whisk in flour and cook to form a roux. Gradually add milk, whisking constantly, and cook until thickened. Stir in thyme, parsley, cayenne pepper, salt, and pepper.
Assemble Dish: Layer ¼ of the potato slices in the dish, cover with ¼ of the sauce. Repeat layers, ending with sauce on top. Sprinkle with remaining thyme and parsley.
Bake: Cover with foil and bake for 45 minutes. Remove foil and bake uncovered for 30-45 minutes until tender. Broil for 1-2 minutes if desired for a golden top.
Serve: Let cool slightly before serving.