The fact that he was able to find a handful of highly competent senior leaders among what he hadn't purged such as Konstantin Rokossovsky, Georgy Zhukov and Ivan Konev also made a huge difference.
“Stalin didn’t help his situation much by purging his most competent military commanders to replace them with boot licking ideologues in the years leading up to the war.”
One of the books I read talked of a train full of Soviet officers headed to the gulag and certain death.
Stalin turned it around and had it head back right after the invasion started...
Stalin also wisely took a hand-off approach to military planning. He set the overall strategy, but let his generals work out the details. Contrast that with Hitler, who interfered with his generals at all levels.
There’s a lesson in all that. FDR took the hands-off approach, and was quite successful in WW II. LBJ tried to micro-manage his war, and was much less successful.
Stalin still treated Zhukov like crap, given everything he did.