I've had trouble with mucus and allergies as well as some other issues. I've systematically trying to cut out the vast majority of processed food in my diet as well as diversifying my diet.
It's actually quite a challenge and requires a lot of retraining even for someone well versed in nutrition. It's so easy to fall into the endless number of traps: dairy and fig newton bars, granola bars, etc. the food industry has created an endless array of seemingly healthy items but that are actually all come from the same three ingredients: processed wheat, sugar and oil. and we as consumers tend to vastly overestimate the amount of healthy ingredients in something because we aren't aware of the caloric densities of everything that goes into it (sugar is 4 cals per gram, oil is 9 cals per gram, veggies are 0.3 cals per gram -> this ends up being very misleading when you compare relative amounts by eyeball). For example: did you know that pumpkin pie is barely 3% pumpkin? i was surprised as well. i didn't realize this until I actually calculated the numbers, detailed here: https://kale.world/pumpkin-pie-is-only-3-percent-pumpkin/
Personally, my general rule of thumb is, if the food didn't come directly from nature: (like a tree or bush or ground), then it's most likely a food like substance that has been processed (and thus goodness removed from it). so, i make most of my diet come from the primary 6 food groups: fruits, vegetables, beans, whole grains, tubers, nuts/seeds. If you do this, you'll get all the magnesium and fiber you need because most of the real food groups are quite high in magnesium, fiber, protein and almost every micronutrient (on average).