Composite Structure Diagram in UML

Introduction

Software systems are rarely just a flat set of objects. They’re made up of components that contain other components — all collaborating to deliver functionality. In UML, a Composite Structure Diagram helps us visualize the internal structure of a class or component by showing how its parts connect and interact.

This diagram is ideal for modeling complex systems where you want to go beyond the high-level class structure and examine the architecture within individual components. In this tutorial, we’ll explore Composite Structure Diagrams using a real-world example of a school system built in Java.

What is a Composite Structure Diagram?

A Composite Structure Diagram shows the internal configuration of a classifier (like a class or component) and the interactions between its parts through connectors and ports. Think of it as an exploded view of a system’s internals.

It’s like opening a machine to see its gears and how they’re connected — not just what the machine does, but how it does it internally.

Composite structure layout overview with parts and ports

Why Use Composite Structure Diagrams?

  • Model internal architectures: Show how parts of a class or component are wired
  • Design reusable components: Define clear internal structure and communication
  • Clarify complex interactions: Particularly helpful in embedded or service-based systems
  • Bridge between class and deployment diagrams: Offers medium-level detail

Key Elements of Composite Structure Diagrams

1. Classifier (Class/Component)

The main element whose internal structure is being modeled — like ResultService.

2. Part

An instance of a property of the classifier. For example, a ResultService might have parts like StudentRepository and MarkCalculator.

3. Port

A port is an interaction point where the classifier exposes services or communicates with other components.

4. Connector

A line between parts or ports showing how they interact internally. Can be typed (representing specific interfaces) or untyped.

Diagram with parts, ports, and connectors in a class structure

Example: School System - Result Generator

Scenario

Imagine you’re building a Java class called ResultService. It has two main responsibilities:

  • Fetching student records using a StudentRepository
  • Calculating marks via a MarkCalculator

Java Code Snapshot

public class ResultService {

  private StudentRepository studentRepo;
  private MarkCalculator calculator;

  public Result generateResult(int studentId) {
    Student student = studentRepo.findById(studentId);
    return calculator.calculate(student);
  }
}

This class is composed of two parts: studentRepo and calculator. Let’s visualize this in a Composite Structure Diagram.

Composite Structure Representation

  • Classifier: ResultService
  • Parts: studentRepo : StudentRepository, calculator : MarkCalculator
  • Port: resultPort for exposing result generation functionality
  • Connectors: Link ResultService to its internal parts
Composite diagram for ResultService class and its parts

Step-by-Step: How to Draw a Composite Structure Diagram

Step 1: Choose the Classifier

Decide what component or class you want to open up — this is your “main block.”

Step 2: Identify Internal Parts

Look at attributes and inner components that support the main logic.

Step 3: Define Ports

If your classifier exposes specific services or needs to receive input, define ports at the edges of the block.

Step 4: Add Connectors

Draw lines to show how parts are connected. Label if needed with interfaces or types.

Step 5: Organize Layout

Use nested rectangles or separate blocks. Keep the diagram clean and modular.

Another Example: Teacher Dashboard

Let’s say a TeacherDashboard component in a school system internally uses:

  • ScheduleManager: to manage class schedules
  • GradeUploader: to upload student marks

Composite Diagram View

We’ll show:

  • Ports for dashboard services
  • Parts for its internal collaborators
  • Connectors between the dashboard and its parts
Composite structure of TeacherDashboard component

Best Practices

  • Use for medium-level detail: Don’t try to show every class or every method
  • Be selective with ports: Only show those relevant for external/internal interactions
  • Name clearly: Use intuitive labels for parts and ports
  • Use notes where needed: Clarify complex connections or design decisions

Common Use Cases

  • Modeling software components: Like Java beans, microservices, or UI widgets
  • Embedded systems design: Showing internals of hardware modules or control loops
  • Collaborative systems: Describing how agents, services, or controllers interact

Tools to Draw Composite Structure Diagrams

  • StarUML: Full support for ports, parts, connectors
  • Visual Paradigm: Great for enterprise modeling
  • PlantUML: Partial support via component notation
  • Lucidchart: Ideal for easy-to-read modular diagrams

PlantUML Workaround Example

@startuml
component "ResultService" {
  [StudentRepository] --> [ResultService]
  [MarkCalculator] --> [ResultService]
}
@enduml
PlantUML composite-style component representation

Conclusion

Composite Structure Diagrams help bridge the gap between structural and behavioral views in software design. They are invaluable for modeling how components are built internally and how they collaborate through ports and connectors. Especially in modular Java applications or service-based designs, this diagram brings clarity to complex internals without overwhelming the viewer with low-level class detail.

Start with a familiar class — perhaps one you’ve written in Java — and draw its internal architecture. You’ll see your code from a new and insightful perspective.

Next up in this UML series, we’ll move into Use Case Diagrams — focusing on what your system offers to its users from the outside-in.

QUIZ

Question 1:What is the primary purpose of a Composite Structure Diagram in UML?

Question 2:In a Composite Structure Diagram, ports are used to represent interaction points with the environment or other parts.

Question 3:Which of the following are core elements in a Composite Structure Diagram?

Question 4:Which UML concept best describes a 'Part' in a Composite Structure Diagram?

Question 5:Connectors can only link external interfaces in a Composite Structure Diagram.

Question 6:Which of the following are valid use cases of Composite Structure Diagrams?

Question 7:In UML, what does a port typically indicate?

Question 8:A Composite Structure Diagram can contain nested parts within parts.

Question 9:In a Composite Structure Diagram, what do connectors typically represent?

Question 10:Consider this snippet for a school software system:
class School {
  Classroom class1;
  Classroom class2;
}
Which UML concept does this best relate to in a Composite Structure Diagram?