How statelyai/xstate-tools works
Project type and purpose
• This is a public monorepo for XState tooling. It ships:
• A command-line tool under apps/cli
• A VS Code extension under apps/extension (split into client & server halves)
• Two reusable libraries under packages/machine-extractor and packages/shared
File structure
• Top-level “apps” folder:
• cli: the end-user CLI project
• extension: the VS Code extension, further subdivided into client (webview + editor integration) and server (language server)
• Top-level “packages” folder:
• machine-extractor: parses TS/JS files for XState machines, returns an AST-style extract result and supports modifications
• shared: common helpers for walking state trees, computing typegen output, mapping file edits, etc.
• Configuration and scripts:
• Babel, Jest, ESLint, Prettier, Husky hooks, GitHub Actions workflows for CI & publish
• Root scripts folder for e2e tests, bundling editor assets, tagging releases
README for additional insights
• Confirms this is the “XState Tools” monorepo
• Links directly to the VS Code extension, implying tight integration with the client/server subprojects
a. Main components
• CLI application
• VS Code extension client (UI/webview, editor glue)
• VS Code extension server (Language Server Protocol endpoint)
• Shared library packages:
– machine-extractor
– shared
• External integrations:
– TypeScript compiler API (for parsing/AST)
– VS Code editor host (for loading the extension)
b. Relationships & interactions
• CLI → invokes machine-extractor and shared APIs → outputs code/typegen/config files to disk
• Extension client ↔ communicates via LSP (JSON‐RPC) ↔ extension server
• Extension server → uses shared + machine-extractor to perform diagnostics, code actions, typegen hints
• Both CLI and extension server depend on the two packages in packages/
• CI/CD workflows orchestrate tests & publish pipelines for all apps and packages
c. Architectural patterns & design principles
• Monorepo workspace pattern (sharing code via relative imports/package.json workspaces)
• Separation of concerns:
– UI layer (extension client)
– Language server logic (extension server)
– Core parsing/extraction logic (machine-extractor)
– Utility functions & abstractions (shared)
• LSP design for the extension (client/server split over Webview vs Node process)
• CLI tool using Node/TypeScript for batch operations
d. Key technologies & frameworks
• TypeScript (ts-node in CLI, compiled in extension/server)
• VS Code Extension API + Webview
• Language Server Protocol (vscode-languageclient, vscode-languageserver)
• Babel & Jest for testing
• Husky, ESLint, Prettier for pre-commit checks
• GitHub Actions for CI & publish