Skip to content

Diagram Overview

effect-analyzer produces Mermaid diagrams that visualize the structure of your Effect programs. When you run the analyzer without specifying a format, auto mode examines your program and selects the most informative views.

Flowchart diagram showing program control flow

Auto mode is the default behavior when you run:

Terminal window
npx effect-analyze ./src/program.ts

It always produces a baseline diagram - railway for simple programs, flowchart for complex ones - plus up to two specialized views based on what your program contains. The selection uses a combination of hard rules and soft heuristics.

Certain IR patterns always trigger a specific diagram type:

Pattern DetectedDiagram Selected
Effect.all with concurrency, Effect.raceConcurrency view
Conditional branches, Effect.ifDecision tree
Effect.loop, Effect.iterateStandard flowchart
Multiple services or layersService map

When hard rules do not apply, the analyzer scores your program on several dimensions:

  • Complexity - low cyclomatic complexity favors railway; high complexity favors flowchart
  • Error density - many error types or handlers trigger the error flow view
  • Service count - programs with several Context.Tag dependencies get a service map
  • Retry/timeout presence - retry or timeout nodes trigger the retry timeline view
  • Layer composition - programs with Layer.provide or Layer.merge get a layer graph

The inferBestDiagramType function implements the baseline selection:

import { inferBestDiagramType } from "effect-analyzer"
const type = inferBestDiagramType(ir)
// Returns 'railway' or 'mermaid'

Specify a format explicitly to bypass auto-detection:

Terminal window
npx effect-analyze ./src/program.ts --format mermaid-services

effect-analyzer includes 15 Mermaid diagram renderers, each optimized for a different aspect of your program:

FormatDescription
mermaidStandard flowchart showing all control-flow paths
mermaid-railwayLinear happy path with error branches - best for sequential programs
mermaid-pathsAll execution paths rendered as separate flows
mermaid-enhancedRich annotations per node (types, services, errors)
mermaid-servicesService dependency map showing which steps require which services
mermaid-errorsError handling and propagation visualization
mermaid-decisionsConditional branching tree
mermaid-causesCause and Exit error wrapping hierarchy
mermaid-concurrencyParallel and race patterns with fork/join structure
mermaid-timelineStep sequence displayed as a timeline
mermaid-layersLayer composition and dependency graph
mermaid-retryRetry and timeout strategy visualization
mermaid-testabilityWhich steps need mocking and what to test
mermaid-dataflowData dependencies between steps in a pipeline
FormatDescription
jsonFull IR as JSON - use for tooling integration
statsComplexity metrics and analysis statistics
explainPlain-English narrative of what the program does
summaryOne-line description per program
matrixProgram-by-service dependency table
showcaseDetailed step-by-step breakdown with annotations
FormatDescription
api-docsExtract HttpApi structure to markdown
openapi-pathsMinimal OpenAPI paths for spec merging
openapi-runtimeFull OpenAPI spec via runtime OpenApi.fromApi

Control the flow direction of Mermaid diagrams with the --direction flag:

Terminal window
npx effect-analyze ./src/program.ts --direction LR
ValueDirection
TBTop to bottom (default for flowcharts)
LRLeft to right (default for railway)
BTBottom to top
RLRight to left