Preheat oven to 350 degrees Fahrenheit (180 degrees Celsius).
Make the Loaf: Add the lentils to 3 cups of water and boil until tender, usually only 5 to 10 minutes as red lentils cook fairly quickly. Drain well.
In a food processor, process the lentils for a few seconds into a coarse paste. Leave some lentils intact for texture. Set aside.
Chop the walnuts finely, or process them in food processor until crumbly. Set aside.
In a large wok, heat the olive oil over medium heat. Add the onion and garlic and sauté until the onions are translucent. Add sea salt and black pepper to taste. Add the celery, carrot, apple and raisins and sauté for another 5 minutes.
Stir in the processed lentils, flaxseed, walnuts, brown rice flour, bread crumbs, thyme, oregano and a little more sea salt and black pepper to taste and the cayenne pepper. Stir well until mixture is well-combined.
Press the mixture firmly and evenly into a large loaf pan or small casserole dish.
Make the Balsamic Apple Glaze: In a bowl, mix together the ketchup, applesauce, balsamic vinegar and maple syrup until combined. Slowly add brown rice flour to thicken as desired. Spread the glaze evenly over the loaf with a spoon or basting brush.
Bake, uncovered, for 50 minutes until the edges are lightly browned. Cool the loaf in the pan for 30 minutes before slicing it. If you try to slice it before it's partially cooled, it may crumble slightly.
Garnish with fresh thyme leaves if desired and serve.