Component Diagram: UML Notation, Examples, How to Draw

Raghav Chamadiya10 min read
Compared in this post: repowise and
  • PlantUML
  • Mermaid
On this page

A component diagram is a UML diagram that shows a software system as a set of components, the interfaces each one provides and requires, and the dependencies between them. It answers one question: which parts make up this system, and what does each part need from the others?

What is a component diagram?

A component is a modular part of a system that hides its internals behind interfaces and can, in principle, be swapped for another part that offers the same interfaces. A service, a library, a package or a plugin can all be a component. The diagram draws each one as a box and draws only the contracts between them.

That restraint is the point. A class diagram tells you how one part is built. A component diagram tells you how the parts fit together, which is the question a new engineer, a reviewer or an architect asks first. The UML specification from the Object Management Group defines the notation; most teams use a lighter version of it.

UML component diagram notation

Six symbols cover almost every diagram you will draw.

SymbolMeaningHow it looks
ComponentA replaceable part of the systemRectangle with the <<component>> label, or a small two-tab icon in the corner
Provided interfaceA service the component offersLollipop: a circle on a line attached to the component
Required interfaceA service the component needsSocket: a half circle on a line attached to the component
Assembly connectorA provided interface plugged into a required oneBall and socket fitted together
PortA named point where a component meets its surroundingsSmall square on the component's border
DependencyOne component uses anotherDashed arrow pointing at the thing depended on

Scroll the table sideways to see every column.

Two details trip people up. First, the lollipop and socket must match: a socket with nothing plugged in is a missing dependency, and a lollipop nobody plugs into is an unused service. Second, a dependency arrow points from the user to the used, the same direction a compile error would travel if the used part vanished.

Component diagram example: an online store in PlantUML

Take a small online store. A web app takes orders, an order service owns them, a payment service charges cards, and an inventory service tracks stock. Each backend service offers one interface and the order service needs the other two.

@startuml
interface "Order API" as OrderAPI
interface "Payment API" as PayAPI
interface "Stock API" as StockAPI

package "Storefront" {
  [Web App]
}

package "Backend" {
  [Order Service]
  [Payment Service]
  [Inventory Service]
}

OrderAPI - [Order Service]
PayAPI - [Payment Service]
StockAPI - [Inventory Service]

[Web App] ..> OrderAPI : use
[Order Service] ..> PayAPI : use
[Order Service] ..> StockAPI : use
@enduml

Paste it into the PlantUML online server or render it locally with plantuml store.puml. The syntax follows the PlantUML component diagram reference: [Name] declares a component, interface declares an interface, A - B draws the lollipop link, and ..> draws a dependency labelled use.

Read it from the outside in. The web app only knows about the Order API. It cannot reach the payment service directly, which is exactly the constraint the diagram exists to show. If someone adds an arrow from the web app to the Payment API in code review, the diagram makes the violation obvious.

PlantUML also draws ports, which matter when a component has several distinct entry points:

@startuml
[Browser]
[Message Bus]
component C {
  portin http
  portout events
  component logic
}
[Browser] --> http
http --> logic
logic --> events
events --> [Message Bus]
@enduml

portin and portout mark inputs and outputs on the border of the component, as documented on the same PlantUML page.

The same diagram in Mermaid

Mermaid has no dedicated UML component diagram type. The practical substitute is a flowchart with subgraphs, which renders natively in GitHub, GitLab and most Markdown viewers. See the Mermaid flowchart syntax.

You lose the lollipop and socket glyphs and label the edge with the interface name instead. For a README that engineers read inline, that trade is usually worth it: the diagram lives next to the code and shows up in the pull request diff. For a formal design review, PlantUML's real UML shapes read better.

UML component diagram example: a mobile app with a backend

A second example shows how the diagram records a design decision. A mobile app has a UI, a local cache, a sync client and a push handler. The backend offers a REST API and a push gateway.

@startuml
interface "REST API" as REST
interface "Push Gateway" as PUSH
interface "Local Store" as STORE

package "Mobile App" {
  [UI]
  [Sync Client]
  [Cache]
  [Push Handler]
}

package "Backend" {
  [API Server]
  [Notification Service]
}

STORE - [Cache]
REST - [API Server]
PUSH - [Notification Service]

[UI] ..> STORE : use
[Sync Client] ..> STORE : use
[Sync Client] ..> REST : use
[Push Handler] ..> PUSH : use
@enduml

The UI talks to the cache and never to the network. Only the sync client touches the REST API. That separation is a choice, and the diagram records it where a reviewer can check it.

Component diagram vs class, deployment and C4 diagrams

These diagrams get confused because they all draw boxes and arrows. They differ in what a box means.

DiagramA box isShowsUse it to
UML componentA replaceable part with interfacesProvided and required interfaces, dependenciesExplain how parts fit and what they depend on
UML classOne classFields, methods, inheritance, associationsDesign or document how a single part is built
UML deploymentA node (machine, container, runtime) holding artifactsWhere software runs and how nodes connectPlan hosting, networks and environments
C4 componentA group of code inside one containerResponsibilities and relationships, in plain labelsOrient developers on one deployable unit

Scroll the table sideways to see every column.

