Well if you don't want magic to be 100% mandatory to beat the game, then the first thing you need is an interesting alternative to magic for the player to use. With no competition, spamming magic is always the optimal strategy. By introducing something that is mutually exclusive it forces the player to choose whether they want to invest in magic or in this other mechanic. Each one will need a clear strength and weakness, preferably one that makes sense in your setting.
For example, if magic in your setting is related to the local religion or is some kind of divine gift, you can then limit the number of spells a player can cast but have them replenish their spell stock by visiting temples or shrines. There can also be a non-magical class like an Engineer that can purchase machines to gain new abilities, trading spell slots for an ammo system and being more convenient at the cost of being more expensive to maintain. In this system a Mage might get a fire spell while an Engineer can buy a flamethrower. The Mage can cast his spells for free but only gets so many before he is tapped out. The Engineer on the other hand can get many more uses out of their flamethrower but has to purchase the fuel needed for each use. Same effect, different methods.
The most important balancing factor for this is actually your other classes. Each class should have some variance in resource consumption to make the player choose how they want to allocate their resources to meet their needs.
I feel the class system in
Dragon Quest III does this nicely:
- Soldiers have high Strength and Vitality but low Agility and can equip most weapons and armors, making them hit hard and take lots of hits but slow and usually the last to act in battle. Since they rely on weapons and armor they are one of the most expensive classes in the game.
- Fighters have high Strength and Agility but low Vitality and have few but cheap weapon and armor options, making them glass cannons that often act first in battle. Since they don't really use weapons or armor they are on of the cheapest classes in the game.
- Priests have good healing and utility spells but little in the way of offense. They have surprisingly good health and actually get some weapon and armor options making them almost closer to Paladins if you invest in them. Moderate cost to equip since you'll want to upgrade their gear whenever possible.
- Mages have good attack spells and some utility but are only really good for nuking enemies. They are extremely squishy and have almost no weapon or armor options, so you might end up having them just Attack or Defend against common mobs to conserve their MP. Very low cost to equip.
- Merchants are strong well-rounded characters in the early game and can use many weapons and armors. Their strength is mostly in how well you equip them but they have the early stats to be useful when other leveling weaker classes and gain extra gold per battle to help support more expensive classes.
- Jesters are pretty much a joke class but they have outrageously high luck so you can use them to fish for rare drops to find top-notch gear for other classes or extra gold to buy gear.
The player character has the Hero class which makes them well-rounded with good weapon and armor options with both attack and healing magic to fill in gaps in the team they pick. The player can choose all Soldiers and have a wall of tanks, but the cost to properly equip them all would be insane. The player can choose to go Fighter, Fighter, Mage with the Hero for healing and have almost no upkeep costs, but the party will risk going down quick if anything survives the fight 1-2 rounds. Low cost early options like Fighters and Merchants help offset the costs of expensive Soldiers and Priests, but it's fully possible to go with all-magic or no-magic party comps if the player chooses.