Sirendocs

Class Diagram

Complete syntax reference for Siren class diagrams.

Class diagrams show object-oriented structures — classes, their attributes and methods, and the relationships between them.

Minimal Example

{
  "type": "class",
  "classes": [
    { "id": "animal", "name": "Animal", "methods": ["speak()"] },
    { "id": "dog", "name": "Dog", "methods": ["speak()"] }
  ],
  "relationships": [
    { "from": "dog", "to": "animal", "type": "inheritance" }
  ]
}

Full Example

{
  "type": "class",
  "classes": [
    {
      "id": "user",
      "name": "User",
      "attributes": ["id: string", "email: string", "name: string"],
      "methods": ["updateProfile()", "changePassword()"]
    },
    {
      "id": "order",
      "name": "Order",
      "attributes": ["id: string", "total: number", "status: string"],
      "methods": ["cancel()", "refund()"]
    },
    {
      "id": "lineItem",
      "name": "LineItem",
      "attributes": ["productId: string", "quantity: number", "price: number"]
    },
    {
      "id": "payment",
      "name": "PaymentProcessor",
      "methods": ["charge(amount)", "refund(transactionId)"]
    }
  ],
  "relationships": [
    { "from": "user", "to": "order", "type": "association", "label": "places" },
    { "from": "order", "to": "lineItem", "type": "composition", "label": "contains" },
    { "from": "order", "to": "payment", "type": "dependency", "label": "uses" }
  ]
}

Classes

Each class needs a unique id and a name.

FieldRequiredDescription
idYesUnique identifier — relationships reference this
nameYesDisplay name shown in the class header
attributesNoArray of attribute strings (e.g., "name: string")
methodsNoArray of method strings (e.g., "save()")
{
  "id": "product",
  "name": "Product",
  "attributes": ["id: string", "price: number"],
  "methods": ["applyDiscount(percent)"]
}

Relationships

Each relationship connects two classes by their id.

FieldRequiredDescription
fromYesSource class id
toYesTarget class id
typeYesRelationship type (see below)
labelNoText on the connector

Relationship Types

TypeArrowUse for
"inheritance"Solid with hollow triangle"is a" (extends)
"realization"Dashed with hollow triangle"implements" (interface)
"composition"Solid with filled diamond"owns" (lifecycle-bound)
"aggregation"Solid with hollow diamond"has" (independent lifecycle)
"association"Solid lineGeneral "uses" or "knows about"
"dependency"Dashed lineWeak "depends on"

More Examples

Repository Pattern

{
  "type": "class",
  "classes": [
    {
      "id": "repo",
      "name": "UserRepository",
      "methods": ["findById(id)", "save(user)", "delete(id)"]
    },
    {
      "id": "iRepo",
      "name": "IRepository",
      "methods": ["findById(id)", "save(entity)", "delete(id)"]
    },
    {
      "id": "entity",
      "name": "User",
      "attributes": ["id: string", "email: string"]
    },
    {
      "id": "db",
      "name": "Database",
      "methods": ["query(sql)"]
    }
  ],
  "relationships": [
    { "from": "repo", "to": "iRepo", "type": "realization" },
    { "from": "repo", "to": "entity", "type": "association", "label": "manages" },
    { "from": "repo", "to": "db", "type": "dependency", "label": "queries" }
  ]
}

Observer Pattern

{
  "type": "class",
  "classes": [
    {
      "id": "subject",
      "name": "EventEmitter",
      "attributes": ["listeners: Map"],
      "methods": ["on(event, fn)", "emit(event, data)"]
    },
    {
      "id": "observer",
      "name": "Observer",
      "methods": ["update(data)"]
    },
    {
      "id": "logger",
      "name": "Logger",
      "methods": ["update(data)"]
    },
    {
      "id": "metrics",
      "name": "MetricsCollector",
      "methods": ["update(data)"]
    }
  ],
  "relationships": [
    { "from": "subject", "to": "observer", "type": "aggregation", "label": "notifies" },
    { "from": "logger", "to": "observer", "type": "realization" },
    { "from": "metrics", "to": "observer", "type": "realization" }
  ]
}

On this page