Polagram Documentation
Introduction
Polagram is a sequence diagram transformation engine designed for complex systems. It helps you maintain a single source of truth while generating clarity for every context.
The Problem: One Size Doesn't Fit All
Sequence diagrams are a powerful tool for visualizing systems, but a single diagram rarely satisfies everyone's needs. The "optimal" level of detail depends entirely on your role:
- For Developers: Details like error handling, retry logic, and authentication flows are critical for implementation.
- For Product Managers: These technical details are noise. They need to see the high-level user journey and happy paths to understand the feature.
- For QA Engineers: They might need to focus exclusively on specific failure scenarios or edge cases.
Traditionally, this forces a choice: maintain one giant, unreadable diagram, or manually keep multiple diagrams in sync—a recipe for documentation drift. Polagram solves this by dynamically generating all these views from a single source of truth.
One Diagram. Every View.
Polagram treats diagrams like code. Instead of maintaining multiple fragmented diagrams manually, you maintain one master diagram and use Lenses to generate specific views.
Source
Lenses
Optimized Views
The Power of Lenses
Don't just take our word for it. Lenses allow you to transform a complex master diagram into specific views for every stakeholder.
Try applying different lenses to the complex diagram below. Notice how the internal logic changes based on the audience.
Live Demo: Context Switching
See how the same diagram looks to different team members.
Why Polagram?
Installation
Install the Polagram CLI globally or as a development dependency in your project.
npm install -g @polagram/cli # or pnpm add -g @polagram/cli
Quick Start
Create a polagram.yml configuration file to define your diagram targets and transformations.
version: 1
targets:
- input: ["diagram.mmd"]
outputDir: "generated"
lenses:
- name: clean-view
layers:
# A comprehensive lens example
# 1. Hide the Logger participant (Remove)
- action: remove
selector:
kind: participant
name: Logger
# 2. Focus only on critical path participants (Focus)
- action: focus
selector:
kind: participant
name: API
# 3. Simplify success scenarios (Resolve)
- action: resolve
selector:
kind: fragment
condition:
pattern: "Success:.*"Then run the CLI to generate your diagrams:
polagram generate
CLI Options
Customize the execution with the following options:
-c, --config <path>Specify the path to the configuration file. Defaults to polagram.yml in the current directory.
POLAGRAM_CONFIGEnv VarAlternative way to specify the config file path via environment variable.
CI/CD Integration
Polagram is built for automation. Generate up-to-date diagrams on every commit using GitHub Actions or your preferred CI provider.
name: Generate Diagrams
on: [push]
jobs:
diagrams:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- name: Install Polagram
run: pnpm add -g @polagram/cli
- name: Generate Diagrams
run: polagram generate
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: diagrams
path: generated/Specification
Detailed reference for the polagram.yml configuration file. The file format is YAML.
Root Object
versionnumberRequiredtargetsTarget[]RequiredTarget
inputstring[]RequiredoutputDirstringRequiredignorestring[]lensesLens[]RequiredLens
namestringRequiredlayersLayer[]RequiredLayer
action'focus' | 'remove' | 'resolve'RequiredThe operation to perform on the selected elements. Each action only supports specific selector kinds.
Keeps only interactions involving the selected participants.
participantRemoves the selected elements (participants, messages, or groups).
participantmessagegroupUnwraps specific branches of fragments (alt, opt, loop).
fragmentselectorSelectorRequiredSelector
Specifies the criteria for selecting elements. All string matching is exact by default. Use an object with pattern for Regex.
Common Fields
kind'participant' | 'message' | 'fragment' | 'group'RequiredKind-Specific Fields
name(Matcher): Filter by participant name.id(Matcher): Filter by participant ID (alias).stereotype(Matcher): Filter by stereotype (e.g.<<Service>>).
text(Matcher): Filter by message content.from(Matcher): Filter by Sender ID.to(Matcher): Filter by Receiver ID.
condition(Matcher): Filter by branch condition text (e.g. "Success").operator(string | string[]): Filter by loop/alt type.
Type Definitions
Coming Soon
PlantUML Support
We are currently developing support for PlantUML diagrams. Soon you will be able to apply the same powerful transformations to your existing PlantUML files (.puml).