Part-writing (or voice leading) is the composition of parts in consideration of harmony and counterpoint. In the context of polyphonic composition the term voice may be used instead of part to denote a single melodic line or textural layer. The term is generic, and is not meant to imply that the line should necessarily be vocal in character, instead referring to instrumentation, the function of the line within the counterpoint structure, or simply to register.
The historical development of polyphony and part-writing is a central thread through European music history. The earliest notated pieces of music in Europe were gregorian chant melodies. It appears that the Codex Calixtinus (12th century) contains the earliest extant decipherable part music. Many histories of music trace the development of new rules for dissonances, and shifting stylistic possibilities for relationships between parts.
In some places and time periods, part-writing has been systematized as a set of counterpoint rules taught to musicians as part of their early education. One notable example is Johann Fux's Gradus ad Parnassum, which dictates a style of counterpoint writing that resembles the work of the famous Renaissance composer Palestrina. The standard for most Western music theory in the twentieth century is generalized from the work of Classical composers in the common practice period. For example, a recent general music textbook states,
Part writing is derived from four-voice chorales written by J.S. Bach. The late baroque era composer wrote a total of 371 harmonized chorales. Today most students' reference Albert Riemenschneider's 1941 compilation of Bach chorales.
Polyphony and part-writing are also present in many popular music and folk music traditions, although they may not be described as explicitly or systematically as they sometimes are in the Western tradition. 
In musical forms, a part may refer to a subdivision in the structure of a piece. Sometimes "part" is a title given by the composer or publisher to the main sections of a large-scale work, especially oratorios. For example, Handel's Messiah, which is organized into Part I, Part II, and Part II, each of which contains multiple scenes and one or two dozen individual arias or choruses.
Other times, "part" is used to refer in a more general sense to any identifiable section of the piece. This is for example the case in the widely used ternary form, usually schematized as A-B-A. In this form the first and third parts (A) are musically identical, or very nearly so, while the second part (B) in some way provides a contrast with them. In this meaning of part, similar terms used are section, strain, or turn.
One frequently distinguishes the outer (highest and lowest) parts (Ger. Aussensatz) from the inner (middle) part or parts.
In early polyphony parts were named not according to vocal range or timbre, but on the basis of their function in the contrapuntal design [...] With the introduction of such names as 'contratenor bassus', part names began to take on registral connotations.
The primary division of certain large-scale works (especially oratorios), equivalent to the act in theatrical works.
In certain large-scale genres, e.g. oratorios, 'Part' is used to designate the main division of the work.