Set the oven to 375°F (190°C). Grease a 9x13-inch baking dish with butter or cooking spray.
Wash, peel, and thinly slice the potatoes (about 1/8-inch thick) using a knife or mandoline slicer for even cooking.
In a saucepan over medium heat, melt the butter and sauté the onions and garlic until fragrant and softened.
Stir in the flour, cooking for one minute to create a roux. Slowly whisk in the heavy cream or milk, stirring continuously to prevent lumps.
Season with salt, pepper, thyme, and nutmeg, letting the sauce simmer until slightly thickened.
Arrange half of the sliced potatoes in the baking dish, slightly overlapping them.
Pour half of the creamy sauce over the first layer, then repeat with the remaining potatoes and sauce.
If using cheese, sprinkle Parmesan or Gruyère over the top for a golden, crispy finish.
Cover the dish with foil and bake for 40 minutes.
Remove the foil and continue baking for another 20-25 minutes, or until the potatoes are tender and the top is golden brown.
Allow the scalloped potatoes to cool for 10 minutes before serving.
Garnish with fresh parsley or thyme, and enjoy.