This article may be too technical for most readers to understand. Please help improve it to make it understandable to non-experts, without removing the technical details. (June 2023) (Learn how and when to remove this template message)

This article provides insufficient context for those unfamiliar with the subject. Please help improve the article by providing more context for the reader, especially: For most readers, diagrams are graphical representations such as those presented in commutative diagram; the article must starts with this, and explain why the content of the article is a formalization of this representation. (June 2023) (Learn how and when to remove this template message)

In category theory, a branch of mathematics, a **diagram** is the categorical analogue of an indexed family in set theory. The primary difference is that in the categorical setting one has morphisms that also need indexing. An indexed family of sets is a collection of sets, indexed by a fixed set; equivalently, a *function* from a fixed index *set* to the class of *sets*. A diagram is a collection of objects and morphisms, indexed by a fixed category; equivalently, a *functor* from a fixed index *category* to some *category*.

The universal functor of a diagram is the diagonal functor; its right adjoint is the limit of the diagram and its left adjoint is the colimit.^{[1]} The natural transformation from the diagonal functor to some arbitrary diagram is called a cone.

Formally, a **diagram** of type *J* in a category *C* is a (covariant) functor

The category *J* is called the **index category** or the **scheme** of the diagram *D*; the functor is sometimes called a ** J-shaped diagram**.

Although, technically, there is no difference between an individual *diagram* and a *functor* or between a *scheme* and a *category*, the change in terminology reflects a change in perspective, just as in the set theoretic case: one fixes the index category, and allows the functor (and, secondarily, the target category) to vary.

One is most often interested in the case where the scheme *J* is a small or even finite category. A diagram is said to be **small** or **finite** whenever *J* is.

A morphism of diagrams of type *J* in a category *C* is a natural transformation between functors. One can then interpret the **category of diagrams** of type *J* in *C* as the functor category *C*^{J}, and a diagram is then an object in this category.

- Given any object
*A*in*C*, one has the**constant diagram**, which is the diagram that maps all objects in*J*to*A*, and all morphisms of*J*to the identity morphism on*A*. Notationally, one often uses an underbar to denote the constant diagram: thus, for any object in*C*, one has the constant diagram . - If
*J*is a (small) discrete category, then a diagram of type*J*is essentially just an indexed family of objects in*C*(indexed by*J*). When used in the construction of the limit, the result is the product; for the colimit, one gets the coproduct. So, for example, when*J*is the discrete category with two objects, the resulting limit is just the binary product. - If
*J*= −1 ← 0 → +1, then a diagram of type*J*(*A*←*B*→*C*) is a span, and its colimit is a pushout. If one were to "forget" that the diagram had object*B*and the two arrows*B*→*A*,*B*→*C*, the resulting diagram would simply be the discrete category with the two objects*A*and*C*, and the colimit would simply be the binary coproduct. Thus, this example shows an important way in which the idea of the diagram generalizes that of the index set in set theory: by including the morphisms*B*→*A*,*B*→*C*, one discovers additional structure in constructions built from the diagram, structure that would not be evident if one only had an index set with no relations between the objects in the index. - Dual to the above, if
*J*= −1 → 0 ← +1, then a diagram of type*J*(*A*→*B*←*C*) is a cospan, and its limit is a pullback. - The index is called "two parallel morphisms", or sometimes the free quiver or the walking quiver. A diagram of type is then a quiver; its limit is an equalizer, and its colimit is a coequalizer.
- If
*J*is a poset category, then a diagram of type*J*is a family of objects*D*_{i}together with a unique morphism*f*_{ij}:*D*_{i}→*D*_{j}whenever*i*≤*j*. If*J*is directed then a diagram of type*J*is called a direct system of objects and morphisms. If the diagram is contravariant then it is called an inverse system.

A cone with vertex *N* of a diagram *D* : *J* → *C* is a morphism from the constant diagram Δ(*N*) to *D*. The constant diagram is the diagram which sends every object of *J* to an object *N* of *C* and every morphism to the identity morphism on *N*.

The limit of a diagram *D* is a universal cone to *D*. That is, a cone through which all other cones uniquely factor. If the limit exists in a category *C* for all diagrams of type *J* one obtains a functor

lim : *C*^{J} → *C*

which sends each diagram to its limit.

Dually, the colimit of diagram *D* is a universal cone from *D*. If the colimit exists for all diagrams of type *J* one has a functor

colim : *C*^{J} → *C*

which sends each diagram to its colimit.

Main article: Commutative diagram |

Diagrams and functor categories are often visualized by commutative diagrams, particularly if the index category is a finite poset category with few elements: one draws a commutative diagram with a node for every object in the index category, and an arrow for a generating set of morphisms, omitting identity maps and morphisms that can be expressed as compositions. The commutativity corresponds to the uniqueness of a map between two objects in a poset category. Conversely, every commutative diagram represents a diagram (a functor from a poset index category) in this way.

Not every diagram commutes, as not every index category is a poset category: most simply, the diagram of a single object with an endomorphism (), or with two parallel arrows (; ) need not commute. Further, diagrams may be impossible to draw (because they are infinite) or simply messy (because there are too many objects or morphisms); however, schematic commutative diagrams (for subcategories of the index category, or with ellipses, such as for a directed system) are used to clarify such complex diagrams.