Complete Diagram Guide
by Peta Team
Complete Diagram Guide
Class Diagrams
Class diagrams visualize the structure and relationships between components in a system. They're perfect for showing architecture, dependencies, and data models.
Basic Syntax
The fundamental syntax for class diagrams shows relationships between entities:
This creates a composition relationship between two entities.
Relationship Syntax
Relationship Types
Peta supports two main relationship types:
- Composition (`|+|`): Strong ownership, lifecycle dependency
- Aggregation (`|o|`): Weak ownership, shared reference
Composition
Use `|+|` for strong ownership relationships:
This means an Order owns OrderItems, and OrderItems cannot exist without the Order.
Aggregation
Use `|o|` for weak ownership relationships:
This means a User has an Address, but the Address can exist independently.
Creating Relationships
Single Relationship
Connect two entities:
Multiple Relationships
An entity can have multiple relationships:
Complex Architectures
System Architecture
Show complete system structure:
Data Model
Represent database schema:
Practical Examples
Blog System
E-commerce Platform
Social Media
Content Management System
Tips and Best Practices
- Clear entity names: Use descriptive, concise names
- Appropriate relationships: Choose composition vs aggregation carefully
- Logical grouping: Group related entities together
- Consistent direction: Generally show dependencies from dependent to provider
- Avoid clutter: Don't overcomplicate the diagram
Relationship Guidelines
When to Use Composition
Use `|+|` when:
- The child cannot exist without the parent
- The child's lifecycle is managed by the parent
- Deleting the parent should delete the child
Examples:
- Order and OrderItems
- Document and Pages
- User and UserProfile
When to Use Aggregation
Use `|o|` when:
- The child can exist independently
- The child is shared among multiple parents
- Deleting the parent should not delete the child
Examples:
- User and Address
- Course and Student
- Department and Employee
Common Patterns
Repository Pattern
Service Layer
Module System
Next Steps
Now that you understand class diagrams, let's explore state diagrams for visualizing state machines in the next chapter.