The Chinese Communist Party was founded at a secret conference in Shanghai's French Concession in 1921. It was an offshoot of the both the May 4th movement and the news of the Russian Revolution.
In its early years, the party largely followed the directions received from Moscow calling for it to focus on national unification rather than the establishment of Communism. This was a natural extension of the nationalism the party had grown out of and still strongly supported. This was also a worthwhile policy for the Communists, who came to dominate the left wing of the Guomindang and became close allies of Sun Yatsen. This role also easily sprung out of the classic Communist theory that Communism would be achieved thanks to the workers starting a revolution against their employers. This idea became an integrated part of the Guomindang strategy for the unification of China by having the Communists enter the cities to rouse the workers for the impending liberation.
This strategy came to an end with Chiang Kaishek's purge of the Communists from the Guomindang. Following this, activity in the cities became virtually impossible and any Communism in the major cities of China was brutally suppressed. However, orders from Mosco still called for these, weakening ties between the Chinese Communists and the Soviet Union. Instead the party followed the leadership of the peasant son Mao Zedong in seeking refuge in remote, mountainous regions. These weren't secure either and the Communists were repeatedly driven from their bases by the Guomindang and allied warlords. The final of these was in 1934 which nearly broke the party and forced it to one of the most remote regions of China. Despite persistent attacks by Chiang Kaishek, it built a local state in these areas where it could experiment with rural Communism.
The 1937 Japanese invasion brought an end to the fights with the Guomindang and an alliance between the two parties. This alliance didn't survive for the entire war, but the two parties were geographically distant and were forced to focus on more important issues than fighting each other. This opportunity and the legitimacy gained from opposing the Japanese were used by the Communists to gain control over a large territory in northern China and gain considerable support from China's rural population. This allowed the Communists to defeat the Guomindang in the civil war following immediately after the second world war and proclaim the sovereignty People's Republic of China, still under the leadership of Mao Zedong, over all of mainland China.