After the coup attempt in Turkey, we have been red hunderds of news or analyses about it: who organized the plot, are the plotters one sect or have some distinctions between, did US support them, which parts or Turkish Military jioned the plot, how about other parts of it etc. And even 15 days after, some questions have no answer for the ruling AKP too.
This point is the major reason of the aggressive purges and arrests. For a superficial observation, you may think that Erdoğan is stronger than before the coup attempt because he has atrated to get ride of all opponents of him. But this is not the real scene of Turkey and Erdoğan right now. Because he could never know that who is reliable or not. Moreover, Erdoğan now know that both Turkish bourgeoise and most of imperialistic partners wait for success of the coup attempt first hours. So hard times began for Erdoğan after the "victory" of Erdoğan. In the other words, failed attempt was successful for the future as a means of control Erdoğan.
To answer the question on the top efficiently lets go a little back on political history of AKP and Erdoğan first. After the division of the Welfare Party, Recep Tayyip Erdoğan and Abdullah Gül led a new party that named Justice and Development Party, AKP. The new Party was describe itself as a "conservative democrat" party. As we red from AKP documents, conservative democracy was a kind of liberalism who survives as a muslim concept of liberalism. AKP made certain the western imperialism that she will never try to conflict with their will. Moreover, as a muslim partner, AKP could do what imperialism want for middle east and nobody could think that its a new crusade.
Like the western imperialism, Turkish big bourgeoise saw the pottential of the AKP for their interests on the region. Not only the muslim bourgeoise named the Anatolian Tigers supported the AKP, but especially biggest capitalist holdings like Sabancı, Koç, Doğan etc. Because, in the AKP era, capitalist class gained huge benefits against working class with the laws of AKP governments.
This two, western imperialism and Turkish big bourgeoise, was the main parts of the coalition which gived AKP to the its power. But there were one important component of the coalition: Turkish reactionism. After the 1980 coup, popularising of the political islam was a state policy. This process helped the mass sentiment for AKP. If you want to discuss about Erdoğan's strenght, you have to see its first sources clearly like this: western imperialism, Turkish bourgeoise and reactionism.
Erdoğan was successful first years of his reign. Despite membership process of the EU, Arab Spring gived a big opportunity for him too. But with Syrian War, things have been strated the change for him as i wrote before: "So, the victory of AKP will mean that the victory of US and its
imperialist allies. An the defeat of AKP will mean the stumble of US
plans on Middle East."
Now we know that new ottomanist foreign policy of Erdoğan and Davutoğlu defeated in Syria and it caused the defeat of imperialistic plans too. It was the first warning for the coalition partners of AKP. With the June uprising of 2013 in Turkey, AKP has been lost public support too. Then, the coalition which took the AKP as ruling party of Turkey, crashed quickly.
After this point, a political/ideological crisis wrapped around the Turkey and the crisis could not solved yet. Indeed, motivation of the plotters came from there too. Turkey is not such a country and "must" be governance for capitalist class' and western imperialisms will.
For my opinion, weakness of Erdoğan is derives from governance crisis and there is no any safe process to make Turkey stabile for future. Erdoğan has no enough staff to govern Turkey and has no enough ally to find convenient staff. The crowds on streets not able to maintain any political process but fanatic islamist mostly. Here is the catalysor of the nightmares of Erdoğan...