Component diagram

The component diagram provides a consistent transition from the logical to the physical representation of the system in the form of software components. The main elements of the diagram are components, interfaces and dependencies between them. 

A component diagram is developed for the following purposes

  • Visualization of the overall structure of the source code of the software system
  • Specifications of the executable version of the software system
  • Ensuring reuse of individual pieces of program code
  • Representation of conceptual and physical database schemas

1. Basic elements

A component is the physical part of a system. It implements a certain set of interfaces and serves to generalize the elements of the physical representation of the model. Components are class source files, libraries, executable modules, etc., which must have a consistent set of interfaces. The following symbols are used for their graphical representation:

The name of the component is written inside the rectangle, some additional information can also be placed here in the form of marked value.

An interface is an externally visible, named set of operations that a class, component, or subsystem can provide to another class, component, or subsystem to perform its functions. In the component diagram, the interface is graphically represented by a circle that connects to the component with a line segment without arrows. The interface name is written next to the circle. Semantically, a line means implementing an interface, and the presence of interfaces on a component means that this component implements an appropriate set of interfaces.

To the left of the component the required interfaces are displayed; on the right side, there are the provided interfaces.

If it is necessary to present the internal structure of the interface, it can be represented on the diagram as a class rectangle with the stereotype “interface” and possible sections of attributes and operations.

Dependencies describe the relationship when a change in one model element has an effect or leads to a change in another model element.
The component diagram is represented by a line with an arrow directed from the client (dependent element) to the source (independent element).

2. Syntax

Components

To declare components, you can use:

1. Square brackets [, ] inside which the designation of the component is written:

Код скопирован
  • @startuml
  • [First component]
  • @enduml

2. The keyword component to declare a component:

Код скопирован
  • @startuml
  • component Comp3
  • @enduml

3. You can declare an alias using the as keyword. This alias can be used later when declaring links.

Код скопирован
  • @startuml
  • [Another component] as Comp2
  • @enduml

If you need to place multi-line text in the component body, use square brackets: 

Код скопирован
  • @startuml 
  • component comp1 [ 
  • This component 
  • has a long comment 
  • on several lines 
  • ] 
  • @enduml 

After defining the component, you can set its color

Код скопирован
  • @startuml
  • component [Web Server] #Red
  • @enduml

Component Types 

Since the component as an element of the physical implementation of the model is a separate module of the code, it is sometimes commented on with additional graphic symbols that illustrate specific features of its implementation.

The use of such symbols simplifies the understanding of the diagram and improves its visibility. To use them, you should explicitly indicate the stereotype of the component before its name.

Components can have these standard stereotypes:

  • file – any file, except database table
  • executable – program (executable file)
  • library – static or dynamic library
  • source – program source file
  • document – other files (for instance, help file)
  • table – database table

Interfaces

To declare interfaces, you can use round brackets () or keyword interface. You can declare an alias using the as keyword. This alias can be used later when communications are specified.

The following interfaces will look like this:

Код скопирован
  • @startuml
  • () “First Interface”
  • () “Another interface” as Interf2
  • interface Interf3
  • interface “Last\ninterface” as Interf4
  • @enduml

Relations

Relations between elements are created using a combination of dotted lines .., straight lines -- and arrows -->

Код скопирован
  • @startuml
  • ()DataAccess [First Component]
  • [First Component] ..> HTTP : use
  • @enduml

By default, relationships between classes have two dashes -- and are oriented vertically. You can create horizontal connections using a single dash (or point), like this: 

Код скопирован
  • @startuml 
  • [Component] –> Interface1 
  • [Component] -> Interface2 
  • @enduml 

You can change directions by reversing the connection: 

Код скопирован
  • @startuml
  • Interface1 <– [Component]
  • Interface2 <- [Component]
  • @enduml

You can also change the direction of the arrow by adding the keywords left, right, up or down inside the arrow:

Код скопирован
  • @startuml 
  • [Component] –left-> left  
  • [Component] –right-> right  
  • [Component] –up-> up 
  • [Component] –down-> down 
  • @enduml 

Component grouping

If you need to group components and interfaces, you can use the keywords:

  • package
  • node
  • folder
  • frame
  • cloud
  • database
Код скопирован
  • @startuml
  • package “Some Group” {
  • HTTP – [First \nComponent]
  • [Another \nComponent]
  • }
  • node “Other Groups and Components” {
  • FTP – [Second \nComponent]
  • [First \nComponent] –> FTP
  • }
  • cloud {
  • [Example 1]
  • }
  • database “MySql” {
  • folder “This is my folder” {
  • [Folder 3]
  • }
  • frame “Foo” {
  • [Frame 4]
  • }
  • }
  • [Another \nComponent] –> [Example 1]
  • [Example 1] –> [Folder 3]
  • [Folder 3] –> [Frame 4]
  • @enduml

Using notes 

The keywords note left of, note right of, note top of, note bottom of can be used to specify labels that relate to a single object.

A note can also be set not attached using the note keyword, and then attached to other objects using the symbol … (relationships).

Код скопирован
  • @startuml
  • interface “Data Access” as DA
  • DA – [First Component]
  • [First Component] ..> HTTP : use
  • note left of HTTP : Web Service only
  • note right of [First Component]
  • A note can also
  • be on several lines
  • end note
  • @enduml