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:

Basic Class Diagram Entity A Attributes Methods Entity B Attributes Methods

This creates a composition relationship between two entities.

Relationship Syntax

Relationship Types

Peta supports two main relationship types:

  1. Composition (`|+|`): Strong ownership, lifecycle dependency
  2. Aggregation (`|o|`): Weak ownership, shared reference

Composition

Use `|+|` for strong ownership relationships:

Order Attributes Methods OrderItem Attributes Methods

This means an Order owns OrderItems, and OrderItems cannot exist without the Order.

Aggregation

Use `|o|` for weak ownership relationships:

User Attributes Methods Address Attributes Methods

This means a User has an Address, but the Address can exist independently.

Creating Relationships

Single Relationship

Connect two entities:

User Attributes Methods Profile Attributes Methods

Multiple Relationships

An entity can have multiple relationships:

User Attributes Methods Post Attributes Methods Comment Attributes Methods Settings Attributes Methods

Complex Architectures

System Architecture

Show complete system structure:

System Architecture Application Attributes Methods Controller Attributes Methods Service Attributes Methods Repository Attributes Methods Database Attributes Methods Cache Attributes Methods Validator Attributes Methods

Data Model

Represent database schema:

Data Model User Attributes Methods Profile Attributes Methods Order Attributes Methods OrderItem Attributes Methods Payment Attributes Methods Product Attributes Methods Category Attributes Methods

Practical Examples

Blog System

Blog System Architecture User Attributes Methods Post Attributes Methods Comment Attributes Methods Category Attributes Methods Tag Attributes Methods Subscription Attributes Methods

E-commerce Platform

E-commerce Platform Customer Attributes Methods Order Attributes Methods Address Attributes Methods Wishlist Attributes Methods OrderItem Attributes Methods Payment Attributes Methods Product Attributes Methods Review Attributes Methods Category Attributes Methods Inventory Attributes Methods

Social Media

Social Media Platform User Attributes Methods Post Attributes Methods Comment Attributes Methods Like Attributes Methods Follow Attributes Methods Media Attributes Methods Group Attributes Methods

Content Management System

CMS Architecture Site Attributes Methods Page Attributes Methods User Attributes Methods Post Attributes Methods Template Attributes Methods Content Attributes Methods Media Attributes Methods Storage Attributes Methods Role Attributes Methods Permission Attributes Methods

Tips and Best Practices

  1. Clear entity names: Use descriptive, concise names
  2. Appropriate relationships: Choose composition vs aggregation carefully
  3. Logical grouping: Group related entities together
  4. Consistent direction: Generally show dependencies from dependent to provider
  5. 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

Repository Pattern Service Attributes Methods Repository Attributes Methods Database Attributes Methods Cache Attributes Methods Controller Attributes Methods

Service Layer

Service Layer Architecture Controller Attributes Methods Service Attributes Methods Repository Attributes Methods Database Attributes Methods External API Attributes Methods Validator Attributes Methods

Module System

Module System Core Attributes Methods Auth Module Attributes Methods User Module Attributes Methods Content Module Attributes Methods

Next Steps

Now that you understand class diagrams, let's explore state diagrams for visualizing state machines in the next chapter.