Create beautiful, interactive sequence diagrams with code
Feynman is a domain-specific language (DSL) for creating animated sequence diagrams. It allows you to describe complex system interactions in a simple, readable format.
Break down complex flows into individual steps that viewers can navigate through
Compose diagrams from reusable subsystems for better organization
Focus, dim, show, and hide participants to guide viewer attention
Show when participants are actively processing
Add explanatory text and documentation directly to your diagrams
Every Feynman diagram starts with an animateSequence declaration:
animateSequence "My Diagram Title"
participant Client
participant Server
step "Description of what happens"
Client -> Server: "Request message"
end
end
end keywords.
Participants are the actors in your sequence diagram. They can be services, users, databases, or any entity that sends or receives messages.
participant UserService
Reference a previously defined sequence as a subsystem using the * prefix:
participant *authService
animateSequence "API Gateway Flow"
participant Client
participant APIGateway
participant AuthService
participant Database
end
Steps are the building blocks of your animation. Each step has a description and contains one or more interactions.
step "Step description"
From -> To: "Message"
end
Interactions follow the pattern: FromParticipant Arrow ToParticipant: "Message"
step "User authentication flow"
Client -> APIGateway: "POST /login"
APIGateway -> AuthService: "Verify credentials"
AuthService -> Database: "SELECT user"
Database --> AuthService: "User data"
AuthService --> APIGateway: "JWT token"
APIGateway --> Client: "200 OK"
end
A participant can interact with itself, shown as a loop:
Validator -> Validator: "Parse JWT"
Different arrow types convey different meanings in your diagram:
->
Solid arrow for synchronous calls
-->
Dashed arrow for return/response messages
->>
Async arrow for asynchronous operations
-->>
Dashed async arrow for async responses
step "Mixed interaction types"
Client -> Server: "Synchronous request"
Server --> Client: "Synchronous response"
Server ->> MessageQueue: "Publish event (async)"
MessageQueue -->> Worker: "Event delivered (async)"
end
Directives control participant visibility and help guide viewer attention through your diagram.
| Directive | Effect | Use Case |
|---|---|---|
focus: |
Highlights specified participants | Draw attention to active components |
dim: |
Fades specified participants | De-emphasize inactive components |
show: |
Makes participants visible | Introduce new components |
hide: |
Makes participants invisible | Remove components from view |
activate: |
Shows activation box on lifeline | Indicate active processing |
deactivate: |
Removes activation box | End processing state |
Directives are placed at the beginning of a step and can target multiple participants:
step "Focus on authentication"
focus: Client, AuthService
dim: Database
Client -> AuthService: "Authenticate"
end
animateSequence "Progressive Reveal"
participant A
participant B
participant C
step "Introduce A"
show: A
dim: B, C
end
step "A calls B"
focus: A, B
dim: C
A -> B: "Request"
end
step "B calls C"
focus: B, C
dim: A
B -> C: "Forward"
end
end
Build complex diagrams by composing smaller sequences into larger ones. This promotes reusability and keeps diagrams organized.
Use &identifier to assign a reference name to a sequence:
animateSequence "Auth Service" &authService
participant TokenValidator
participant SessionStore
step "Validate token"
TokenValidator -> SessionStore: "Check session"
end
end
Reference the subsystem in another sequence using *identifier:
animateSequence "Main Flow"
participant Client
participant *authService
step "Client authenticates"
Client -> *authService: "Login request"
end
end
# Define subsystems first
animateSequence "Database Layer" &dbLayer
participant Cache
participant Database
step "Cache lookup"
Cache -> Database: "Query if miss"
end
end
animateSequence "Auth Layer" &authLayer
participant Validator
participant SessionStore
step "Validate"
Validator -> SessionStore: "Check session"
end
end
# Use subsystems in main flow
animateSequence "Application Flow"
participant Client
participant API
participant *authLayer
participant *dbLayer
step "Client request"
Client -> API: "Request"
end
step "Authenticate"
API -> *authLayer: "Verify"
end
step "Fetch data"
API -> *dbLayer: "Query"
end
end
Activation boxes appear on a participant's lifeline to show when they are actively processing.
step "Processing starts"
activate: Server
Client -> Server: "Request"
end
step "Processing continues"
Server -> Database: "Query"
end
step "Processing ends"
Server -> Client: "Response"
deactivate: Server
end
animateSequence "Request Processing"
participant Client
participant Server
participant Database
step "Request arrives"
activate: Server
Client -> Server: "GET /users"
end
step "Server queries database"
activate: Database
Server -> Database: "SELECT * FROM users"
end
step "Database returns"
Database --> Server: "User records"
deactivate: Database
end
step "Server responds"
Server --> Client: "200 OK"
deactivate: Server
end
end
Notes allow you to add explanatory text or annotations to your diagrams. They appear as colored boxes positioned relative to participants.
Notes can be positioned in three ways:
note over: Participant: "Note text" # Over a participant
note left: Participant: "Note text" # To the left
note right: Participant: "Note text" # To the right
For "over" positioning, you can span a note across multiple participants:
note over: Participant1, Participant2: "Spans both participants"
animateSequence "Authentication with Notes"
participant Client
participant Server
participant Database
step "Login attempt"
note over: Client: "User enters credentials"
Client -> Server: "POST /login"
end
step "Verify credentials"
activate: Server
note over: Server, Database: "Check against stored hash"
Server -> Database: "SELECT password_hash"
Database --> Server: "Hash returned"
end
step "Generate token"
Server -> Server: "Create JWT"
note over: Server: "Token valid for 24 hours"
Server --> Client: "200 OK + token"
deactivate: Server
end
end
animateSequence "Payment Processing"
participant Client
participant *paymentService
participant Bank
step "Process payment"
Client -> *paymentService: "Charge card"
note over: *paymentService: "Subsystem handles PCI compliance"
end
step "Bank authorization"
*paymentService -> Bank: "Authorize transaction"
note left: Bank: "External API call"
Bank --> *paymentService: "Approved"
end
end
animateSequence "Simple REST API"
participant Browser
participant API
participant Database
step "User requests data"
Browser -> API: "GET /api/users"
end
step "API queries database"
activate: API
API -> Database: "SELECT * FROM users"
Database --> API: "User records"
end
step "API returns response"
API --> Browser: "200 OK [users]"
deactivate: API
end
end
animateSequence "Auth with Cache"
participant Client
participant Server
participant Cache
participant Database
step "Login attempt"
Client -> Server: "POST /login"
activate: Server
end
step "Check cache for user"
Server -> Cache: "GET user:email"
Cache --> Server: "Cache miss"
end
step "Query database"
dim: Cache
focus: Server, Database
activate: Database
Server -> Database: "SELECT FROM users"
Database --> Server: "User data"
deactivate: Database
end
step "Update cache"
focus: Server, Cache
Server ->> Cache: "SET user:email (async)"
end
step "Return to client"
focus: Server, Client
Server --> Client: "200 OK + JWT"
deactivate: Server
end
end
# Payment processing subsystem
animateSequence "Payment Service" &paymentService
participant Gateway
participant Processor
participant Bank
step "Process payment"
activate: Processor
Gateway -> Processor: "Charge card"
Processor -> Bank: "Authorize"
Bank --> Processor: "Approved"
Processor --> Gateway: "Success"
deactivate: Processor
end
end
# Order management subsystem
animateSequence "Order Service" &orderService
participant OrderAPI
participant Inventory
participant Database
step "Create order"
activate: OrderAPI
OrderAPI -> Inventory: "Check stock"
Inventory --> OrderAPI: "Available"
OrderAPI -> Database: "INSERT order"
deactivate: OrderAPI
end
end
# Main e-commerce flow
animateSequence "Checkout Flow"
participant Customer
participant WebApp
participant *orderService
participant *paymentService
participant Email
step "Checkout initiated"
Customer -> WebApp: "Click checkout"
end
step "Create order"
activate: WebApp
WebApp -> *orderService: "Create order"
*orderService --> WebApp: "Order ID"
end
step "Process payment"
WebApp -> *paymentService: "Charge customer"
*paymentService --> WebApp: "Payment confirmed"
end
step "Send confirmation"
WebApp ->> Email: "Send receipt (async)"
WebApp --> Customer: "Order complete"
deactivate: WebApp
end
end
# for single-line comments to document your diagrams