This is a template that is used by the @sdeverywhere/create package to generate a
new project that uses SDEverywhere for a Svelte-based web application.
The project includes:
- a build process that converts a Vensim model to a JavaScript or WebAssembly module that can run the model in any web browser or in a Node.js application
- a
configdirectory that contains CSV files for configuring the generated model and application - a "core" package that provides a clean JavaScript / TypeScript API around the generated model
- an "app" package containing a web application (based on the Svelte framework) that can be used to exercise the model
- a local development mode (
npm run dev) that allows for rapid prototyping of the model and app - a "model-check" setup that allows for running checks and comparison tests using the generated model
# Create a new project (you can also use yarn or pnpm here, if preferred).
npm create @sdeverywhere@latest -- --template svelte
# Enter development mode for your model. This will start a live
# development environment that will build a JavaScript version of the
# model and run checks on it any time you make changes to:
# - the config files
# - the Vensim model file (<name>.mdl)
# - the model check definitions (model/checks/*.yaml)
# - the model comparison definitions (model/comparisons/*.yaml)
npm run dev-
The Vensim model is in
model/{MODEL_NAME}.mdl. -
The
sde.config.jsfile is used by thesdecommand line tool to generate a JavaScript version of the model, which is copied into thecorepackage at build time (into thepackages/core/src/model/generateddirectory). -
The web app is developed using the Svelte framework. See
packages/app/src/app.sveltefor the top-levelAppcomponent. -
The code that runs the generated model is located in
packages/core/src/model/model.ts. This code:- passes the slider values to the generated model as inputs
- runs the generated model asynchronously (in a Web Worker)
- makes the model outputs available to be displayed (and animated) in the main graphs
If you are modifying SDEverywhere (the packages in this repository) and want
to use this template-svelte example to test your changes, you can use it directly
without copying to a separate directory.
The template already includes the "SIR" Vensim model in model/MODEL_NAME.mdl
and associated graph and slider configuration in the config directory, so it
can be used right away without following the "Quick Start" instructions.
Note that this example is already configured in pnpm-workspace.yaml, which
means that its dependencies (e.g., @sdeverywhere/cli) are already linked to
the ones from the packages directory in this repository; no separate linking
step is necessary.
The following assumes that you have already run pnpm install in the top-level
directory, and have built the local packages with pnpm build.
# Enter local development mode for the project (this uses `sde dev`)
pnpm devThis project automatically publishes your simulator and model-check reports to a public website whenever you push changes to GitHub.
- Every time you push changes to any branch on GitHub, a workflow automatically runs.
- Your simulator becomes available online at a public web address that anyone can visit.
- The model-check reports for your branch are also published alongside your simulator for easy access.
- No manual steps required - everything happens automatically in GitHub Actions.
- Main branch: Your latest simulator app build for the
mainbranch is available athttps://yourusername.github.io/your-project-name/latest - Other branches: Each branch gets its own URL (e.g.,
https://yourusername.github.io/your-project-name/branch/feature-name)- The app build for the branch is available at
https://yourusername.github.io/your-project-name/branch/feature-name/app - A model-check report that compares the branch to the latest
mainbuild will be available athttps://yourusername.github.io/your-project-name/branch/feature-name/extras/check-compare-to-base - The model-check bundle file will be available
https://yourusername.github.io/your-project-name/branch/feature-name/extras/check-bundle.js
- The app build for the branch is available at
Once published, you can share the web address with anyone. They can:
- Use your simulator directly in their web browser
- View the model-check reports to understand how the model on one branch compares to another version of the model
- Access different versions if you're working on multiple features or other changes in parallel
SDEverywhere is distributed under the MIT license. See LICENSE for more details.