Topology and weights are closely related in weighted complex networks and this is reflected in their modular structure. We present a simple network model where the weights are generated dynamically and they shape the developing topology. By tuning a model parameter governing the importance of weights, the resulting networks undergo a gradual structural transition from a module free topology to one with communities. The model also reproduces many features of large social networks, including the "weak links" property.PACS numbers: 89.75. Hc, 87.16.Ac,89.75.Fb, Network theory has undergone a remarkable development over the last decade and has contributed significantly to our understanding of complex systems, ranging from genetic transcriptions to the Internet and human societies [1,2]. Many complex networks are structured in terms of modules, or communities, which are groups of nodes characterized by having more internal than external connections between them. Such a mesoscopic network structure is expected to play a concrete functional role. Consequently, it is an important problem to understand how the communities emerge during the growth of the network. Apart from these issues of topological nature, it is important to realize that many complex networks are weighted, i.e., the interaction between two nodes is characterized not only by the existence of a link but a link with a varying weight assigned to it. There are a number of examples, like traffic, metabolic or correlation based networks, which provide ample evidence that the weights have to be included in their analysis. In many cases the weights affect significantly the properties or function of these networks, e.g., disease spreading [3], synchronisation dynamics of oscillators [4], and motif statistics [5]. It is natural to expect that weights have an influence on the formation of communities, which is the very issue of our study.Earlier, coupled weight-topology dynamics have been used successfully in transport networks modeling [6], which, however, does not lead to community structure. We show that there are mechanisms, by which weights play a crucial role in community formation. While we believe this to be quite a general paradigm for community formation, we have chosen to explore it within the realm of social systems where large datasets have enabled looking into both the coupling of network topology and interaction strengths and properties of communities [7,8,9]. Understanding how the underlying microscopic mechanisms translate into mesoscopic communities and macroscopic social systems is a key problem in its own right and one that is accessible within the scope of sta- tistical physics.Large scale social networks are known to satisfy the weak links hypothesis [10] with the implication that weak links keep the network connected whereas strong links are mostly associated with communities [24]. This weighttopology coupling results from the microscopic mechanisms that govern the evolution of social networks. Network sociology identifies (a) cyclic closure...