
Sf Diagram
- 40 installs
- 12 repo stars
- Updated July 14, 2026
- clientell-ai/salesforce-skills
Generate consistent Salesforce architecture and data-model diagrams in Mermaid or ASCII from reusable ERD and pattern templates.
About
Sf-diagram is an agent skill from the Salesforce skills pack that gives solo builders and small consultancies a diagram reference library: standard Sales Cloud ER diagrams in Mermaid, junction-object patterns, and syntax guidance for ASCII equivalents. Use it when you must explain who relates to what—accounts to opportunities, line items to price books, or custom master-detail links—before configuring flows, integrations, or security reviews. The skill accelerates documentation and alignment meetings rather than deploying metadata. It assumes you are already in a Salesforce-centric build (CRM extensions, revops tooling, or customer-facing SaaS with Salesforce as system of record). Output is diagram source code you paste into repos, Notion, or ADRs. Intermediate familiarity with Salesforce object names helps; beginners can still copy templates and learn relationship cardinality from the examples.
- Reusable Mermaid ERD templates for standard Sales Cloud objects (Account, Contact, Opportunity, Case, Lead, products)
- Custom object patterns such as master-detail junction models (e.g., Project__c / Project_Member__c)
- ASCII and Mermaid syntax reference for Salesforce architecture diagrams
- Copy-paste entity relationship blocks with typed fields (Id PK, FK, picklist, currency)
- Designed as a diagram reference companion to broader Salesforce build skills
Sf Diagram by the numbers
- 40 all-time installs (skills.sh)
- Ranked #870 of 1,879 Documentation skills by installs in the Skillselion catalog
- Security screen: LOW risk (skills.sh audit)
- Data as of Jul 28, 2026 (Skillselion catalog sync)
npx skills add https://github.com/clientell-ai/salesforce-skills --skill sf-diagramAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 40 |
|---|---|
| repo stars | ★ 12 |
| Security audit | 3 / 3 scanners passed |
| Last updated | July 14, 2026 |
| Repository | clientell-ai/salesforce-skills ↗ |
What it does
Generate consistent Salesforce architecture and data-model diagrams in Mermaid or ASCII from reusable ERD and pattern templates.
Files
Salesforce Diagram Generator
You are a Salesforce architecture diagramming specialist. Generate accurate Mermaid diagrams by reading real org metadata, Apex source, and Flow definitions. Every diagram must be grounded in actual project files when available.
1. Entity Relationship Diagrams (ERDs)
Generate Mermaid erDiagram from Salesforce custom objects and their relationships.
How to Build an ERD
1. Find object metadata — Use Glob to locate .object-meta.xml files:
Glob: force-app/**/objects/**/*.object-meta.xml2. Find field metadata — Locate .field-meta.xml for each object:
Glob: force-app/**/objects/*/fields/*.field-meta.xml3. Identify relationships — Read each field file and look for:
<type>Lookup</type>— optional relationship (zero-or-one to many)<type>MasterDetail</type>— required relationship (one to many, cascade delete)<referenceTo>ObjectName</referenceTo>— the related object
4. Render as erDiagram (see diagram-reference.md for full templates):
erDiagram
Account ||--o{ Contact : "has"
Account ||--o{ Opportunity : "has"
Opportunity ||--|{ OpportunityLineItem : "contains"
Contact ||--o{ Case : "raised by"
Account ||--o{ Case : "related to"
Account {
Id Id PK
string Name
string Industry
}
Contact {
Id Id PK
Id AccountId FK
string LastName
string Email
}Relationship Notation
| Salesforce Relationship | Mermaid Notation | Meaning |
|---|---|---|
| Master-Detail | `\ | \ |
| Lookup (required) | `\ | \ |
| Lookup (optional) | `}o--\ | \ |
| Many-to-Many (junction) | Two `\ | \ |
| Self-relationship | Entity to itself | e.g., Account hierarchy |
ERD Filtering Rules
- Include: Custom objects (
__c), standard objects referenced by custom fields - Exclude by default: System audit fields, metadata objects, setup objects
- Field display: Show only key fields (Id, Name, foreign keys, and up to 5 domain fields) unless the user asks for full detail
- Size limit: Cap at ~30 objects per diagram — split large models into functional domains
2. Class Diagrams
Generate Mermaid classDiagram from Apex source files.
How to Build a Class Diagram
1. Find Apex classes:
Glob: force-app/**/classes/*.cls2. Parse each class — Use Read/Grep to identify:
- Class declaration:
public class,public abstract class,public virtual class - Interfaces:
implements SomeInterface - Inheritance:
extends ParentClass - Key methods:
public,@AuraEnabled,@InvocableMethod,@HttpGet - Dependencies: other classes referenced in the body
3. Render as classDiagram (see diagram-reference.md for full templates):
classDiagram
class TriggerHandler {
<<abstract>>
+run() void
+beforeInsert() void
+afterUpdate() void
}
class AccountTriggerHandler {
+beforeInsert() void
-validateAccounts(List~Account~) void
}
class AccountService {
+getAccountsByIds(Set~Id~) List~Account~
}
TriggerHandler <|-- AccountTriggerHandler : extends
AccountTriggerHandler --> AccountService : usesClass Stereotypes
| Apex Pattern | Mermaid Stereotype |
|---|---|
| Interface | <<interface>> |
| Abstract class | <<abstract>> |
| Batch class | <<batch>> |
| Queueable | <<queueable>> |
| Schedulable | <<schedulable>> |
| REST resource | <<restresource>> |
| Test class | <<test>> |
| Trigger handler | <<handler>> |
Visibility Markers
+public-private#protected~internal (default/package)
3. Sequence Diagrams
Generate Mermaid sequenceDiagram for integration flows, trigger execution, and async processing.
REST Callout Sequence
sequenceDiagram
autonumber
participant LWC as Lightning Component
participant Ctrl as ApexController
participant Svc as IntegrationService
participant Ext as External API
LWC->>Ctrl: callImperativeMethod()
Ctrl->>Svc: syncRecords(recordIds)
Svc->>Ext: POST /api/v2/records
Ext-->>Svc: 200 OK {response}
Svc-->>Ctrl: IntegrationResult
Ctrl-->>LWC: Return resultPlatform Event Pub/Sub
sequenceDiagram
autonumber
participant Pub as Order Service
participant Bus as Event Bus
participant Sub1 as Trigger Subscriber
participant Sub2 as Flow Subscriber
Pub->>Bus: EventBus.publish(Order_Event__e)
Note over Bus: Committed after transaction
Bus-->>Sub1: Trigger receives event
Bus-->>Sub2: Flow receives event
Sub1->>Sub1: Process in new transaction
Note right of Sub1: Separate governor limitsSee diagram-reference.md for trigger execution order, async job flow, and error handling sequence templates.
Building from Code
1. Identify the flow — Ask the user or infer from the entry point (trigger, LWC, REST endpoint) 2. Trace the call chain — Read each class involved, follow method calls 3. Map participants — Each class or external system becomes a participant 4. Capture request/response — Solid arrows for calls, dashed arrows for returns 5. Add notes — Mark async boundaries, governor limit resets, transaction boundaries
4. Flow Diagrams
Convert Salesforce Flow XML (.flow-meta.xml) to Mermaid flowcharts.
How to Convert Flows
1. Find Flow files:
Glob: force-app/**/flows/*.flow-meta.xml2. Parse Flow XML elements — Map each element type to a Mermaid node shape:
| Flow Element | XML Tag | Mermaid Shape |
|---|---|---|
| Screen | <screens> | [/ Screen Name /] (parallelogram) |
| Decision | <decisions> | { Decision Label } (diamond) |
| Assignment | <assignments> | [ Assignment Label ] (rectangle) |
| Record Lookup | <recordLookups> | [( SOQL Query )] (stadium) |
| Record Create | <recordCreates> | [[ Insert Record ]] (subroutine) |
| Record Update | <recordUpdates> | [[ Update Record ]] (subroutine) |
| Record Delete | <recordDeletes> | [[ Delete Record ]] (subroutine) |
| Subflow | <subflows> | [[ Subflow Name ]] (subroutine) |
| Action | <actionCalls> | ( Action Label ) (rounded) |
| Loop | <loops> | { Loop Variable } (diamond) |
| Start | <start> | ([ Start ]) (stadium) |
3. Trace connectors — Follow <connector><targetReference> to build edges:
<defaultConnector>for the default path<faultConnector>for error paths (render as red/dashed)- Decision outcomes create labeled branches
4. Render as flowchart:
flowchart TD
Start([Start: Record-Triggered]) --> GetAcct[(Lookup Account)]
GetAcct --> CheckStatus{Status = Active?}
CheckStatus -->|Yes| UpdateAcct[[Update Account Rating]]
CheckStatus -->|No| SendEmail(Send Notification Email)
UpdateAcct --> End([End])
SendEmail --> EndFlow Diagram Rules
- Always show Start and End nodes
- Label decision branches with the outcome name
- Show fault connectors as dashed lines when present
- Group loops visually — show the loop node and its body
- For large Flows (20+ elements), show a summary view first, then offer detail
5. Deployment Dependency Diagrams
Show metadata deployment order as a directed acyclic graph.
How to Build Dependency Graphs
1. Scan the project: Glob: force-app/main/default/**/*-meta.xml 2. Map dependencies: Objects first, then Fields, Classes, Triggers, LWC, Flows, Permission Sets, Profiles 3. Render as flowchart (see diagram-reference.md for full template):
flowchart LR
subgraph "Phase 1: Schema"
Obj[Custom Objects] --> Fields[Custom Fields]
end
subgraph "Phase 2: Code"
Cls[Apex Classes] --> Trg[Apex Triggers]
end
subgraph "Phase 3: UI + Config"
LWC[LWC] --> Pages[FlexiPages]
Flows[Flows]
Perms[Permission Sets]
end
Obj --> Cls
Fields --> Cls
Cls --> LWC
Obj --> Flows
Obj --> Perms6. Data Model Overview
Generate a comprehensive data model diagram from the full objects directory.
Approach
1. Scan all objects: Glob: force-app/**/objects/*/ 2. Categorize into domains — Sales (Account, Contact, Opportunity, Lead), Service (Case, Entitlement), Custom (__c grouped by prefix) 3. Generate domain-scoped ERDs, plus a high-level cross-domain view 4. Use field metadata for cardinality
Rules
- Group into subgraphs by functional domain
- Standard objects use plain names; custom objects show API name
- Limit each subgraph to ~10-15 objects
- Show only cross-domain relationships between subgraphs
- See diagram-reference.md for full data model templates
7. Mermaid Syntax Quick Reference
Diagram Types for Salesforce
| Salesforce Use Case | Mermaid Type | Declaration |
|---|---|---|
| Object relationships | erDiagram | erDiagram |
| Apex class structure | classDiagram | classDiagram |
| Integration flows | sequenceDiagram | sequenceDiagram |
| Flow visualization | flowchart | flowchart TD or flowchart LR |
| Deployment order | flowchart | flowchart LR |
| Timeline / releases | gantt | gantt |
| State machine | stateDiagram-v2 | stateDiagram-v2 |
Directions
TD (top-down, flows), LR (left-right, ERDs/deps), RL, BT
Node Shapes
[Rectangle] process, (Rounded) action, {Diamond} decision, [(Cylinder)] database, ([Stadium]) start/end, [[Subroutine]] DML/subflow, [/Parallelogram/] screen, ((Circle)) connector
Link Types
--> solid, -.-> dashed (async/fault), ==> thick (critical), -->|label| labeled
See diagram-reference.md for full syntax cheat sheet with Salesforce-specific patterns.
8. Output Formats
- Mermaid (default): Wrap in fenced code blocks with
mermaidlanguage identifier - ASCII fallback: Use when user says "ASCII" or "terminal" — see diagram-reference.md for templates
- Provide both when user says "both" or context is unclear
- Always add a
Notessection after the diagram explaining key relationships and assumptions
9. Gotchas
Mermaid Limitations
- Node limit: Mermaid renderers struggle beyond ~100 nodes — filter or split diagrams
- Long labels: Node text over ~40 characters can break layout — abbreviate
- Special characters: Parentheses, quotes, and colons in labels must be wrapped in quotes
- Generics syntax: Use
~instead of<>for generics in class diagrams (e.g.,List~Account~) - GitHub: Renders Mermaid natively in
.mdfiles — test diagrams there - VS Code: Use the "Markdown Preview Mermaid Support" extension
- Confluence / Jira: Require Mermaid plugins — check availability before delivering
Salesforce-Specific Pitfalls
- Polymorphic lookups (WhoId, WhatId): Cannot be represented as a single relationship — show as note or multiple optional links
- Record Types: Not relationships — show as attributes or stereotypes, not as separate entities
- Managed package objects: May have namespace prefixes (
ns__Object__c) — include the prefix - Person Accounts: Merge Account and Contact — note this in the diagram if enabled
- External Objects (
__x): Connect via external lookup — show with a different style - Big Objects (
__b): Async insert only — annotate if included - Junction objects: Render as entities with two master-detail relationships, not as a direct many-to-many line
When to Split Diagrams
- More than 30 objects in an ERD
- More than 15 classes in a class diagram
- More than 20 steps in a sequence diagram
- More than 25 nodes in a flowchart
- Split by domain, module, or functional area
10. Workflow
Generating an ERD
1. Use Glob to find all .object-meta.xml and .field-meta.xml files 2. Read relationship fields to identify Lookup and MasterDetail connections 3. Build the entity list with key fields 4. Render as erDiagram with proper cardinality notation 5. Add notes for polymorphic lookups or special patterns
Generating a Class Diagram
1. Use Glob to find all .cls files in the project 2. Read each class to identify: declaration, extends, implements, key methods 3. Group classes by pattern (service, selector, handler, controller) 4. Render as classDiagram with stereotypes and relationships 5. Show inheritance (<|--), composition (*--), and usage (-->)
Generating a Sequence Diagram
1. Identify the flow entry point (user action, trigger, schedule, API call) 2. Trace the execution path through each class/method 3. Identify external system callouts and async boundaries 4. Render as sequenceDiagram with autonumber 5. Mark transaction boundaries and governor limit reset points
Generating a Flow Diagram
1. Use Glob to find .flow-meta.xml files 2. Read the Flow XML — identify all elements and connectors 3. Map each element type to its Mermaid node shape 4. Follow <connector> and <defaultConnector> to build edges 5. Render as flowchart TD with labeled decision branches
Generating a Deployment Dependency Diagram
1. Scan the project for all metadata types 2. Identify cross-type dependencies (fields reference objects, classes reference objects, etc.) 3. Order into deployment layers 4. Render as flowchart LR with subgraphs per layer
General Checklist
- [ ] Diagram is grounded in actual metadata (not fabricated)
- [ ] Labels are accurate API names or clear display names
- [ ] Cardinality is correct for all relationships
- [ ] Diagram renders cleanly in Mermaid (test node count)
- [ ] Notes section explains assumptions and simplifications
- [ ] ASCII fallback provided if requested
References
- Diagram Reference — templates, examples, syntax cheat sheet, and ASCII fallback patterns
Diagram Reference: Templates, Examples & Syntax
Reusable templates and patterns for generating Salesforce architecture diagrams in Mermaid and ASCII.
---
ERD Templates
Standard Sales Cloud Data Model
erDiagram
Account ||--o{ Contact : "has"
Account ||--o{ Opportunity : "has"
Account ||--o{ Case : "has"
Contact ||--o{ Case : "opened by"
Opportunity ||--|{ OpportunityLineItem : "contains"
Opportunity ||--o{ OpportunityContactRole : "involves"
Contact ||--o{ OpportunityContactRole : "plays role"
Opportunity }o--|| Pricebook2 : "uses"
Product2 ||--|{ PricebookEntry : "listed in"
OpportunityLineItem }o--|| PricebookEntry : "references"
Lead ||--o| Account : "converts to"
Lead ||--o| Contact : "converts to"
Account {
Id Id PK
string Name
string Industry
}
Contact {
Id Id PK
Id AccountId FK
string LastName
string Email
}
Opportunity {
Id Id PK
Id AccountId FK
string StageName
currency Amount
}
Case {
Id Id PK
Id AccountId FK
Id ContactId FK
string Status
}Custom Object Junction Pattern
erDiagram
Project__c ||--|{ Project_Member__c : "has members"
Contact ||--|{ Project_Member__c : "assigned to"
Project_Member__c {
Id Project__c FK "Master-Detail"
Id Contact__c FK "Master-Detail"
picklist Role__c
}---
Class Diagram Templates
Trigger Handler Pattern
classDiagram
class TriggerHandler {
<<abstract>>
+run() void
+beforeInsert() void
+afterUpdate() void
}
class AccountTriggerHandler {
+beforeInsert() void
-validateIndustry(List~Account~) void
}
TriggerHandler <|-- AccountTriggerHandler : extends
AccountTriggerHandler --> AccountService : delegates toService-Selector-Domain Pattern
classDiagram
class AccountService {
+getAccountsByIds(Set~Id~) List~Account~
+mergeAccounts(Id, List~Id~) MergeResult
}
class AccountSelector {
+selectById(Set~Id~) List~Account~
+selectWithContacts(Set~Id~) List~Account~
}
class Accounts {
<<domain>>
-records List~Account~
+validateIndustry() void
+setDefaultRating() void
}
AccountService --> AccountSelector : queries via
AccountService --> Accounts : operates on---
Sequence Diagram Templates
REST Callout with Error Handling
sequenceDiagram
autonumber
participant Ctrl as ApexController
participant Svc as IntegrationService
participant Ext as External REST API
Ctrl->>Svc: callExternalAPI(recordIds)
Svc->>Ext: POST /api/v2/accounts
alt Success (200)
Ext-->>Svc: 200 OK {data}
Svc-->>Ctrl: IntegrationResult(success)
else Error (4xx/5xx)
Ext-->>Svc: Error {message}
Svc->>Svc: Log to Integration_Log__c
Svc-->>Ctrl: IntegrationResult(failure)
endPlatform Event Pub/Sub
sequenceDiagram
autonumber
participant Apex as Publisher
participant Bus as Event Bus
participant Sub1 as Trigger
participant Sub2 as Flow
Apex->>Bus: EventBus.publish(events)
Note over Bus: 72h retention
par Subscribers
Bus-->>Sub1: Deliver (new transaction)
Bus-->>Sub2: Deliver
end
Note over Sub1: Retry via EventBus.RetryableException---
Flow-to-Mermaid Conversion Rules
XML Element Mapping
| Flow XML Tag | Mermaid Shape | Syntax |
|---|---|---|
<start> | Start node | ([Start]) |
<screens> | Screen | [/Screen Name/] |
<decisions> | Decision | {Decision?} |
<assignments> | Assignment | [Set Variables] |
<recordLookups> | Query | [(Get Records)] |
<recordCreates> | DML | [[Create Record]] |
<recordUpdates> | DML | [[Update Record]] |
<recordDeletes> | DML | [[Delete Record]] |
<loops> | Loop | {For Each Item} |
<actionCalls> | Action | (Invoke Action) |
<subflows> | Subflow | [[Run Subflow]] |
<waits> | Wait | {{Wait for Event}} |
Connector Mapping
| Flow Connector | Mermaid Syntax |
|---|---|
<connector> | A --> B |
<defaultConnector> | `A -->\ |
<faultConnector> | `A -.->\ |
<nextValueConnector> | `A -->\ |
<noMoreValuesConnector> | `A -->\ |
Conversion Example
flowchart TD
Start([Start]) --> Get_Account[(Get Account)]
Get_Account --> Check_Status{Status = Active?}
Check_Status -->|Is Active| Update_Rating[[Update Rating]]
Check_Status -->|Default| Send_Alert(Send Alert Email)
Update_Rating --> End([End])
Send_Alert --> End---
Deployment Dependency Graph Template
flowchart LR
subgraph Schema
CO[Objects] --> CF[Fields]
end
subgraph Code
Cls[Apex Classes] --> Trg[Triggers]
end
subgraph UI
LWC --> FP[FlexiPages]
end
subgraph Config
Fl[Flows]
PS[Permission Sets]
end
CO --> Cls
Cls --> LWC
CO --> Fl
CO --> PS---
Mermaid Syntax Cheat Sheet
erDiagram Relationships
A ||--|| B One to one (exact)
A ||--o{ B One to many (Lookup)
A ||--|{ B One to many (Master-Detail)
A }o--o{ B Many to many (via junction)
A }o--|| B Many to one (optional)classDiagram Relationships
A <|-- B Inheritance (extends)
A <|.. B Implementation (implements)
A *-- B Composition (strong ownership)
A o-- B Aggregation (weak ownership)
A --> B Association (uses)
A ..> B Dependency (depends on)Styling Nodes
classDef standard fill:#1b96ff,stroke:#0176d3,color:#fff
classDef custom fill:#06a59a,stroke:#04877a,color:#fff
classDef external fill:#ff6b6b,stroke:#d63d3d,color:#fffTransaction Boundary — use rect blocks in sequence diagrams:
rect rgb(240, 248, 255)
Note over A,C: Transaction 1
end
rect rgb(255, 240, 240)
Note over D,E: Async context
end---
ASCII Fallback Templates
ERD (ASCII)
+-------------+ 1:N +-------------+ N:1 +------------------+
| Account |------>| Contact |------>| Opportunity |
+-------------+ +-------------+ +------------------+
| Id (PK) | | AccountId | | AccountId (FK) |
| Name | | LastName | | StageName |
| Industry | | Email | | Amount |
+-------------+ +-------------+ +------------------+Sequence (ASCII)
LWC Controller Service External API
| | | |
|--callApex---->| | |
| |--process---->| |
| | |--HTTP POST--->|
| | |<--200 OK------|
| |<--result-----| |
|<--response----| | |Class Hierarchy (ASCII)
TriggerHandler (abstract)
+-- AccountTriggerHandler --> AccountService --> AccountSelector
+-- OpportunityTriggerHandler --> OpportunityService
+-- CaseTriggerHandler --> CaseService---
Tips
- Start simple, drill down on request
- Use real Salesforce API names, not display labels
- Annotate governor limits (SOQL/DML counts) and async boundaries
- Label relationships with verbs: "has", "belongs to", "references"
- Test rendering in GitHub markdown or Mermaid live editor
- Max 30 entities per ERD, 100 nodes per diagram; split by domain
- Colors: blue for standard, green for custom, red for external
Related skills
FAQ
Is Sf Diagram safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.