The component and class diagrams are two zoom levels of the same code. If a component box is a payments module, the class diagram is what you see when you open that box. The deployment diagram is orthogonal: it says where things run, not how they relate in code.

UML component diagram vs the C4 component level

The C4 model's third level is also called a component diagram, and the two share an idea but not a notation. A C4 component diagram zooms into one container and shows its major building blocks as labelled boxes with a one-line responsibility and a technology, joined by arrows labelled with a verb. There are no lollipops, sockets or stereotypes. For all four levels, read the C4 model explained, and the C4 glossary entry for the definition.

My view: if your audience is engineers who need orientation, the C4 style is easier to draw and easier to read. If you need to specify interfaces precisely, between teams or for a vendor, UML's provided and required interfaces carry meaning the C4 arrow does not. Pick one per diagram and name it in the title.

Does anyone still use UML?

Yes, in pieces. Almost nobody draws all fourteen UML diagram types. Sequence, class and component diagrams survive because each answers a question that prose answers badly. Tools that generate code from UML diagrams mostly did not survive.

My opinion: use UML as a drawing vocabulary, not as a methodology. Learn the six component symbols above, use them when interfaces matter, and drop them when a plain box-and-arrow diagram says the same thing.

How to draw a component diagram

  1. List the parts. Name the modules, services or packages a new engineer needs to know. Aim for 5 to 12 boxes; more and the diagram stops being readable.
  2. Name each interface. Write down what each part offers to others. If you cannot name it, the boundary is probably in the wrong place.
  3. Draw the dependencies. For each part, which interfaces does it call? Draw one arrow per interface, from user to provider.
  4. Group and label. Put related components in packages, such as a frontend and a backend. Label arrows with use or the protocol where it matters.
  5. Check against the code. Open the imports of two or three components and confirm each arrow exists. Then look for imports the diagram does not show.

Step five is where most diagrams fail. The drawing is written from memory, and memory describes the design that was intended, not the system that shipped.

Why hand-drawn component diagrams rot

A component diagram is a claim about the code, and the code changes every week. Someone adds a direct database call from the web layer, a service gains a dependency, a module is split, and nobody redraws the diagram because nobody is assigned to. After a quarter it describes a system that no longer exists, and people stop trusting it. The wider problem is covered in technical documentation examples and documentation as code.

The fix is to generate the structure from the repository. Which part imports which part is a fact in the source, so a tool can read it and draw it. What a tool cannot know is intent: why a dependency exists and what a component is for. So generate the boxes and arrows, and keep labels and grouping in a small file you edit by hand. Generate C4 diagrams from code walks through that split, and generating an architecture diagram from a GitHub repo shows it on a real project.

Generating component diagrams with repowise

repowise builds a dependency graph of your codebase during repowise init, with no model calls and no network, and its generated wiki draws architecture diagrams from that structure. The repository overview carries a system map: a tiered diagram of who uses the system, the ways in, the server, the engine and the data store. Structure picks the boxes and arrows, and a configured model only names them. The architecture views show the result.

The components that matter to your organisation are the ones you name. Declare them in .repowise/components.yaml, or let repowise read the catalog-info.yaml your developer portal already uses:

yaml
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
  name: payments
  annotations:
    repowise.dev/paths: "services/payments/**"
    repowise.dev/criticality: critical
spec:
  type: service
  owner: group:default/payments-team
  lifecycle: production

With no file, components are derived from workspace services, module pages or top-level directories, so every repository has them from the first index. Health, hotspots, bus factor, test reach, dead code and changes all roll up to components, so a finding reads as "the payments component" instead of a list of files. repowise components list prints them, and repowise components ownership compares declared owners with the last 90 days of commits.

A diagram regenerated from code and tied to the components your team already talks about is one people keep using. For the health side, see the code quality guides.

FAQ

What is the component diagram?
A component diagram is a UML diagram that shows a system as a set of components and the interfaces they provide and require. It describes structure at the level of replaceable parts, not classes or machines. Teams use it to explain how a system fits together and to check dependencies between parts.
What is the difference between a component diagram and a class diagram?
A class diagram shows the inside of one part: classes, fields, methods and inheritance. A component diagram shows the outside of many parts: the interfaces they offer and the dependencies between them. A component box usually contains several classes.
What is the difference between a UML component diagram and a C4 component diagram?
Both show the building blocks inside a system. The UML version uses formal symbols such as lollipop and socket interfaces and ports. The C4 version scopes the diagram to one container and uses plain labelled boxes and arrows with a short responsibility and technology on each.
What are the four types of diagrams?
It depends on the framework. For UML, people often name class, component, sequence and deployment as four common ones. The C4 model has four levels instead: context, container, component and code.
Does anyone still use UML?
Yes, selectively. Sequence, class and component diagrams are still common in design documents and reviews. Model-driven code generation from UML is rare. Most teams treat UML as a shared drawing vocabulary and use the diagrams that answer a real question.
How do you keep a component diagram up to date?
Generate the structure from the code on each change and keep hand-written labels and grouping in a separate file. A diagram edited by hand drifts within weeks. A diagram regenerated from imports stays true, and you annotate only what a person knows.