UML component diagrams
The system as a set of replaceable parts and the contracts between them. What each piece offers, what it needs, and - the useful bit - what you would have to honour to swap one out.
13 min readUML 2.5.117 of 35
The short answer
- A component is a replaceable unit with a defined contract - something you could put out to tender - not simply a large class.
- Every component carries two lists: what it provides and what it requires. The required half is the one people leave off, and it is the half that carries the dependencies.
- A ball on a stick is a provided interface, a half-cup is a required one, and a ball resting in a socket is the two wired together.
- A component is logical and a node is physical. The moment a box acquires a hostname or an instance count you are drawing a deployment diagram.
01What it shows#
A component diagram describes a system as replaceable parts. A component in UML is not just any class - it is a unit with a defined boundary that could, in principle, be swapped for a different implementation of the same contracts without anything around it noticing.
That definition is the whole value. The diagram forces you to write down, for every part, exactly two things: what it provides and what it requires. Those two lists are the part's contract with the rest of the system, and they are the thing you actually need when planning a migration, scoping a rewrite, or deciding whether a service boundary is in the right place.
02The notation#
| Element | Notation | What it means |
|---|---|---|
| Component | rectangle with the plug icon | A replaceable unit. The icon in the corner is the UML 2 form; the older form put the icon in place of the box. |
| Provided interface | The component implements this contract. Drawn as a realization to an «interface», or as a ball on a stick. | |
| Required interface | The component needs somebody to provide this. Drawn as a dependency, or as a socket - a half-cup on a stick. | |
| Assembly connector | a ball sitting in a socket | One component's provided interface wired to another's required one. The compact form of the two rows above. |
| Port | small square on the boundary | A named interaction point. Use when one component has several distinct channels - a public API and an admin API, say. |
| Delegation connector | From a port on the outside to a part on the inside: this external contract is actually handled by that internal piece. |
The ball and socket form is the compact one and what most tools draw by default: a lollipop sticking out of a component is an interface it provides, a half-cup is one it requires, and a ball resting in a socket is the two wired together. It is the same information as the arrows above, in less space. Use whichever your readers find easier; be consistent within a diagram.
Every mark this diagram kind can carry - both interface notations, assembly and delegation connectors, ports, and the four stereotypes worth writing - is set out in component diagram symbols.
03How big is a component?#
This is the question every first component diagram gets stuck on, and the spec is no help: UML says a component is a replaceable unit with a defined contract and leaves the size entirely to you. That is the right answer for a standard and a useless one at a whiteboard, so here is the working rule.
A component is whatever you could put out to tender.If you can imagine handing another team the provided and required interface lists and saying "build this, we will not look inside", it is a component. If handing that over would require a conversation about the internals, the boundary is drawn in the wrong place - and that is the finding, not a drawing problem to be worked around.
In practice that usually lands on one of these, and which one it lands on tells you what the diagram is for.
- A deployable service. One repository, one pipeline, one on-call rota. The most common answer in anything built in the last decade, and the level at which the diagram is worth keeping in the repository.
- A library or module. Inside one deployable, when the argument is about internal structure - which package may depend on which. Here a package diagram often says the same thing more cheaply.
- A whole system. The mainframe, the CRM, the payment provider. The level for a context diagram, where the point is what you depend on rather than how any of it is built.
Mixing two of those levels on one diagram is the mistake that produces the sprawling component diagrams people remember. A picture with three microservices, a utility library and "SAP" on it is three diagrams overlaid, and no reader can tell which boxes are peers.
04Reading one properly#
The single most useful reading technique is to cover a component with your hand. What is left is its contract: the interfaces that were attached to it. If you can hand that list to another team and say "build something that satisfies this", the diagram is doing its job. If you cannot - if replacing the component would require knowing things not drawn - the boundary is in the wrong place, and that is worth knowing before somebody tries.
The second technique is to follow the required interfaces. Every one is a dependency somebody has to satisfy, and a cycle in that graph is a genuine architectural problem that a component diagram makes visible immediately.
Both techniques are easier to see applied than described. Five diagrams of systems you have probably worked on - a shared catalogue, ports and adapters, a legacy swap, a plugin host and a cycle - are worked through in component diagram examples, each with the argument it settles.
05Which box am I drawing?#
Five diagram kinds are rectangles connected by lines, and the difference between them is entirely what a rectangle is. Picking the wrong one is the most expensive mistake available here, because the diagram will look fine and answer a question nobody asked.
| Element | Notation | What it means |
|---|---|---|
| Component | a replaceable unit | Boxes are things that could be swapped for another implementation of the same contract. Lines are provided and required interfaces. Answers: what does each part promise, and what does it need? |
| Class | a type | Boxes are types in the code. Lines are associations, generalizations and dependencies between them. Answers: what is the shape of the code? See the class diagram. |
| Package | a namespace | Boxes are groupings - folders, namespaces, modules. Lines are permitted dependencies. Answers: what is allowed to import what? |
| Deployment | a node | Boxes are machines, containers and runtimes. Lines are communication paths. Answers: where does this actually run and over what? See the deployment diagram. |
| Composite structure | a part inside a whole | Boxes are the parts one classifier is made of, drawn inside it. Answers: what is this thing built from internally? |
The same rectangle in five notations. Read the middle column before you draw: it is the sentence the whole diagram is an answer to.
The question that comes up most is component versus deployment, and the split is clean once stated: a component is a logical unit and a node is a physical one. One component can run on forty nodes; one node can host a dozen components. The moment a box on your component diagram acquires a region, an instance count or a hostname, it has stopped being a component and the diagram has quietly become two.
If you have met C4, its containerdiagram sits almost exactly where a component diagram at the deployable-service level does, and its own "component" level is a step further in than UML usually means. The vocabularies do not line up, so say which one you are using on the diagram itself - that one line of legend prevents most of the arguments.
06When to draw one#
Reach for it when
- Defining service boundaries before splitting or merging systems
- Documenting what a team owns and what it depends on from others
- Planning a replacement - the contract is exactly what the new thing must satisfy
- Reviewing whether dependencies flow the way the architecture claims they do
Reach for something else when
- You mean physical machines and processes - use a deployment diagram
- You mean the internals of one component - use a composite structure diagram
- The parts are classes, not replaceable units - use a class diagram
- There are three services and everyone already knows how they connect
Component diagrams age well, which is unusual. Interfaces change far more slowly than the code behind them, so a component diagram checked into a repository stays true for much longer than a class diagram of the same system - and is correspondingly more worth maintaining.
07Common mistakes#
- Components that are really classes. If it cannot plausibly be replaced independently, it is not a component. Use a class diagram.
- Only provided interfaces drawn. The required ones carry the dependency information, which is the more useful half.
- Arrows between components with no interface.A bare arrow says "depends somehow", which is the thing this diagram exists to make precise.
- Mixing in deployment. Servers, regions and containers belong on a deployment diagram.
- Interfaces named after the provider.
ILedgeris fine when there is one ledger; when there might be two implementations, name the contract after the capability, not the current supplier.
In one line each
- 01A component is a replaceable unit with a defined contract, not just a big class.
- 02Every component has two lists: what it provides and what it requires.
- 03Realization (hollow triangle, dashed) points at the interface being implemented.
- 04Dependency (open arrow, dashed) points at the interface being required.
- 05Ball-and-socket is the compact form of the same information.
- 06Cover a component with your hand: what remains is what a replacement must satisfy.
08Common questions#
What is ball-and-socket notation?
The shorthand for interfaces. A provided interface is a lollipop, a small circle on a stick. A required interface is a socket, a half circle. Fitting the ball into the socket shows one component satisfying another's dependency without drawing the interface out as a class.
What is the difference between a component diagram and a class diagram?
A class diagram shows types and their internal structure. A component diagram shows deployable, replaceable units and the contracts between them, and deliberately hides what is inside each one. The question it answers is what you would have to honour to swap a part out.
What is a port in UML?
A small square on the boundary of a component, representing one distinct point of interaction. Ports let a component expose several separate interfaces, an admin API and a public API for instance, rather than a single undifferentiated surface.
When should I draw a component diagram?
When the system has parts that could plausibly be replaced or bought instead of built, and the interesting question is the interface between them. If nothing in the system is replaceable, the diagram only restates the package structure.
In this series
- 01What is UML?
- 02UML symbols
- 03Choosing a diagram
- 04Class diagrams
- 05Class diagram examples
- 06How to draw a class diagram
- 07Class diagram symbols
- 08Sequence diagrams
- 09Sequence diagram examples
- 10How to draw a sequence diagram
- 11Use case diagrams
- 12Use case examples
- 13Activity diagrams
- 14Activity examples
- 15State machine diagrams
- 16State machine examples
- 17Component diagrams
- 18Component examples
- 19Drawing a component diagram
- 20Component symbols
- 21Deployment diagrams
- 22Deployment examples
- 23Object diagrams
- 24Package diagrams
- 25Composite structure diagrams
- 26Communication diagrams
- 27Sequence vs communication
- 28Timing diagrams
- 29Interaction overview diagrams
- 30Profile diagrams
- 31UML with AI
- 32E-commerce example
- 33Banking example
- 34Microservices example
- 35AWS example
Related reading
Structure diagrams
Modelling practice
Notation reference
Structure diagrams
Structure diagrams
Structure diagrams