FSM documentation generator for XState projects. One ESM codebase. Runs on Deno or Node. Generates Markdown and Mermaid from machines and states.
⚠️ Version Status: Alpha (v1.0.0) - Core functionality is stable, but API may change. See Stability & Versioning below.
state-docs automatically generates human-readable documentation from your finite state machine (FSM) definitions. It transforms complex state machine code into clear documentation that anyone can understand—perfect for product teams, QA engineers, and stakeholders.
In state-docs, "state" refers to the behavioral state of your application's finite state machines (FSMs):
- Application State Machines: User workflows (authentication, checkout, onboarding)
- Business Logic States: Order processing, approval workflows, document lifecycles
- UI Component States: Modal dialogs, form wizards, navigation flows
- System States: Connection status, data sync states, error recovery flows
We focus on XState-compatible state machines that define discrete states and transitions between them.
Linux/macOS:
curl -fsSL https://raw.githubusercontent.com/plures/state-docs/main/install.sh | shWindows (PowerShell):
irm https://raw.githubusercontent.com/plures/state-docs/main/install.ps1 | iexdeno install -A -n statedoc jsr:@plures/statedoc/clinpm install -g @plures/statedocnpx @plures/statedoc gen --config=.stateDoc.jsonAfter installation, generate documentation:
statedoc gen --config=.stateDoc.json- Install state-docs (choose one method from above)
- Initialize a configuration file:
statedoc initThis creates a .stateDoc.json file with sensible defaults:
{
"projectTitle": "My Project",
"source": "./src",
"target": "./docs",
"globs": ["**/*.ts", "**/*.js"],
"visualization": {
"format": "mermaid",
"exportPng": false
}
}- Edit the config file to match your project structure
- Run the generator:
statedoc gen- (Optional) Add to your package.json scripts:
{
"scripts": {
"docs": "statedoc gen"
}
}Deno:
deno task genNode (after building with dnt):
deno run -A scripts/build_npm.ts
cd npm
npm install -g .
statedoc gen --config=.stateDoc.jsonSee the Shopping Cart Example for a comprehensive demonstration:
- Before: Complex TypeScript state machine code
- After: Clear Markdown documentation with Mermaid diagrams
- Use Cases: Product planning, QA testing, stakeholder communication
- CLI Output: See exactly what the tool generates
Currently Supported:
- XState-compatible TypeScript state machines (
.ts,.tsx) - XState-compatible JavaScript state machines (
.js,.jsx)
Planned (see ROADMAP.md):
- JSON state definitions
- Robot Framework state machines
- State Machine Cat format
- YAML state definitions
Currently Supported:
- Markdown (
.md) - Mermaid diagrams (
.mmd)
Planned:
- HTML documentation sites
- PDF exports
- PNG/SVG diagram exports
- OpenAPI specifications
- Runtime: Deno 2.x, Node.js 18+
- Input: TypeScript, JavaScript (ES modules)
- State Libraries: XState-compatible syntax
- Platforms: Linux, macOS, Windows
| Feature | state-docs | XState Inspector | Stately Studio | Custom Docs |
|---|---|---|---|---|
| Auto-generate from code | ✅ | ❌ | ❌ | ❌ |
| Markdown output | ✅ | ❌ | ❌ | ✅ (manual) |
| Mermaid diagrams | ✅ | ❌ | ✅ | ❌ |
| No runtime required | ✅ | ❌ (needs app) | ✅ | ✅ |
| CLI tool | ✅ | ❌ | ❌ | ❌ |
| Free & open source | ✅ | ✅ | 💰 (limited) | ✅ |
| Customizable templates | ✅ | ❌ | 💰 (Pro) | ✅ |
| Version control friendly | ✅ | ❌ | ❌ | ✅ |
| CI/CD integration | ✅ | ❌ | ❌ | ✅ |
| Works offline | ✅ | ❌ | ❌ | ✅ |
- Static Documentation: Generate docs at build time, no runtime dependencies
- Git-Friendly: Markdown output works with standard version control workflows
- Template-Based: Fully customizable output to match your documentation style
- Dual Runtime: Single codebase works on both Deno and Node.js
- CLI-First: Designed for automation, scripting, and CI/CD pipelines
- Developer-Focused: Built by developers, for developers, with extensibility in mind
✅ Use state-docs when:
- You want documentation that lives in your repository
- You need to generate docs automatically in CI/CD
- You want to customize documentation templates
- You're using XState or XState-compatible state machines
- You need offline, static documentation
❌ Consider alternatives when:
- You need real-time state visualization during development (→ use XState Inspector)
- You prefer visual state machine editors (→ use Stately Studio)
- You need collaborative, cloud-based diagramming (→ use Stately Studio)
- You're not using state machines at all
- ✅ Parses XState-compatible state machine definitions
- ✅ Generates Markdown documentation from state machines
- ✅ Creates Mermaid state diagrams
- ✅ Supports customizable templates
- ✅ Works with TypeScript and JavaScript
- ❌ Runtime visualization: We generate static docs, not interactive UIs
- ❌ State machine validation: We document existing machines, don't validate logic
- ❌ Execution: We don't run or test your state machines
- ❌ Visual editor: We're a CLI tool, not a GUI for creating machines
- ❌ Multiple languages: Currently only TypeScript/JavaScript (see roadmap)
- Parser is placeholder-based; full TypeScript parsing coming in v1.1.0
- No PNG/SVG export yet; only Mermaid text format
- No watch mode; must manually re-run generator
- Limited to XState syntax; other formats planned
See our ROADMAP.md for planned improvements.
What this means:
⚠️ API may change: Configuration options and output formats may evolve- ✅ Core functionality works: Basic documentation generation is stable
⚠️ Breaking changes possible: Updates may require configuration changes⚠️ Use with caution in production: Suitable for early adopters and testing
- v1.0.x - v1.4.x (Alpha): Rapid iteration, API refinements, feature additions
- v1.5.x+ (Beta): Feature complete, stable API, minor changes only
- v2.0.0+ (Stable): Production-ready, backward compatibility guaranteed
We follow Semantic Versioning:
- Major (X.0.0): Breaking changes requiring migration
- Minor (1.X.0): New features, backward compatible
- Patch (1.0.X): Bug fixes, no API changes
Current (Alpha):
- ❌ No backward compatibility guarantee between versions
- ❌ Configuration format may change
- ❌ Output format may change
- ✅ We'll document changes in CHANGELOG.md
Future (Beta & Stable):
- ✅ Backward compatibility within same major version
- ✅ Deprecation warnings before removing features
- ✅ Migration guides for breaking changes
- ✅ 6-month deprecation period for removals
As we're in alpha, migrations are expected. We'll provide:
- CHANGELOG.md: Detailed change notes for each release
- ROADMAP.md: Advance notice of upcoming changes
- Migration sections: Specific guides for major updates
Planned migration guides:
- v1.0.x → v1.1.0: Parser implementation changes
- v1.x → v2.0: Major API redesign (when needed)
This project uses Architectural Decision Records (ADRs) to document significant technical and architectural decisions. ADRs help us maintain a clear record of why we made certain choices and provide context for future development.
📖 View all ADRs: docs/adr/README.md
When making significant decisions about architecture, design patterns, technology choices, or processes, please document them as ADRs following our ADR template.
We welcome contributions! Whether you're fixing bugs, adding features, or improving documentation, your help is appreciated.
- 📖 Read the CONTRIBUTING.md guide
- 🗺️ Check the ROADMAP.md for planned features
- 🏷️ Look for issues tagged with
good first issue - 💬 Join the discussion on open issues
- CONTRIBUTING.md - Contribution guidelines and development setup
- ROADMAP.md - Future plans and feature requests
- Issue Templates - Bug reports, feature requests, documentation
- ADR Process - Architectural decision records
The project includes an automated publishing pipeline that triggers when a new version tag is created.
-
Update the CHANGELOG (if exists) or release notes
-
Create and push a version tag (format:
v*.*.*):git tag v1.0.0 git push origin v1.0.0
-
The GitHub Actions workflow will automatically:
- Update version numbers in
deno.jsonandpackage.json.template - Build the npm package using dnt
- Publish to JSR (Deno registry) at
@plures/statedoc - Publish to npm as
@plures/statedoc - Create a GitHub release with the tag
- Update version numbers in
After publishing, users can install via:
- Shell script:
curl -fsSL https://raw.githubusercontent.com/plures/state-docs/main/install.sh | sh - Deno/JSR:
deno install -A -n statedoc jsr:@plures/statedoc/cli - npm global:
npm install -g @plures/statedoc - npx:
npx @plures/statedoc gen
Configure the following secret in the repository settings:
NPM_TOKEN: npm authentication token for publishing (get from npmjs.com)
JSR (Deno):
deno publishnpm:
deno task build:npm
cd npm
npm publish --access public