Class Diagram
Design strongly-typed domain models with classes, interfaces, records, enums, generics, visibility modifiers, and UML relationships.
| 1 | dialect uml; |
| 2 | |
| 3 | uml::class_diagram "E-Commerce Domain-Driven Design Model" { |
| 4 | schema { |
| 5 | frame subsystem @sharedKernel [label: "Shared Kernel"] { |
| 6 | class abstract @BaseEntity [label: "Base Entity"] { |
| 7 | pub id: String; |
| 8 | protected createdAt: Timestamp; |
| 9 | protected updatedAt: Timestamp; |
| 10 | pub getId(): String; |
| 11 | } |
| 12 | |
| 13 | class record @Address [label: "Address Value Object"] { |
| 14 | pub street: String; |
| 15 | pub city: String; |
| 16 | pub postalCode: String; |
| 17 | pub country: String; |
| 18 | pub format(): String; |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | frame subsystem @orderContext [label: "Order Bounded Context"] { |
| 23 | enum @OrderStatus [label: "Order Status"] { |
| 24 | DRAFT; |
| 25 | CONFIRMED; |
| 26 | PAID; |
| 27 | SHIPPED; |
| 28 | DELIVERED; |
| 29 | CANCELLED; |
| 30 | } |
| 31 | |
| 32 | #[invariant(totalAmount >= 0.0)] |
| 33 | class @Order [label: "Order Aggregate Root"] { |
| 34 | pub orderNumber: String; |
| 35 | pub totalAmount: Float; |
| 36 | pub placedAt: Timestamp; |
| 37 | pub calculateTotal(): Float; |
| 38 | pub confirm(): bool; |
| 39 | pub cancel(): bool; |
| 40 | } |
| 41 | |
| 42 | class @OrderItem [label: "Order Line Item"] { |
| 43 | pub sku: String; |
| 44 | pub unitPrice: Float; |
| 45 | pub quantity: Int; |
| 46 | pub getSubtotal(): Float; |
| 47 | } |
| 48 | |
| 49 | interface @IOrderRepository [label: "Order Repository Contract"] { |
| 50 | pub findById(id: String): Option<Order>; |
| 51 | pub save(order: Order): bool; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | frame subsystem @catalogContext [label: "Catalog Bounded Context"] { |
| 56 | class @Product [label: "Catalog Product"] { |
| 57 | pub sku: String; |
| 58 | pub title: String; |
| 59 | pub price: Float; |
| 60 | pub isAvailable(): bool; |
| 61 | } |
| 62 | |
| 63 | class @Category [label: "Product Category"] { |
| 64 | pub name: String; |
| 65 | pub slug: String; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | frame subsystem @paymentContext [label: "Payment Bounded Context"] { |
| 70 | enum @PaymentStatus [label: "Payment Status"] { |
| 71 | PENDING; |
| 72 | AUTHORIZED; |
| 73 | CAPTURED; |
| 74 | REFUNDED; |
| 75 | FAILED; |
| 76 | } |
| 77 | |
| 78 | class @PaymentTransaction [label: "Payment Transaction"] { |
| 79 | pub transactionId: String; |
| 80 | pub amount: Float; |
| 81 | pub process(): bool; |
| 82 | pub refund(): bool; |
| 83 | } |
| 84 | |
| 85 | interface @IPaymentGateway [label: "Payment Provider Contract"] { |
| 86 | pub charge(amount: Float): bool; |
| 87 | pub refund(transactionId: String): bool; |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | flow { |
| 93 | // Explanatory Notes |
| 94 | note @OrderAggNote [on: Order, pos: right] "Aggregate root enforcing line item invariants and total consistency"; |
| 95 | note @AddressRecordNote [on: Address, pos: left] "Immutable value object shared across billing and delivery destinations"; |
| 96 | |
| 97 | // Inheritance & Generalization |
| 98 | Order -> extends BaseEntity; |
| 99 | OrderItem -> extends BaseEntity; |
| 100 | Product -> extends BaseEntity; |
| 101 | Category -> extends BaseEntity; |
| 102 | PaymentTransaction -> extends BaseEntity; |
| 103 | |
| 104 | // Composition & Aggregation |
| 105 | Order[1] -> composes OrderItem[1..*] as items; |
| 106 | Product[0..*] -> aggregates Category[1..*] as categories; |
| 107 | |
| 108 | // Directed Associations |
| 109 | Order[1] -> associates Address[1] as shippingAddress; |
| 110 | Order[1] -> associates Address[1] as billingAddress; |
| 111 | Order[1] -> associates OrderStatus[1] as status; |
| 112 | Order[1] -> associates PaymentTransaction[0..1] as payment; |
| 113 | OrderItem[0..*] -> associates Product[1] as product; |
| 114 | PaymentTransaction[1] -> associates PaymentStatus[1] as status; |
| 115 | |
| 116 | // Dependencies |
| 117 | Order -> depends IOrderRepository; |
| 118 | PaymentTransaction -> depends IPaymentGateway; |
| 119 | } |
| 120 | |
| 121 | // Kinematic Spatial Layout Intent |
| 122 | layout { |
| 123 | // Primary narrative spine: Core ordering domain aggregate |
| 124 | reference order_spine: column [gap: 60, align: center] { |
| 125 | BaseEntity |
| 126 | Address |
| 127 | } |
| 128 | |
| 129 | // Secondary branch: Product catalog hierarchy |
| 130 | branch catalog_branch: column [gap: 50, align: center] { |
| 131 | Product |
| 132 | Category |
| 133 | } |
| 134 | |
| 135 | // Secondary branch: Payment processing subsystem |
| 136 | branch payment_branch: column [gap: 50, align: center] { |
| 137 | OrderItem |
| 138 | Order |
| 139 | OrderStatus |
| 140 | IOrderRepository |
| 141 | } |
| 142 | |
| 143 | // Secondary branch: Order lifecycle support and value objects |
| 144 | branch order_support_branch: column [gap: 80, align: center] { |
| 145 | PaymentStatus |
| 146 | PaymentTransaction |
| 147 | IPaymentGateway |
| 148 | } |
| 149 | |
| 150 | joint order_to_catalog: column [gap: 120, align: middle] { |
| 151 | Address |
| 152 | Product |
| 153 | } |
| 154 | |
| 155 | joint order_to_payment: row [gap: 240, align: middle] { |
| 156 | BaseEntity |
| 157 | OrderItem |
| 158 | PaymentStatus |
| 159 | } |
| 160 | |
| 161 | // Note pin-state offsets |
| 162 | note @OrderAggNote { |
| 163 | offset_x: 60 |
| 164 | offset_y: 20 |
| 165 | } |
| 166 | |
| 167 | note @AddressRecordNote { |
| 168 | offset_x: -60 |
| 169 | offset_y: -10 |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | |
| 175 | |
Errors: 0 | class-diagram
Core Syntax Reference
| Construct | Purpose |
|---|---|
class @Name { +field: Type; +method(): Ret; } | Declare classes with typed fields and operations |
interface / abstract / record / enum | Full UML classifier vocabulary |
A --|> B / A *-- B / A ..> B | Inheritance, composition, aggregation, and dependency |
#[invariant(...)] | Attach domain constraints to classifiers |